Learning more about Vim

I mentioned in a tweet recently that I’ve been using some form of Vi for about twenty years. It all started in college where we had highly advanced green screen monitors attached to a large Unix box. I can’t remember what Unix it was ran on that machine (it may have been UnixWare) but it was a far cry from the nice GNU interface we’re used to on modern Unix systems. Vim certainly was not a part of the default install.

However, Vim has been my editor of choice all my working life. All this time I’ve known I’m only scratching the surface of it’s functionality but only recently has it become clear how much. I can navigate through it with ease, open numerous files in separate splits, search/replace and of course vimdiff was partly responsible for every single WordPress MU release as I used it to pull over changes from WordPress.

So, thanks to /r/vim I discovered the following today:

  1. /r/vim_magic is indeed full of magic.
  2. More Instantly Better Vim is a great talk on some insane things to do with Vim.
  3. I had no idea Vim had tabs but I still prefer splits.
  4. snipMate.vim is a snippet plugin for Vim based on the snippets in TextMate. Around the turn of the century I had messed with abbreviations but this is way better. Found that here where there’s plenty more tips to read.
  5. Coming home to Vim is the story of the return of a TextMate user to Vim. Why didn’t I know about daX and diX?
  6. Since I use split files, I’m always tapping CTRL-w w or CTRL-w UP/DOWN to switch between splits. It never occurred to me that I could map the TAB like this to switch split files. TAB switches to the next split file, SHIFT-TAB hops back.

    map <Tab> <C-W>w
    map <S-Tab> <C-W>p

  7. I am tentatively mapping ; to : with nnoremap ; : but I probably won’t use it. My fingers are too used to LSHIFT-; to stop now. I’ve never used the ; command, I had to look it up to see what it did!

From my tweet comes some productivity tips. I have never used the Leader key. The shame, the shame!

So much to learn. I’ll probably leave comments on this post linking to all the bits and pieces I find. Yes, I’m excited about a bloody text editor. Haha!

Author: Donncha

Donncha Ɠ Caoimh is a software developer at Automattic and WordPress plugin developer. He posts photos at In Photos and can also be found on Google+ and Twitter.

4 thoughts on “Learning more about Vim”

  1. Here are my notes on vim, far from complete but might be a few nuggets in there.

    I tend to primarily use buffers instead of tabs, to be honest I don’t really know the difference. There’s a nifty plugin called “dwm” which does some nice managing of buffer windows and splits.

    Also if you didn’t come across them check out Derek Wyatt’s tutorials, both informative and fun.

  2. gj, gk, g0 and g$ all work on wrapped text. move cursor to a number. press C-a or C-x. Number increments or decrements.

    You type /foo to find the next occurrence of “foo”. But say that you were going to change some of those foos to fobs? You’d really like it if the cursor was on the second o, not the f. so type /fo\zso The \zs tells vim where to put your cursor. I use this about once or twice a week since I learned it.

    zz will put the line you’re editing in the center.

    type qa to start recording editing actions. press q to stop. recall those actions with @a. qb…b @b, qc…q @c, etc.

    Say you just want to replace text in a paragraph. The easy way to set this up is to type !} – now you’ll be at the bottom of the string with something like :.,+5! so just press backspace to delete the ! and replace it with s/old/new/ or g/bad stuff/d

Leave a Reply