vim

vim is a command line text editor popular among Linux and Unix users. It is an extension of the famous vi editor, and is (as I see it) one of the “big two” editors in the open source world, the other being emacs. These two are often seen in techie comic strips and are frequently at the heart of deep-felt religious debates.

I’ve always known enough about vim to use it at a basic level. When developing on Linux, you inevitably need to use it at some point, usually when doing some work on a remote server. I had been fumbling along with the fairly decent jEdit for some time; it did all I needed it to do and served me quite well, but I decided that at some point I would have to take a leap of faith and move to that higher level of development know-how; I would have to fully learn one of the big two. I would have to learn vim (I tried emacs once but I just didn’t like it that much!).

The learning curve is pretty steep though; steep enough to keep me from using it seriously until now, and if it wasn’t for a couple of things that happened recently, I may not have taken the plunge. An ever increasing sluggishness presumably caused by my use of several Java apps and the discovery of the rather nifty Grep plugin for vim pushed me over the edge: a want to drop jEdit and the one tool I needed to do my work, a “find in files” type function for my editor of choice.

It’s been a taxing week. Every little thing that is so instinctive in your old editor needs to be looked up on the web, noted and memorised; and with vim, such things are usually radically different. Even saving a file requires the command :w, whereas in most other IDEs and editors it is the classic Ctrl+s. Yet, despite all this, I am starting to feel the power behind it, and can understand the decades of praise and hype that it has received. The major benefit is that you never need to use your mouse, and with it running directly from the command line, you can switch to another shell to do anything else you need to do, again without the mouse. The “command mode” allows you to navigate around the document without even using the arrow keys, meaning you can do your work without your fingers even leaving the home keys! Talk about efficient. (I am finding my general typing skills improving as I use vim more and more; another thing I’ve been meaning to work on that is being fixed by the switch.)

As mentioned, I noted down some of the commands I looked up and wanted to remember; some of which are listed below. I also found the VIM Quick Reference Card very helpful and had to laugh at a Vim Introduction and Tutorial:

I often tried to learn the great Emacs editor/IDE/operating system. The last time I tried it, I spent some time getting comfortable with it until I wanted to customize my .emacs file.

That was the point when I entered vi .emacs. As soon as I realized what I’ve done, I knew that Vim has won me over a long time ago.

Anyway, here’s my list:

  • gt, gT – goto next/prev tab
  • Rgrep
    • Rgrep PATTERN *
    • :ccl – close quickfix buffer
    • :cwindow – open quickfix buffer
    • quickfix
    • :let Grep_Default_Filelist = ‘*.c *.cpp *.asm’
  • :ls – list all buffers
  • :b 1 – jump to buffer number 1
  • ctags -R *
    • ctrl ] – jump to sub/method definition
    • ctrl t – go back to where you came from
    • ctrl i and ctrl o – traverse the tag stack
  • ctrl G – show current filename
  • :e – reload buffer from disk
  • ctrl [ – same as ESC; exit editing mode
  • * – jump to next occurrence of word under cursor
  • # – jump to previous occurrence of word under cursor

I urge you to use and learn this great editor, maybe starting with some of the resources mentioned here. Even from my brief time using it, I can tell that the effort is more than worth it in the long run. For years it has been designed and refined to make editing code fast, easy and intuitive. I’m the words of a friend and former colleague, vi rocks man!