Working with Ruby
Hi, I am Jan. This is my old Ruby blog. I still post about Ruby, but I now do it on idiosyncratic-ruby.com. You should also install Irbtools to improve your IRB.

RubyBuntu -4- Make gedit better than any IDE ;)

You can, of course, use an IDE for coding – but reconsider it: After hours of initialization, it tries to do everything for you… Somewhere in the never ending menu jungle… And you need to click all the time… Stop! Focus on the gist! You want to write code!

So, as an ubuntu developer, you have the following options:

  • Even so, get an IDE and be happy with it. I am not saying that all IDEs are bad, for example, Netbeans is quite cool.
  • Become a vim or emacs freak. Start being productive in thousand years.
  • Buy a Mac and buy TextMate.No, don’t do that!
  • Use gedit, because it is a slim, powerful, flexible, fast, pretty and stable editor ;)

Update: This guide covers gedit 2. Please use the newer version of this article for gedit 3 ;)

Getting the plugins

gedit is the gnome standard editor so it is already installed on a fresh ubuntu. But the fun begins with the plugins, so you should get more of them. There are two ubuntu packages with lots of popular plugins: gedit-plugins and gedit-gmate. The latter is found in the ubuntu on rails ppa. Add/Install:

sudo add-apt-repository ppa:ubuntu-on-rails
sudo apt-get update
sudo apt-get install gedit-plugins gedit-gmate

Installing plugins manually

There are many other plugins available and installing them is quite easy. Just place the downloaded files of a plugin at: ~/.gnome2/gedit/plugins. Pay attention that the .plugin file must lay exactly in the directory. In most cases it comes with an additional .py file and/or a folder named after the plugin.

Basic settings

At first you should configure some basic settings common for Ruby programming at Edit/Preferences:

View Display line numbers on
View Highlight current line on
View Highlight matching bracket on
Editor Tab width 2
Editor Insert spaces instead of tabs on
Editor Enable automatic indentation on

At the Font & Colors tab you can choose some colors that suit you. I use the great “Railscasts Improved”.

You should also deactivate the redundant toolbar in the View menu and learn/change the shortcut for toggling the bottom- and sidebars (F9).

Hot hot keys

Before getting into the plugins, let me highlight that good shortcuts for good features are very important. What is the use of a plugin that you do not use, because you do not know how to use?

ubuntu offers a nice way to change menu shortcuts: The global Editable menu shortcuts setting. It allows you to change a shortcut of a menu item by moving the mouse over the item and pressing the desired shortcut.

Unfortunately, it has disappeared in ubuntu 10.4 from the appearance settings. But it is not lost, it is just hidden. You can get it back with the gconf-editor by activating the option /desktop/gnome/interface/can_change_accels:

activate desktop/gnome/interface/can_change_accels

Plugin list

You can activate each of the plugins at Edit/Preferences/Plugins. Every plugin in the list without a download link is in one of the above packages. For some plugins I added a shortcut suggestion.

Essential Plugins

You should use these ;)

Code comment

Comment out whole blocks of code with one keystroke.
Edit/Comment Code Strg+#
Edit/Uncomment Code Strg+Alt+#

File Search & Find in Project

This does a full text search in the specified directory or in the directory selected in the file browser. Especially needed, when working with code you do not know.
Search/Search files Strg+Shift+F
Search/Find in project Strg+Alt+F

Indent Lines

This lets you indent the current line(s). Very useful. Unfortunately, it has been removed in ubuntu 10.4, because it is now possible to indent marked text with the Tab key. However, I prefer the old plugin (download), because you can change the shortcut keys and you are also able to indent single lines. It really is fun to move around text with Alt+ArrowKeys :)
Edit/Indent Alt+Right
Edit/Unindent Alt+Left

Rails Extract Partial

Mark some text, press the shortcut, enter a partial name – a must have for Rails developers.
Edit/Extract Partial Alt+P

Smart Indent

Auto indentation, customizable via regex. Familiar comfort.

Snap open or Fuzzy Open

I think, this is the most important plugin. Press the shortcut and type the filename you want to open – it integrates with the file browser pane and searches through all files in the selected root directory. In about 9 of 10 file switchings, I use this plugin.
Search/Go to File or Snap/Open Strg+O

Snippets

Another wonderful helper. It lets you easily include templates by typing an alias and pressing Tab. Furthermore, it puts the cursor to the right spot (e.g. between the html tags). Some templates even have more cursor spots (hit tab again). Alternatively, you can press Strg+Space to get a list of available aliases (also nice for learning them). You can easily customize the snippets at Tools/Manage Snippets…

Word completion

This plugin searches trough all open documents (which are quite a lot when using Snap open) and offers known words for completion. Take the one that completes by pressing Enter to choose one.

Zoom

Download. Missing feature, needed for presentations: Zoom in and out with Strg/-.

Maybe you like it?

These plugins might be perfect for you – or annoying. I use some of them.

Embedded Terminal

