This is a simple plugin for Gedit 3 which automatically trims trailing whitespace from documents when saving. It deletes all horizontal whitespace on the ends of lines as well as extra blank lines at the end of the file.
Make sure that you have the GtkSource-3.0 GI typelib (
/usr/lib64/girepository-1.0/GtkSource-3.0.typelib). On Ubuntu, this can be installed via:
sudo apt-get install gir1.2-gtksource-3.0
Fedora users should already have the typelib, as it is included in the
You may need to create some directories if you haven't installed Gedit plugins locally before:
mkdir --parents ~/.local/share/gedit/plugins
As root, save
/usr/local/share/glib-2.0/schemas(you may need to create this directory if it does not exist) and run:
Alternatively, to install the GSettings schema without root access, you can change the
XDG_DATA_DIRSenvironment variable to include a directory under your control, such as
Add the following to your
if [ -z "$XDG_DATA_DIRS" ]; then export XDG_DATA_DIRS=/usr/local/share/:/usr/share/ fi export XDG_DATA_DIRS=~/.local/share/:"$XDG_DATA_DIRS"
mkdir --parents ~/.local/share/glib-2.0/schemas
From the Edit menu, select "Preferences".
On the Plugins tab, scroll down to the entry for "Trim Trailing Whitespace Before Saving" and check the checkbox.
- From the Edit menu, select "Preferences".
- On the Plugins tab, scroll down to the entry for "Trim Trailing Whitespace Before Saving" and uncheck the checkbox.
- Close Gedit.
The plugin looks at the document's syntax highlighting mode. If the highlighting mode is "Plain Text" or "Diff", then the plugin does not remove trailing whitespace.
The plugin source code is based on Osmo Salomaa's "Save without trailing space" plugin for Gedit 2.x that was uploaded to
http://users.tkk.fi/~otsaloma/gedit/. The website seems to be down now, but the Internet Archive as well as this git repo hold copies of the original source files,
If you see the error message:
(gedit:3582): GLib-GIO-ERROR **: Settings schema 'org.gnome.gedit.plugins.trimtrailingws' is not installed
then you need to install the GSettings schema file, `org.gnome.gedit.plugins.trimtrailingws.gschema.xml`. See the section on Installation above.
Copyright © 2010–2014 Daniel Trebbien Copyright © 2006–2008 Osmo Salomaa This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.