It is a truth universally acknowledged that a developer, with a job to do must be in want of a good text editor.

Text editors are a topic which will be argued over until the end of time. Classic arguments start as Vim v Emacs, move towards Textmate and recently steer close to Sublime. Note here, I’m not talking IDEs – IDEs are often toolchain specific and have their own set of arguments. Text editors are religions unto themselves, and there are thousands of blog posts already devoted to their own relative merits.

After spending lots of time with various editors, and some time spent with a particular friend, I’ve come back to the venerable Vim. Vim does not make learning easy, but it’s operating language and grammar are very flexible and (to me) a joy to use.

Vim does not make the beginner’s life easy. The learning curve is notoriously steep before you really feel the benefits of it. Below are some of my own tips which will hopefully help you make the jump, should you be willing.

In a future blog post, I’ll discuss editing C# and .NET with VIM.

Learning Vim

Vimtutor is a built in system designed to make learning the Vim basics simple. Personally, I found it a waste of space and frustrating.

First let us accept that Vim does not like beginners. For those not familar with modal editing (and who the hell is?), it’s confusing, archaic, and really slow to do simple things. Once you’ve learned the syntax, the grammar, the why, and how it all fits together, then it becomes a thing of beauty. So put down those one page blog tutorials and pick up “Learning the vi and Vim Editors” from O’Reilly. Read it cover to cover (it’s okay to skip the sections on other vi clones). It’s well written, and gives you a truly thorough understanding of vi, vim and ex. Read the book, make notes, go play. Learn.

Plain Text File Configuration

Vim configuration files come in plain text. Developers love plain text. It stores nicely in version control, and vim’s configurations are portable between platforms (you can even stick in statements for platform specific configuration). This makes them easy to dump in a git repository and deploy on to any working environment. Mine are available here:

https://github.com/kianryan/.vim

If you’re working in more than one graphical environment, have a look at /rc/.gvimrc for setting platform specific options.

Pathogen

Vim plugins are traditionally a bit of a mess. By default, Vim expects all plugins to be stored in a single folder, all doc files to be stored in another folder, etc. This makes separation of different plugins a bit tricky, and ongoing updates quite hard. Pathogen allows each plugin to be stored in a separate folder, and as such each plugin can be managed independently.

Git also allows you to add other repositories as submodules. With Pathogen and Git, plugin repositories (and most useful ones are now stored in git) can be added as submodules to your git repo. Setting up on a new platform becomes git clone, git submodule init. Updating all your plugins simply means fast-forwarding the plugin versions to head.

Plugins

Vim is a veritable candy-shop when it comes to plugins. There are plugins to cope with almost any language, any environment and idea you’ve possibly had. Most plugins happily co-exist with each other (see Pathogen). There is nothing wrong with using an army of plugins, when you understand what’s going on underneath the hood. Spend some time with the vanilla editor before jumping in to plugins, so you’re using them as extensions, not crutches. With that warning, here’s the list of plugins I’m currently using:

  • NavigationNERDTree (Folder view in a buffer) and Command-T (Search and open files)
  • Colour SchemesCSApprox (Approximates full colour schemes to 88 and 256 colours)
  • CommentsNERDComment (Easy comment management)
  • Brackets and Closing ThingsMatchIt (Advanced paren matching), delimitMate (Auto closing brackets), Vim-Surround (Change surrounding quotes and xml tags), CloseTag (auto tag closing).
  • SnippetsSnipMate (Snippet management)

Vim Fullscreen

Not a plugin per-se, but a DLL extension for Win32 gVim which allows you to run gVim full screen. Map it to leader command and you’ve got a few keystrokes to toggle in and out full screen. This makes for a great, immersive environment.

I’m currently editing this blog post in the following session:

(Notes: gvim for Windows. No buttons, scroll bars or chroming. Vim fullscreen. Three windows, left and right showing the same empty buffer, middle showing the blog post with the vim-markdown plugin)

Tinker

Vim is highly configurable and extensible. That is one of its beauties and downfalls. You will find yourself spending a lot of time tinkering to make the environment what you want it to be. Color schemes, UI options, key mappings, your configs will mature and age with time. This tinker time may feel like a time-sink (and the initial setup probably will be), but you’ll reap the overall benefits later on. Spend the time making your Vim setup what you want it to be.