gEdit is one of the excellent text editors available with GNOME. Hard core Linux users mostly focus on either vim or emacs. If you are one of those people – Great ! You have found the editor of your dreams. If you are one of the new users to Linux , it will not hurt to learn to use gEdit. Probably this is the editor with least learning curve. Most people underestimate the power of gEdit – comparing it to notepad in Windows. gEdit is much much more powerful than notepad (or Wordpad for that matter).
I primarily use Vim for my coding and use gEdit for some basic stuff like taking notes, writing blog post drafts etc. This post is not a tutorial on using gEdit. Instead, I will focus on its powerful plugin architecture and recommend some plugins which I hope will , dramatically improve your productivity. I will focus on Ubuntu version of gEdit and its plugins – although most of the points are applicable to other Linux distributions.
gEdit is a lightweight editor in GNOME with lot of neat features. It is very flexible and extensible – it has an excellent plugin architecture , allows themes to customize UI and so on. gEdit is also very intuitive to use. If you have worked in any general purpose text editor, you will be immediately feel at home with gEdit.
Before we go to plugins, one of the coolest feature in gEdit is its syntax highlighting. gEdit can highlight syntax for huge number of languages. Most of the time it can figure it out and do the highlighting automatically. In some scenarios where it fails (eg rhtml or phtml) , you can make it highlight using "View -> Highlight Mode -> [language]" . The other option is to select the language from the status bar.
Themes are another way to customize the colors of gEdit. gEdit comes with a few themes. To play with them, go to "Edit -> Preferences -> Font & Colors" . You can select one of the color schemes that is pleasing for you and also blends with your desktop / shell background. I use a neat style called DarkMate . To install it, download the xml file and put the file in ~/.gnome2/gedit/styles . After this, restart gEdit and follow the procedure described above to change styles.
Installing and Enabling gEdit Plugins
gEdit has a powerful plugin architecture based on GTK. You can use Python to write plugins. I wrote my first plugin (mimicking vim’s autocmd filetype feature) in couple of hours. You can produce excellent plugins within hours if not days. gEdit comes bundled with some excellent plugins. A more comprehensive set can be obtained by installing the package "gedit-plugins". The command is
sudo apt-get install gedit-plugins
This package contains lot more plugin goodies which should be enough for most users’ needs.
Sometimes some developers might put their own plugins in their websites. You can install them by downloading the file and extracting it at ~/.gnome2/gedit/plugins (If you want the plugins only for you) or at /usr/lib/gedit-2/plugins/ (If you want a system wide install).
Once you installed the plugins , the next step is to activate them. Go to "Edit -> Preferences->Plugins" . Go through the list and enable the plugins that catches your fascination. Each plugins has individual behavior and hence it is hard to explain how to play with them – Lot of plugins add a new menu or add a menu item in "Tools" . Some add themselves to left or bottom pane. To view them use the "View" menu and select "Side Pane" (or F9) or "Bottom Pane" (ctrl+F9).
There are some plugins that I use regularly . I will try to give a brief discussion about the plugins.
In my opinion, this is probably the most useful plugin. As the name suggests, you can use it create snippets of text or code that are triggered by some word or shortcut key. It comes preloaded with a huge list of useful snippets for all the commonly used languages.
It also has a neat placeholder feature that is useful when the placeholder has to be replaced with some actual variable or some text. For eg, C’s do while loop has two placeholders. One for the condition and other for the loop body. These can be entered by pressing tab key. Placeholders can do more powerful stuff too. For eg, in C’s for loop, there are many placeholders – like the initialization, condition, increment and loop body. Most of the time, the initialization placeholder is used in all of the other places. So this plugin allows you to say that if the user entered j as initialization variables, replace all other placeholders with j.
Another very powerful feature is its ability to give you choices for categorical variables. You can learn a lot by checking out sample snippets (eg C’s snippets). It even allows Python code within the snippets (see C’s gpl snippet). To learn all about Snippets’ powerful features check out this site. A simpler tutorial is here.
Lastly, this plugin allows you to give shortcut keys to each of the snippets which increases the productivity even more for keyboard junkies like me.
This plugin allows you to execute some commands through the shell from gEdit. This is pretty flexible as it allows you to start an external command and play with its input and output. Sample scenarios are : committing the current file to SVN , tidy your html by running HTMLTidy , run make or start a nuclear war.
To configure, go to "Tools -> Manage External Tools" . You can add a new command here. It can accept a variety of inputs (from current word to current document), run any arbitrary set of commands and do variety of stuff with the output (from do nothing to replacing current document). It is not necessary that the code you enter is always a shell code. You can even enter Python code as long as you enter the she-bang line correctly. Note that, if you made the output as "Display in bottom pane" then you need to make the bottom pane visible to see it (If you are using other plugins too , then you need to watch the "Shell Output" tab of the bottom pane. Again, you can have keyboard shortcuts for executing these commands. For more details, see this page.
This plugin shows the list of symbols in the loaded source file (eg classes, functions etc). This works pretty well for most common languages (partly because it uses ctags which is versatile). To see it in action, load some C , C++ or Ruby file. View the left pane (View -> Side Pane) . If you have multiple plugins using the side pane, then the click on the icon looking like indented document . It will show a schematic representation of your source file.
Document Word Completion
What this plugin does is simple. It reads all the words in all the open documents and when you type , it shows potential words in a drop down. This is a big time saver for slow typers like me. Of course some people might be irritated by the constant popups – If so a simpler plugin is at this page . You have to download the three files beginning with completion and put it at ~/.gnome2/gedit/plugins .
I know very few people use LaTeX but in case you are one of those , gEdit has a powerful LaTeX plugin. The best way to download it in Ubuntu is to use the command :
sudo apt-get install gedit-latex-plugin
There are other good LaTeX plugins too. Basically, it allows you to auto-complete LaTeX commands, do syntax highlighting . It has a rudimentary syntax checking which can catch simple errors like missing brackets. It also has multiple wizards for creating new LaTeX files , building and citing.
This is another neat plugin which shows a terminal in the bottom pane. I kinda use it partly because Kate in KDE has a terminal with it. Again, you need to view the bottom pane before seeing this terminal. You can do lot of stuff with this plugin. Recently though, I realized most of the common stuff I do can be automated using the External Tools plugin and hence I no longer use it much. But it is still a very useful plugin.
This is probably the geekiest of gEdit plugins. I mainly use it for doing some bulk operations on all the open documents. You can use it only if you knew basic Python and also gEdit’s API. But if you knew it , then this plugin is a great lifesaver. One common thing I do is a "Save All Documents" . gEdit does not have a menu option to do that . Hence I use this code snippet.
[doc.save(True) for doc in window.get_unsaved_documents()]
Another real cool plugin. The main purpose is to allow editing multiple parts of the document simultaneously. Most of the time, this scenario occurs rarely but when it does, this is a great time saver. One common thing I use is for renaming a variable. I select the declaration and all its usages – If I rename the variable, it is reflected immediately at all places. This is usually very helpful when I do Python coding. See this screen cast for all its features.
There are lot of other good plugins. Some of my favorites are :
1. Code Comment : Allows bulk commenting of text. Select a block of text and press Ctrl+M to comment and Ctrl+Shift+M to uncomment. It works for lot of common programming languages.
2. File Browser : Allows you to browse your system and open files easily. It also has basic search functionality.
3. Advanced Bookmarks : Allows you set bookmarks inside the document and navigate them efficiently.
4. Session Saver : Very useful if you use gEdit to edit lot of related files (Eg some project code). In this case, you can save all the documents as a session and retrieve them in one shot. Neat !
5. Snap Open : Allows you to effectively search and open files related to the files open currently. It internally uses find and grep. If you find it too slow, change the code to make it use locate (Assuming you regularly do updatedb).
Developing New gEdit Plugins
Using gEdit plugins is only half the fun. Most of the time, you will have unique requirements on your own. For eg, I wanted gEdit to enter some text automatically when I open certain types of files. Eg : fill out all the common includes and empty main function whenever I open a new C++ file. There is a high chance that some body faced the issue and wrote a plugin – If not do not worry. Writing a gEdit plugin is a snap – if you know Python. gEdit has a excellent documentation and tutorial for the same. See the official How-To.
1. gEdit Plugins : The official plugin listing page is here.
2. gEdit Plugin Development : The official tutorial is here.
3. The plugins can found at either ~/.gnome2/gedit/plugins or at /usr/lib/gedit-2/plugins/ .
If you liked this post , please subscribe to the RSS feed .