Introduction
Text Editor (gedit) is the default GUI text editor in the Ubuntu operating system. It is UTF-8 compatible and supports most standard text editor features as well as many advanced features. These include multilanguage spell checking, extensive support of syntax highlighting, and a large number of official and third party plugins.
gedit is suited for both basic and more advanced text editing and is released under the GNU General Public License.
Screenshot
Installation
gedit is located in Ubuntu's Main repository and is installed by default. gedit can be installed in Kubuntu, Xubuntu and other distributions although additional libraries are necessary and will be installed on non-GNOME systems.
To install gedit:
Select gedit in Synaptic (System → Adminstration → Synaptic Package Manager)
- From a terminal or ALT-F2:
sudo apt-get install gedit
Opening gedit
gedit incorporates a graphical user interface (GUI) and is opened by going to Applications → Accessories → Text Editor or by pressing Alt+F2 and typing gedit
Command Line Tips
Opening gedit via the command line allows the user to take advantage of several options unavailable from the GUI menu. If a path is not included in the startup command, gedit will look for the file in the current directory. If the file is not found, gedit will open a blank file with the file name entered on the command line:
To open a specific file:
gedit filename
To open multiple files:
gedit file1 file2
To edit system files such as sources.list and fstab, open it with administrative privileges. It is NOT recommended to manually run graphical applications with administrative privileges, but in case you insist to do it, be sure to use gksudo rather than sudo.
gksudo gedit
To open at a specific line number, useful when an error message includes the line number, include "+<line number>". (gksudo is used in this example since the file is a system file owned by root):
gksudo gedit +21 /etc/apt/sources.list
Configuration Options
Several popular options which the user may wish to review after the initial installation are:
Create Backup Copy: Edit → Preferences → Editor tab. This option is enabled by default and creates a copy of the file before saving changes. Backup files saved in this manner are appended with a trailing "~". If the user does not want gedit to back up files in this manner, deselect the option.
Autosave: Edit → Preferences → Editor tab. This feature is not enabled by default. The user may also select the time between autosaves.
Spell Checker: Edit → Preferences → Plugins tab. This feature is enabled by default.
Plugins
Plugins greatly enhance the power of gedit and are are accessed via Edit → Preferences → Plugins. More than a dozen plugins are pre-installed and can be enabled/disabled in this section. Some of the most popular are enabled by default while others must be enabled by the user.
- Tag List. Displays common tags in a side pane and allows for easy insertion into the file.
External Tools. One of the powerful default plugins available (but not enabled by default), External Tools allows the user to run external commands on the file being edited from within gedit itself.
Once this plugin is enabled, the user can select custom tools from the Tools menu.
The addition of shortcut keys and the configuration of tools from the External Tools Manager are accomplished via the Tools → External Tools... menu.
For descriptions of standard plugins distributed with the gedit package visit this link.
Many additional plugins are available from third-party resources. See the Links section near the bottom of this page.
Syntax Highlighting
A very useful feature of gedit is the ability to color programming code. Using syntax highlighting makes simple errors easier to recognize. gedit uses the GtkSourceView for syntax highlighting. The .lang file for a specific programing language is located in the /usr/share/gtksourceview-3.0/language-specs/ folder. These files may be edited or additional files created to further define the highlighting definitions.
Syntax highlighting is automatic and is selected in one of two methods. It can be chosen via the menu with View, Highlight Mode or via the lower statusbar. The statusbar, enabled via the View menu, displays programming language options for many types of sources, scripts, markup and scientific formats. A screenshot of the statusbar in use is located further down this page.
Using gedit for XML / Docbook XML
gedit provides a user-friendly way to make XML markup or Docbook XML for yelp and ubuntu documentation. The pictures and instructions given below use gedit 2.26.1. The recommended changes help take full advantage of the syntax color highlighting which gedit provides.
- Under the View tab make the following selections. Selecting most of the options just make life easier.
- The next change to make is under Editor tab. As one can see there is not much to do here.
Next is the Plugins Tab. A screenshot of the plugins tab is available in the Plugins section above. There are a number of changes you can make on the Plugins page, the most important perhaps is the Tag List option. Experiment with other plugins and see what they do. This link gives a brief explanation of each default plugin.
Now comes the most interesting part, go to View > Highlight Mode > Markup and while we want Docbook one can also see XML and both look slightly different from each other:
The above one is when the text is highlighted using geditdocbook. The same text when highlighted using XML looks like:
Experiment with gedit's settings and markup in general to have a feel of what works best for you.
Uninstalling gedit
If you are running Ubuntu and attempt to remove gedit via Synaptic or apt, the system will also attempt to remove the ubuntu-desktop metapackage. If you try to remove ubuntu-desktop specifically in Synaptic the user will be cautioned with:
This package depends on all of the packages in the Ubuntu desktop system. It is also used to help ensure proper upgrades, so it is recommended that it not be removed.
If the user is experiencing problems with gedit, it may be preferable to first reset the user's preferences by removing the user's .config/gedit folder rather than attempting to remove the entire application and the ubuntu-desktop metapackage. Learn more about Ubuntu's MetaPackages.
Related Apps
Kate - the installed editor for Kubuntu
- Mousepad - the lightweight text editor for Xubuntu