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
:
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
Code comment
Edit/Comment Code | Strg+# |
Edit/Uncomment Code | Strg+Alt+# |
File Search & Find in Project
Search/Search files | Strg+Shift+F |
Search/Find in project | Strg+Alt+F |
Indent Lines
Edit/Indent | Alt+Right |
Edit/Unindent | Alt+Left |
Rails Extract Partial
Edit/Extract Partial | Alt+P |
Smart Indent
Snap open or Fuzzy Open
Search/Go to File or Snap/Open | Strg+O |
Snippets
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
Enter
to choose one.Zoom
Maybe you like it?
Embedded Terminal
Strg
+F9
). I rather have my terminals in extra windows, but it is ok for a little irb
.External Tools
#!/bin/sh
ruby
Input: Current DocumentOutput: 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
Rails Hotkeys
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
The icing on the cake!
Color Picker
Code Formatter
Open Folder
Tools/Open folder | Alt+O |
Open URI Context Menu
TODO List
There are a lot of more plugins and resources available. Some links you could check out, if you want more:
- https://live.gnome.org/Gedit/Plugins
- https://grigio.org/pimp_my_gedit_was_textmate_linux
- https://blog.siverti.com.br/gmate/
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!
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!
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!
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