I use Vim as my editor of choice for all of my programming work these days. Lately, I’ve begun to scratch the surface of the more advanced features of the editor and it’s rather brilliant extensibility.
IDEs, in my experience, tend to be rather heavy affairs ([Aptana] on OS X weighs in at a whopping 130MiB). Often, they’ll include their own version of things which you already have on your computer if you’re using it for development.
Do you really need this duplication? I don’t think so. I think that you need to be able to efficiently edit your source code files; be able to interact with the environment your programming for and, if possible, not waste precious storage space.
Isn’t Vim harder to understand than Chinese Algebra?
Vim has a reputation of almost mythic proportions about its flexibility, powerful feature set and steep learning learning curve and tetchy way of editing and interacting with files.
Drew Neil is going a long way to dispel the myth of Vim being difficult to use with his excellent VimCasts. They are a series of well presented and well paced introductions to some of the more confusing aspects of using Vim.
OK – Fine, but you said ‘All the IDE’, tell me more!
IDEs give you a lot of functionality in one massive application. Applications like Aptana provide a complete environment for you to work with your projects and provide features to automate some of the ‘boiler plate’ work of creating software.
What can you expect from IDE? Well:
- Syntax completion (a la intellisense) and colouring
- Code Auto-indenting
- Integrated Shell / Command Line
- Some kind of DBMS manager
- Some kind of debugging support
You may be surprised to learn that not only can you do all this with Vim, but that most of the functionality is built in by default and is relatively straight-forward to use.
Syntax completion and colouring
Vim includes a powerful system for dealing with syntax colour and completion. Vim looks for a ‘dictionary’ file for each file-type that is knows about. It comes with a default set of files for colouring the syntax of pretty much every programming language which it is able to edit.
For code completion, you can generally press CTRL + N after you’ve started typing something and Vim will attempt to complete it using values from your other active buffers.
A lot of people are used to using Tab or Control + Tab to trigger their completion. You can, of course, map the key yourself in your .vimrc file; there is a rather good plugin called SuperTab, which allows you to do all of your insert-mode completion with the Tab key, it also plays rather nicely with other plugins.
Auto indentation is automatically available for you within Vim, and in most platforms it is on by default. If, however, you find you don’t have it, you’ll need to add the following to your .vimrc file (VIMRC on Windows): set autoindent
If you’re using separate indentation, syntax dictionary and highlighting definitions for each of the language code code in, you can also use: filetype plugin indent on
As of Vim 7.0 on most Linux distributions, this setting is enabled by default.
Integrated Shell / Command Line
By default, Vim provides a hand-full of ways to interact with your operating system’s shell from within the application – none of them are exactly the same as an ‘integrated’ shell – but they do certainly come in handy. The methods are:
The :shell command replaces your current Vim session with your operating system’s default shell (Linux / Unix / OS X) or MS DOS (Windows). When you exit the shell, you will be returned to Vim. None of the input or output within the shell is returned to Vim.
The :! command (Bang! Command) executes whichever you command you key in directly on the shell without ‘dropping’ you to it. You can also pass it the special argument % which will pass the command the path to the file currently being edited in the active buffer.
For example :!ruby -c % will check the Ruby syntax of the file in the active buffer. When the command execution has completed; you will be prompted to press enter to return to Vim.
The Read command :r is one way to open a file in Vim. You are able to chain it with the Bang command, :! to read the output of a command and place them in a vim buffer. This means you could use :r ! ruby -c % to run the above command and output it’s results in the current buffer.
However, since IDEs have shells integrated, what I really should be doing is telling you how to achieve that with Vim. While vim, by default, does not include this functionality; due to the extensible nature of Vim you are able to download and install a plugin which adds this ability.
If you’re on OS X, you’re going to need to get a new version of Vim, since the one the ships is not compatible with running Python. Luckily, you can swap it our for something better! MacVim is a brilliant replacement. If you’re on Snow Leopard, grab the latest Snapshot.
Luckily, if you’re on a fairly recent Linux distribution you probably have a compatible version of Vim already installed. Ubuntu users will need to sudo aptitude install vim-full.
Since the installation instructions are all ready there on Conque’s Website, you should go follow them.
Conque Shell is a unique and powerful addition to Vim which gives you access to your operating system’s shell from within a Vim buffer – effectively allowing you to treat it just like any other file you’re editing.
The only limitation Conque has is that it can not run *Curses based applications – this means you can’t use it to run Vim within Vim, or use IRSSI (yet).
A little later, I’ll add a post to the Tutorials section all about Conque and to go into greater detail of how to use it.
Here are some screenshots of Conque Shell working:
Some kind of DBMS manager
A fair few IDEs provide a rudimentary graphical application for interacting with the DBMS (Database) behind your application. They can be very pretty and certainly do make it easy to find records and tables within your database.
Using Conque Shell, you can effectly embed a MySQL / pgSQL / SQLite console in one of the buffers in Vim. This has the added benefit of giving you not only the ‘full power’ of your DBMS in one place, but letting you yank SQL from one Vim buffer and put it in another, and doing the same with the output.
Furthermore – Since you probably already have mysql or sqlite commands installed, there’s no need for you to download extra software to duplicate the functionality the already have.
Some kind of debugging support
Your IDE may well let you run your application in an interactive console and use any breakpointing functionality available in your language to allow you to debug interactively.
Using Conque Shell, you can easily achieve this. Since you can fire off your Ruby interpreter in it’s own buffer, or, if you’re a Rails developer, run ./script/server -d, you have full and direct access to your interpreter’s own debug functionality – and you’re able to yank and put form it’s buffer as if it was any other file you were editing.
This leads to something very powerful and directly more useful than the tiny little debugger consoles built into IDEs.