Over the weekend I was helping a friend setup a small Ubuntu server but since he is dead set on remaining on Windows for his desktop needs, I setup a Ubuntu Desktop guest instance in Sun's excellent VirtualBox to work from for the afternoon. I was using a disk clone from my own PC (where I keep Vista on hold for those days I want to blow up chains of cars stuck on a bridge in Liberty City) and he seemed sort of shocked to see Ubuntu working perfectly well inside Vista at near full resolution. Another Ubuntu convert in the making .
Being one of those Editplus/Notepad++ types, he was also impressed by Ubuntu's default editor, the infamous "Text Editor" aka gedit. His surprise at gedit reminded me that to so many people, the humble Gnome editor is often compared to Windows notepad app. A simple editor with minimal features that is pathetic for anything else.
Not true!
The truth is that I use gedit for programming in Ubuntu at least as often as I boot up Eclipse. So there! There are times you want a heavy IDE, and times you need a lightweight editor that starts in a second and takes less than five minutes to open a file. I've always liked to avoid IDEs when I can because I find them a chore to use for anything but a few bigger applications where their awesomeness is actually awesome and not just tedious. Mostly they tend to be slow and cumbersome, and this is made worse when you're running inside a small virtualised OS. Gedit on the other hand is about as unassuming as you could wish for - small, fast, stable and customisable with plugins if you know Python or C (or can download third party plugins ).
Gedit can, with a little work, become an excellent source code editor. It's main advantage is its plugin system which allows for some really great customisations that allow gedit to appear and act more like Mac OS's TextMate (which presumably is a good thing). Let there be no mistake, I love gedit. I've been tempted into trying alternatives, but gedit seems to suit a need for simplicity in my programming life where I spend all my time using the Gnome desktop.
To get us started here's a quick video showing a plugged and styled gedit in action.
Basic Functionality
By default, gedit comes with few bells and whistles enabled and its initial state really does make it just another notepad. It will immediately offer source code highlighting however which is a step up at least. Once you have your barebones setup it's time to look under the hood and get it pimped out.
Your first stop should be the User Preferences (Edit > Preferences). From here you can enable tabs or space indents depending on your likes, enable highlighting of the current line, enable matching bracket highlighting, etc. Basic editing preferences you can't live without .
Next, locate the plugins pane (Edit > Preferences > Plugins) which provides a list of installed plugins. The following should be enabled:
File Browser: A file browser plugin allowing to easily access your filesystem (includes remote mounts, creating new files/dirs, monitor dirs for changes, etc)
Indent: Indents or un-indents selected lines
Snippets: Insert often used pieces of text in a fast way.
External tools: Execute external commands and shell scripts
The two ones to watch are File Browser and Snippets. The File Browser is one of those features you'll take for granted, a bare essential. Snippets is one alternative approach to the lack of full IDE autocompletion allowing you to create countless snippets of reusable code you can insert into files by typing the relevant tag and pressing the tab key. The Snippet format is similar to TextMate's and supports some cool scripting with Python or bash to tailor the snippet based on other Snippet fields or shell accessible values.
More Official Plugins
Why stop here? Move right along, and install the official gedit-plugins package using (for Ubuntu):
sudo aptitude install gedit-plugins
Now return to your user preferences (you may need to restart gedit so it can pick up newly added/changed files) and enable some additional plugins from this package:
Bracket Completion: Add automaically a closing bracket when you insert one
Code Comment: Comment or uncomment blocks of code
Session Saver: Allow to bookmark working sessions in order to get them back for further use
Terminal: A simple terminal widget accessible from the bottom panel
Third Party Plugins
We're really getting somewhere now! To add even more functionality you cannot live without, we'll need a few more unofficial plugins. Well, more than a few... To make things a lot easier, it's worth grabbing a precompiled collection of the most useful third party plugins, themes, and other assorted updates. The collection we're after is called "gedit-mate" which is based on a previous collection called "GMate".
I've repacked the current version of this collection with some tweaks and added some PHP specific enhancements. It's available from http://github.com/padraic/gedit-mate (this is forked from the original Rails version at http://github.com/ivyl/gedit-mate). You can git clone from there, or simply use the Download button on the page to grab a zip or tar archive to work with.
I replaced the original Ruby Rake installer script with something more appropriate, so you just need to navigate to the gedit-mate directory and run:
sudo sh install.sh
Now back to our plugin preferences, enable the following plugins:
Advanced Bookmarks: Advanced bookmarking tool for Gedit
Class Browser: A class browser located in the side pane. Based on ctags, it supports a wide range of languages allowing to quickly navigate files by their classes and methods.
Find In Files: Searches all docs under the root of your File Browser sidepane
Word Completion: Display a completion popup, updating as you type, with suggestions from all words in all documents in all windows
Snap Open: A regex open file dialog that resembles that of Textmate
Open Files: Opens files based on a name query
You can assess a few other plugins to be enabled if you wish, but DO NOT enable the Gemini plugin which conflicts with Bracket Completion and creates some undesireable effects. I found that Gemini had problems with PHP bracket closing.
You now have an editor with some new features and pretty toys to play with. Have a look at the remaining plugins left disabled to see what additional features you might want to enable to
Adding A Splash Of Style
There are any number of personal preferences when it comes to editor styles. My personal choice is a dark background with fairly well bolded text in a lighter (but not overly white) colour which I find is a lot easier on my eyes. At the moment I use the Darkmate theme which matches my needs admirably and looks pretty cool to boot. Our third party plugin pack will have installed a lot more themes to experiment with.
The plugin pack will also have installed the Monaco font that everyone seems to love in TextMate into your user's .font directory. You can adjust your font style for gedit from the default monospace option to monaco and pick your preferred font size, or pick any other suitable monospace font you prefer.
Zend Framework Snippets
With the Snippets plugin, we have the ability to create strings of code to reuse at will. Gedit cannot support IDE style autocompletion (if you need that, use an IDE!) but Snippets remove quite a bit of that pain when autocompletion is not an absolutely essential requirement (personally I never took to autocompletion much except as a nice aide mémoire - I have a habit of writing over all the suggestions without stopping ).
The plugin pack from above will have installed a php.xml snippets file I wrote which will add updated snippets for common PHP structures (the defaults are not the usual conventions acceptable in PEAR CS) and includes a collection of Zend Framework snippets (the Snippet list prefixes them all with "ZF" so they are at the bottom of the PHP list) to make use of. Feel free to suggest changes/additions to those ZF snippets - maybe one day someone will build and release a TextMate bundle for Zend Framework which I can port more completely into gedit (or vice versa). The Textmate and gedit snippet syntaxes are not completely dissimilar.
Conclusion
Gnome's default editor is easy to dismiss as a serious programming tool, yet its simplicity and plugin architecture both enable a simple stable lightweight code editor that is capable of holding its own against a range of alternatives and which bears a few resemblances to Mac OS's much celebrated Textmate.
No, it's not an IDE, but it's a very good editor for many purposes when a full blown IDE is overkill. It's also a viable alternative for those who, like myself, avoid IDEs unless they are obviously needed. Since I use gedit a lot (as in everyday!) for my code editing, the approach above simply makes a good thing even better. Maybe one day they'll even get around to adding code folding and I can call it a day .
Still, if gedit does not strike your fancy there are lots of other editors to try out for Linux with varying option bundles. Emacs and vim remain ever popular (after you survive their attrocious interface and realise what gems they are), and in the lightweight category we have options like jedit, scribes or geany. Hopefully this paragraph cuts off the inevitable suggestions about choosing a "real" editor (like any IDE-Bloat-Of-Doom).
I use Geany before I read your post... now I totally switch to GEdit.
But can you help me please with this error I get when trying to install the third party plug-ins?:
dumitru@dumitru:~/Desktop/padraic-gedit-mate-381a51930ecb25e30ce3a00ad0e480deea446bcf$ sudo ./install.sh Error in type 'application/x-php' (in /usr/share/mime/packages/zendframework.xml):
* Unknown freedesktop.org field 'generic-icon'.
I removed the offending line in zendframework.php - I'm on Ubuntu Intrepid so some other Linux flavours or version might not recognise the problem field/mime. Grab a fresh download with the change and see if that works.
Well i know gedit as a slim and fast editor for Linux, but i wouldn´t use it for more Development.
For me it is a good solution to view anything fast and more comfortable than vi.
For other stuff i prefer an Zend or Eclipse
I'll only venture that there are a bunch of people who will never adopt Eclipse or any IDE (or vi), or at least won't adopt them for everything. For some people, simplicity of nature and sheer performance are more powerful feature preferences and this is where alternatives like gedit fit the bill.
That isn't to devalue IDEs - they are really excellent tools in the right circumstances with the right person. Not all people are alike however.
Nice post, Paddy. This solidifies a position I've maintained for some time, however: in order to be an effective programmer, you need to learn your editor backwards and forwards, and also how to extend it. (Non-extensible editors are of no value to a developer.)
It looks like you've put the same effort into making gedit a productive environment as I have into making vim a productive environment -- and when you have an editor with a slim footprint that has a ton of power... IDEs tend to lose their allure.
#5
Matthew Weier O'Phinney
(Homepage)
on
2009-02-04 21:44
(Reply)
Knowing how to extend your editor is one of those things every programmer should learn. One of the things about gedit I liked was that plugins can be written against GtkSourceView2 using Python, leaving C only for those times you need C libs.
Nice post,
this is exactly the same configuration I use with gedit: folders viewer, gray color theme, and terminal. I mostly program with higher-lever IDEs but for rapid hacks gedit is insuperable.
So Eclipse is slow, fat and bloated? I heart that argument when PC's had 256 MB and then 512 MB.
Now the newest PC-generation comes with 8 GB! And I'm sure I will hear again the "Eclipse is slow, fat and bloated" even with 8 GB 4 Cores and probably with 16 GB 8 cores too and so on...
Could it be that some of yer Linux-freaks are simply out of touch with reality? Or maybe you hate IDE's like Eclipse for religious reasons?
Eclipse takes less then 5% memory with a 4 GB PC. It (warm-)starts immediately on a 1 GB PC. And you call that slow, fat and bloated? Get real, pal!
"I heart that argument when PC's had 256 MB and then 512 MB."
Could swear I played high resolution 3D games on hardware at that level. What's the excuse of a Text Editor? Sorry, it's not fair to compare Eclipse to a major driver of performance advancement in Desktop PCs. Stupid me.
"Now the newest PC-generation comes with 8 GB!"
If you stump up the extra cash over the 2GB model, and get yourself some pretty shiny DDR3 instead of that DDR2 ancient technology.
"And I'm sure I will hear again the "Eclipse is slow, fat and bloated" even with 8 GB 4 Cores and probably with 16 GB 8 cores too and so on..."
Eventually you'll reach a point where quantum computing can fold Eclipse onto a few dozen spinning electrons and all will be right in the world. I see your point though - Eclipse is not a hog so long as you use 25th Century technology. What about those still here in the 21st, or even the 20th? Do we need a gaming rig so Eclipse can feel less guilty?
"Could it be that some of yer Linux-freaks are simply out of touch with reality?"
Ah, it's because Linux people are freaks and gedit is a Linux editor and therefore freakish? What's that got to do with Eclipse? It runs on Linux, you know. And isn't Java developed by similarly freakish folk who distribute an even freakier operating system? Maybe we're all freaks at heart - the philosophy bears further examination whenever you get over yourself. Speaking of philosophy, if I refuse to observe you, do you really exist?
"Or maybe you hate IDE's like Eclipse for religious reasons?"
I discussed the matter earlier today with Father Ted Crilly, Father Dougal McGuire and Father Jack Hackett of the Catholic Church who are well regarded experts on religion here in Ireland and the UK. They assure me that God does not hate Eclipse, assuming it is not an inspiration of Satan, the Antichrist, George W. Bush, or Brian Cowen.
"Eclipse takes less then 5% memory with a 4 GB PC."
Wow. It sure knows how to store text files in memory. Now THAT's a text editor.
"It (warm-)starts immediately on a 1 GB PC."
Impressive! Wait a minute...what's that "warm-" thing you're hiding in brackets you tricksy Hobbit!
"And you call that slow, fat and bloated?"
Nah. I see the error of my ways! It's a lean, mean fighting machines sent back in time by Skynet to edit the crap out of the world. That explains the 25th century technological requirements!
On a serious note - I use Eclipse all the time and have done since...since...forever. I know what it is.
Hmmm...forking the original plugin collection inherited missing plugins . I'm going to add the missing ones (they have updated alternatives and I think a lot went AWOL because of GtkSourceView2 being introduced which vastly improved Gnome plugin support).
Updated the repository with some missing plugins including a more focused version of Snap Open. I added the Word Completion plugin but I may swap it in the future for a more advanced version (there is one but it needs compiling for full support so it's currently omitted to keep things simple to install).
As i'm only interested in your updated php snippets, I looked at your install script. Then I copied php.xml to ~/.gnome2/gedit/snippets/ directory.
However now all PHP snippets are doubled (excepting the new Zend snippets). The original ones are not updated. As they share the same keywords, there might be a problem ?
I also tried to replace /usr/share/gedit-2/plugins/snippets/php.xml with your version instead, without success. There is no changes to the default PHP snippets list.
The formats may differ since Snippet's originally had no import/export function and doubtlessly the new feature demanded some adjustments to the external editable XML from the then internal variant. So long as the plugin parses both correctly it shouldn't be a problem.
I updated the install instructions in git for the default snippet file removal. It will remain as a manual instruction since I don't really like forcing that kind of global change onto users via an install script.
I assume your grasp of English is superior to mine. That would explain why saying Gedit can be like TextMate, really means Gedit is identical to TextMate. I should probably brush off my English textbook.
That or you're just being pedantic. Gedit with a few plugins can be like TextMate. Sufficiently so that people can use it freely without remortgaging their homes to buy a new Mac just to get the real TextMate .
Gedit is a fine text editor indeed. Still, Gedit compared to Bluefish on performance is like Eclipse compared to Gedit
It doesn't have a plugin system in the current stable version but the current unstable version does... Except that that atm still loads up a bit slower
Thanks P! Where do you find the time my friend? Duh... with a bag o tricks like these of course!
Gedit with default Intrepid plugins was working well. Now it's working very well! Thanks! I'm liking that DarkMate also. I never took the time to build a color scheme to my liking for a dark bg; many thanks to all!
I've had the best luck with Netbeans for a PHP IDE but greatly prefer to stay in gedit; especially now.