Sunday, June 28, 2009

Sprucing up gedit

For 'true' Linux aficionados, there is Emacs...
For worshippers of the devil, there is VI, and VIM...
For us lesser (non-gui impaired) mortals, there is gedit.

But like many things open source, gedit can transformed into something vastly more useful for programming purposes. Note that I am not saying that Gedit will be better than eclipse. It is not even close in terms of being a development platform. But once in a while, if you want a simple, lightweight GUI for coding, Gedit can be a serious contender.

In today's (and maybe tomorrow's) article, I will show you how to go from this:


to this:


GEDIT Plugins:
Most distributions of linux offer a package called gedit-plugins.
This will give you most of the essential plugins you need to spice up gedit.

On ubuntu for example, "sudo apt get install gedit-plugins" will get you this package.

This package will give you, among others, these useful plugins:
1. Code Comment: Comment or uncomment blocks of code (ctrl+M, ctrl+shift+M by default). This plugin is quite clever. It understands various comment formats, and depending on whether you are editing HTML, C, C++, vb or python or whatever else, it uses the appropriate comments.
2. Session Saver: Allow to bookmark working sessions in order to get them back for further use.
3. Terminal: A simple terminal widget accessible from the bottom panel. This, IMO is the coolest feature. You get to use a full bash terminal from within gedit. Compile and run your programs, move around things, browse... perfect if you don't hate the command line, but need some gui to maintain sanity.

Apart from this, a few of the original (default) plugins are very/somewhat useful too:
1. File Browser: A file browser plugin allowing to easily access your filesystem (includes remote mounts, creating new files/dirs, monitor dirs for changes, etc)
2. Indent: Indents or un-indents selected lines.
3. Spell: Checks the spelling of the current document.
4. Document Statistics: Reports the number of words, lines etc.

Finally, there are third party plugins. gedit plugins are written in python, so if you are a python geek, Here is how you can get started. There are a huge number of such plugins, but the one that I personally can't live without is the Autocomplete plugin. Download it here: http://sourceforge.net/projects/gedit-autocomp

Installing custom plugins. The .gnome2 directory:

gedit (and many other gnome programs) store their settings in a directory called '.gnome2'. This is a hidden directory in your home directory. gedit specifically uses the '.gnome2/gedit/plugins' directory to store its plugins. If this directory does not exist, simply make it.
ie:

mkdir -p ~/.gnome2/gedit/plugins

The -p option makes any directory that does not exist in the path that you specify. So, even if the gedit directory is not there, it will be created.

Now, simply download the plugin and unpack it into the plugins directory, so that you have the file "autocomplete.gedit-plugin" in your 'plugins' directory.

Enabling Plugins in gedit:

To enable the plugins, after installing all plugins, simply restart gedit. Go to the Edit Menu, and click on Preferences. In the Plugins tab, select the plugins you want to use. Also, while we are in the Preferences menu, we may as well do some other useful things, like enabling Line Numbers (the 'Display Line Numbers' option in the View tab), enabling Auto Indentation (in the 'Editor' tab), and (depending on your preference), using a cooler color scheme, like Oblivion (in Fonts and Colors tab). If you are annoyed with the ~ files that gedit keeps creating, here is your chance to disable backup creation as well (in the Editor tab).

Finally, to actually see these plugins that you have enabled, you need to go to the View menu, and enable 'Side pane' and 'Bottom pane'. This opens up the file browser, and the terminal plugin.

In tomorrow's post, we will see how to use another powerful feature, the "External Tools" option.

More plugins can be found Here.

3 comments: