Learning Vim takes time, but once you master enough commands (keys), you understand why it is one of the most powerful editors out there. In this post some simple tips that helped (and still helps) me improving my Vim skills.


OK, like becoming a better programmer practice is everything, but to facilitate that you need to get out of your comfort zone. I used Textmate a lot on the mac and recently I was using Sublime for all my coding on each OS. If you are serious about learning Vim though, start using it for all your work. At the beginning you will not be able to do all things as fast as in your favorite (graphical) editor but that pushes you to learn the shortcuts / commands, and believe me: with Vim you can do it all! I think this is the most important step towards becoming a Vim ninja.

Start looking up key shortcuts / commands / combinations

featured image

This advice comes from destroy all software: when you don't know about the functionality of a certain key shortcut, look it up with :help . Go from unshifted keys, to shifted keys, to control keys as this is the order of importance of the keys. Check out the motion commands (:help motion.txt) as well. An important rule is to never repeat yourself, when you do it probably indicates a hole in your Vim knowledge (cheers Gary for this great piece of advice).

You can't remember all shortcuts in a week, but gradually over time you can learn quite a lot. Just by doing this I found out about f+char to go to the next char (so you can delete a phrase till the end dot by df.) , markers with 'm', named buffers, using w or e to go to next words including/excluding trailing spaces, and other less frequently used shortcuts. It is also important to learn useful combinations like diw (delete in word), or daw = deleting a word killing the adjacent white space as well, or copying or deleting till the end of the line, y$ and d$ respectively. Another very useful thing to try to grasp early on is repeating commands: . for repeating a command in normal mode, n/N for forward/backward repeated search and & to repeat a replacement (:s/foo/bar/g) operation.

Check out some books / resources about Vim

Even with some prior knowledge I found $ vimtutor a useful program to run and doublecheck, it takes +/- 20 min and towards the end there are some neat tricks. If you are at a beginner level or you have not used Vim in a while this is the best place to start (refresh).

Books: I am using Hacking Vim and Learning Vim to study and practice. They are invaluable. Learning Vim goes from basic to pretty advanced, I am halfway through and it is a really good resource. Hacking Vim is a cookbook and has tought me some useful tricks so far: cntrl+n for autocomplete, gd on a variable name to go to its initial definition (go to definition), .vimrc settings (see next), % to go to the end of a code block, g, / g; for go back of recent locations you made changes, g# / g* for search for the word your cursor is on, etc. It even introduces to Vim scripting!

Resources II) Google, stackoverflow and blogs

Yes everything is possible in Vim, for example I wanted to open multiple files, no problem : vim -p files and you open files in tabs, ct takes you to the next tab, in horizontal split? No problem, use vim -o files, or when editing a file, open a 2nd one in vertical split with ex command :vsp file2 - most I found by just googling and on stackoverflow. There is so much material out there, and practicing it bit by bit, making notes and doing it over and over again, you become faster and faster in Vim.

Make life easier with .vimrc

Try to tweak your config, I started pretty basic with just a few settings: set nu to set line numbers, mapleader for command-t you really should check out (also discovered this via the very useful destroy all software Vim screencasts), highlighting, etc. I probably end up with 100+ lines over time, but this small set of config settings is helpful already:

syntax on
let mapleader = ","
set nu
set cursorline
highlight CursorLine guibg=lightblue ctermbg=lightgray
set hls is
" <Ctrl-l> redraws the screen and removes any search highlighting.
nnoremap <silent> <C-l> :nohl<CR><C-l>

More Vim ...

I opened a category for Vim to share more tricks and resources in the future. Efficient use of a text editor is one of the fundamental tools of any software developer.

Your editor?

Would Vim be your editor of choice? Why or why not?

Bob Belderbos

Software Developer, Pythonista, Data Geek, Student of Life. About me