About a month ago, I decided that I would try and switch to Vim as my only editor. I’ve been a pretty hard core Textmate for about 5 years now, and haven’t really had any issues. So why bother switching? My first reason is I spend a ton of time in SSH + terminals. Due to working with many headless virtual machines and computers in far-away lands, I’m in a terminal quite often. There is no Textmate in a terminal, so I used vim. Having to remember two sets of keyboard commands to do the same thing started to bug me. I’ve also seen people work pretty damn fast in vim if they knew what they were doing. Being able to get faster at something I do all day grabbed my interest as well.
While vim is already installed in most non-windows computers, I also installed MacVim mostly so I could get some normal OSX bindings, and ease myself into vim. MacVim also supports more colours than terminal vim which is nice. I heard one of the keys to using vim is to get a good
.vimrc file. So after installing MacVim, I installed Janus. While Janus is a bit ruby focused, it comes with a number of great plugins all bundled together, so Vim noobs like me can figure things out. I’ve since forked Janus into my github account , which I use to keep my vim config in sync across my various computers. I’ve added a few more python and PHP specific plugins, as that is what I spend most of my time working with.
I started off learning vim using
vimtutor. It covers most of the essentials, such as vim’s modes, movement commands and how to make changes to text. The most helpful things I found to try and master at the beginning were modes, and movement. Getting into and out of the various modes is critical to getting work done. Learning the various movement commands, helps you more efficiently get around in your files, and is a big part of vim’s power. Knowing the movement commands, also plays nicely with most other commands, making them more powerful as well. The next topic, I spent time learning was buffers, windows and registers. These features really exposed the power vim has, and got me hooked on using vim. Having more than one clipboard, and split windows, are pretty powerful features, and ones I found lacking in textmate. Of course the most important and useful command of them all is
:help. This lets you peruse the extensive built-in help, which has been more helpful than any other editor’s help.
Navigating your code
Getting around a big code base is really important to me, as I work on a few fairly large code bases. I routinely use Ack.vim to quickly grep through code. Command-T is also really helpful here as well. I also use vim’s ctags support as well. Once you’ve generated a
tags file with exuberant tags you can use
CTRL-] to navigate to function definitions, and
CTRL-T to go back to where you were. Vim also has fantastic searching, and
* are your friends.
Janus includes a pile of plugin, most of which I don’t think I’ve used. There are a few I use everyday, all day though. I pretty much always have NERDTree open. It allows you to easily explore a project, and open files in split windows or tabs. I also use command-t all day. I loved the equivalent command in TextMate, and being able to use it in vim is awesome. I also find ZoomWin pretty handy. There are a few more great plugins I use, but those stand out to me.
Since I’ve only just started using vim, there are a few things I did quite easily with TextMate, but are a bit more challenging in vim – at least how I’m doing things. Hopefully, I’m doing them wrong and there is an easier way.
- Creating new files. Currently I use
:!touch /path/to/file.extto create new files. It feels kind of clunky and I hope there is a nice way to do this.
- Renaming files. Currently I use
:!mvto do this, again it feels a bit clunky.
- Remembering all the commands. Vim has a mountain of commands to remember, and it can be extremely daunting to remember them all.