This adds the gnome-terminal in the bottom pane (Strg+F9). I rather have my terminals in extra windows, but it is ok for a little irb.

External Tools

Lets you execute any commands! The definite toy for power users :). For example, you can easily execute your Ruby code with this snippet:
#!/bin/sh
ruby
Input: Current Document
Output: Display in bottom pane
Change ruby to ruby -c to only check the syntax. You can find lots of more External Tools snippets at the gnome wiki and in my next blog article.

Gemini

Automatically adds common characters like closing brackets – but there are occasions, where it does the wrong thing. Nevertheless, I like it.

Rails Hotkeys

Offers Rails-specific shortcuts. Hit Strg+Shift+R and then F1 to see a list of available ones. It is a good idea, but in most cases, Snap open just does the job more intuitive.

Reopen Tabs

Download. Opens all the tabs from last time, when gedit starts. Nice, to quickly get back into work, but pretty slow, when there are lots of open tabs…

The icing on the cake!

Plugins in this category are nice to have, but probably not that important

Color Picker

Press shortcut when cursor is on a color to get a nice color picker. Useful for web/css development.

Code Formatter

Download. Reindent spaghetti Ruby code with on keystroke.

Open Folder

Download. Opens the folder of the current active document.
Tools/Open folder Alt+O

Open URI Context Menu

Download. Adds “Open link” to link context menus.

TODO List

Hit the shortcut and it displays a list if your TODO/FIXME annotations (like Snap open, it integrates with the file browser). Do it from time to time ;)

There are a lot of more plugins and resources available. Some links you could check out, if you want more:

Rails Footnotes °_°

In the end, there is some nice extra sugar for Rails-developer: The rails-footnotes gem! It adds interesting informations about the current Rails request to the bottom of each rendered browser page.. It also provides helpful links to associated files – which open in gedit!

footnotes are added at the bottom of every page

But that is still not everything… When you get an error page, you can click on each referenced line and gedit will open the accordant document and jump to the line!

You can click on an error..

...and gedit opens the accordant file on the right line

Total convenience! I gained much productivity using this tool.

Install:

sudo gem install rails-footnotes-linux

Add this line to the Rails project’s config/environments/development.rb:

config.gem 'rails-footnotes-linux', :lib => 'rails-footnotes'

Not working for Rails 3, yet

That’s it!

At this spot, a big thank you to all people who developed gedit, translated it, wrote plugins or otherwise contributed. Without you guys, gedit would not be such a great editor!

Creative Commons License

Janmartin | April 29, 2010

Very cool!
How do I start gedit without all those plugins?
After all from time to time I need to edit a textfile, containing text, not code.
Thanks.

J-_-L | April 29, 2010

Even with many plugins, gedit remains pretty fast. You could deactivate the plugins at Edit/Preferences/Plugins or use another program for editing plain files, but I would recommend just using gedit as it is - most of the plugins are very unobtrusive.

@rathgar | April 30, 2010

If gmate isn't available, add Ubuntu on Rails PPA in Software Sources on Other Software tab: ppa:ubuntu-on-rails/ppa
Then you'll be able to find it :)
See https://github.com/gmate/gmate for more info

Anonymous | May 02, 2010

Many thanks for paragraph "hot hot keys"

Anonymous | May 03, 2010

awesome - gedit rocks ;)

Dan | May 03, 2010

keep your eyes on redcar editor... I am.

DonL | May 10, 2010

very nice guys!

Dimas | May 22, 2010

Very nice article. Thank you!!
When will you post the next one?

J-_-L | May 23, 2010

Thank you for your positive feedback :),
@Dimas: I have planned two articles for this month: another one on gedit and one about a little Active Record plugin.

Jerry | June 27, 2010

You did a great job for ruby rookies like me!
Thank you very much!!

@MatthewClosson | June 30, 2010

Outstanding article and although I still love vim and its associated plugins as well, this is a very sweet, fast, and easy setup on Ubuntu. I will highly recommend your article to all linux rails developers I know.

krzysiek | July 30, 2010

thanks, i find gedit-gmate better than geany now!

piotr | August 03, 2010

Activate can_change_accels with simple command:
gconftool -s /desktop/gnome/interface/can_change_accels -t bool true

Ernest | December 19, 2010

Finally someone who talks out of reason. I was sick and tired hearing "use VIM|Emacs - the real man's editor". Thank you for this great post!

sohussain | October 22, 2011

Can you please update this guide for the new default gedit v3.x ?
purdy plox!!

J-_-L | October 24, 2011

Hi sohussain,

I am working on it :)

sohussain | October 24, 2011

I must say being a (micro)softy in the past, being new to Ubuntu/linux, ruby, rack, ......., rails,etc. simultaneously is very hard!, and your rubybuntu series has been a godsend for me!

looking forward to the gedit 3.x update |o_o|

milan | February 29, 2012

If /desktop/gnome/interface/can_change_accels in gconf-editor doesn't work (i.e. Ubuntu 11.10) try running
gsettings set org.gnome.desktop.interface can-change-accels true