RubyBuntu -6- gedit 3! wtf? set it up for ruby/web development :)
So you’ve installed (or upgraded to) ubuntu 11.10 and everything looks great… Except – uh!, lots of gedit plugins are only compatible with gedit 2! But don’t be sad.. or angry.. This guide points out, how to, nevertheless, create a solid foundation that allows you getting prodcutive with gedit!
Setting up gedit
, the slim and powerful, pretty and fast, flexible and stable code editor ;)
This guide assumes an ubuntu 11.10(gnome shell) system, but will also work for similar variants (Btw, what’s the first thing you should adjust in a new ubuntu system? Change the gnome theme to radiance!).
Aside from that, you should already have installed ruby and git (sudo apt-get install git-core
). If you still use GNOME 2/gedit 2, please use this previous article instead.
Scaffold
Firstly, ensure that you’ve got the official gedit-plugins package:
sudo apt-get install gedit-plugins
Besides this official package, I usually recommend installing the gedit-gmate package. However, one disadvantage is that plugins get not stored in the default user plugin directory. Moreover, it comes with an extra Ruby language specification for Ruby files in Rails, so editing Ruby files can lead to different colorizations, which is quite confusing. Nevertheless, gmate comes with lots of useful additions that will be used below.
On the other hand, I’ve started to improve the Ruby (and related) gedit configurations and called this rubybuntu-gedit. It’s not finished, yet, but already includes better Ruby specifications. Still, it does not include other web-related language definitions, but gmate has them! In some folder, clone the gmate repo:
git clone https://github.com/gmate/gmate
Copy the files from gmate/lang-specs
to /usr/share/gtksourceview-3.0/language-specs
:
sudo cp gmate/lang-specs/*.lang /usr/share/gtksourceview-3.0/language-specs
Next up, install the rubybuntu-gedit gem. It will copy more language files to the above folder, delete the rails and rhtml files and set some gnome mime types (install as sudo when prompted):
gem install rubybuntu-gedit
rubybuntu-gedit install -3
After these steps, gedit can speak languages like Ruby 1.9, Sass, Haml, Cucumber, Gemfile.lock etc. ;)
Settings
Now, start gedit!
Here are some recommendations for the basic settings at the Edit/Preferences dialog:
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 |
Under the Font & Colors tab, you have to either select the RubyBuntuOne or the RubyBuntuTwo theme to use the enhanced language specifications from above.
The redundant toolbar can be deactivated in the View menu. The default shortcut for toggling the bottom- and sidebars is (<Ctrl>+)<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 always forget how to use it?
ubuntu/gnome 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 in GNOME 3 with the gsettings command:
gsettings set org.gnome.desktop.interface can-change-accels true
And while we’re on it, let’s also improve the way the home key works in gedit (should jump to the first char, instead of the absolute beginning of a line):
gsettings set org.gnome.gedit.preferences.editor smart-home-end before
Plugins
Installing gedit plugins is quite easy. Just place the downloaded files of a plugin at: ~/.local/share/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. Plugins can be activated at Edit/Preferences/Plugins.
Below is a list of plugins I use, ordered by subjective importance. Every plugin without a download link is available in the official plugin package or in gmate(gedit3). I’ve alse added a shortcut suggestion for some of them.
Snap open
File/Snap open | Strg+O |
Code comment
Edit/Comment Code | Strg+# |
Edit/Uncomment Code | Strg+Alt+# |
Advanced Find/Replace
alias grp='grep . --color=auto -r3e '
Snippets
Word completion
Draw Spaces
External Tools
#!/bin/sh
ruby
Input: Current DocumentOutput: Display in bottom pane
Change
ruby
to ruby -c
to only check the syntax. There are lots of more External Tools snippets at the gnome wiki and in this blog article. GNOME 3 stores the tools in ~/.config/gedit/tools
. Little pitfall: When using Ruby via RVM, you need to load RVM (the code line you also find in your .bashrc) prior executing ruby
. Alternatively, start gedit from a RVM-powered terminal.Smart Highlight
Pair Character Completion
Color Picker
Open URI Context Menu
Embedded Terminal
Strg
+F9
). I rather have my terminals in extra windows, but it is ok for a little irb
.Regex Search and Replace
I miss my gedit 2 plugins!!!11
This list is definitely shorter than the one for gedit 2, many plugins are not ported, yet. For example, I haven’t found a replacement for these ones:
- Smart Indent
- TODO List
- Rails Extract Partials
In addition, I miss an indent plugin that allows you to (un)indent using <Alt> and the arrow keys. Although gtksourceview (which is a part of gedit) offers indenting using (<Shift>)<Tab>, it’s absolutely not satisfying when trying to indent single lines.
I will update this post with new gedit 3 compatible plugins that I’ll use (or maybe write). New plugins can also be found at:
- the official wiki
- the gmate repository
Rails Footnotes
Last but not least, some extra sugar for Rails-developers: The rails-footnotes gem! It adds useful information 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 the referenced line and gedit will open the accordant document and jump to the line!
Total convenience! I gained much productivity using this tool. Because it’s written with textmate in mind, some tweaking is needed. Let’s start with adding this line to the development section of your Gemfile
:
gem 'rails-footnotes'
Then run the generator:
rails generate rails_footnotes:install
The next step is to create a textmate handler that the browser uses to open txmt://
links. Create it somewhere on your disk, for example in ~/.txmt_handler
:
#!/bin/bash
# simple txmt: to gedit handler (simple because: needs this order and completeness)
# see https://rbjl.janlelis.com/58
if [[ $1 =~ ^txmt://open\?url=file://(.*?)\&line=([0-9]*)\&column=([0-9]*)$ ]]
then
exec /usr/bin/gedit ${BASH_REMATCH[1]} +${BASH_REMATCH[2]}:${BASH_REMATCH[3]}
fi
After making this file executable (chmod +x
), you need to add the txmt:
protocoll handler to your browser. In firefox, just go to about:config
and create a boolean key named network.protocol-handler.expose.txmt
that you set to false
. When you now click on a txmt:
link for the first time, firefox will open a popup, in which you can select the script from above.
A.I. | December 07, 2011
Why you don’t use Ubuntu on Rails PPA and don’t install gedit-gmate package?
J-_-L | December 07, 2011
Hi ai. Besides the facts in the guide, the main reason is: To have control of which plugins get installed. Furthermore, one can faster react on new plugins in your gmate github repo ;)
stephen murdoch | December 15, 2011
these instructions worked fine on Lubuntu (11.10), thanks very much
Stefan | March 31, 2012
Justin Federspiel | April 02, 2012
Bit late to the party, but thanks for the guide! Looks like I've got a pretty sweet gedit setup going, having followed your direction.
Stefan | April 17, 2012
Do you have any idea as why syntax highlighting would stop working? I already had gmate installed as sudo.. so i deleted ruby_on_rails.lang and rhtml.lang, installed your gem as sudo.. now every .rb file I open defaults to "plain text". I have checked the mime types, they seem ok.. Also i had no problems on a clean install (following your guide word by word).
Any help is appreciated! Thank you in advance
Lucas | August 12, 2012
I have ruby installed via rvm and I can't run the ruby interpreter with gedit's external tools. How can I load RVM?