How I learned to love VIM in 7 days
November 27, 2010
VIM is a text-editor, that has a steep learning curve. The first days were frustrating, because a lot of simple tasks just doesn’t work out in the usual way.
Here are my tips, that should help other people who want to give VIM a try:
- I first tried VIM, later on I switched to MacVim. MacVim has a few advantages over the OSX Terminal-Vim:
- Tabs are a great way to keep multiple instance of vim editors open. When you use VIM-Windows for a lot of files you easily loose focus. Tabs are easier to handle.
- The Fullscreen mode of MacVim is really nice.
- It has bindings to the standard OS X Keyboard shortcuts.
- Mouse support works very well (for example resizing VIM-Windows)
- I suggest you to use the default VIM at first to learn the basics: how to navigate, edit, copy/paste, search/replace etc, then later switch to MacVim to use advantages of both worlds.
- At first I installed plugins the common way. I copied plugin files and/or syntax files in special folders. It was okay, but I discovered a better, more easier way to do it later on: Vim-Addon-Manager.
- This one is not VIM specific, but it helped me to work much faster: I minimized the keyboard repeat delay rate with the following shell command:
defaults write NSGlobalDomain KeyRepeat -int 0
- When you start to work with VIM you often need to adjust the settings, so I added the following entry to my .vimrc:
map <F12> :edit ~/.vimrc<CR>
and the following line to .gvimrc:
map <F12> :tabedit ~/.vimrc<CR>
Now, when I press F12 the config file opens up directly (in MacVim in a new tab).
- In Eclipse I often use ALT-CursorUp/Down to move lines, well, you guessed it, up and down. With the following settings it’s also possible with VIM (Shift-K / Shift-J):
" Bubble single lines nmap <S-K> ddkP nmap <S-J> ddp " Bubble multiple lines vmap <S-K> xkP`[V`] vmap <S-J> xp`[V`]
- I also have done a lot of other mappings. I mapped various plugins and tasks like FuzzyFinder, NERDTree, moving through VIM-Windows, etc. to special keys. This is really great in VIM – you can configure everything the way you like it.
- I tried some plugins. Here are the ones that I like most:
- FuzzyFinder – Surf through your filesystem with wildcards.
NERDTree – the explorer/finder for VIM. In MacVim there is an ugly scrollbar when you open NERDTree. The following line disables it:
Taglist – Shows variables, classes, functions. Similar to an outline browser. With the following command you can create a tagfile of your complete project, which is very helpful sometimes:
- snipMate – Incredible helpful tool: You can create code templates. This improves productivity a lot. A must have!
- tComment – Comment in/out lines in your source.
- It’s possible to compile directly from within VIM using the make command. I have added a make.sh file into my Haxe project folder that looks like that:
#!/bin/bash cd ~/Documents/Haxe/Demo/ haxe project.hxml
Then I added the following lines to my .vimrc
let g:haxe_build_hxml="/Users/jochenheizmann/Documents/Haxe/Demo/project.hxml" set makeprg=~/Documents/Haxe/Demo/make.sh map <F5> :w!<CR>:make<CR>:copen<CR><C-w>6-<CR>
If I press F5 in VIM it starts to compile the project, then if any compiler errors found it opens a small quicklist window where I can browse through the source files and errors. Great!
Omnicron doesn’t work yet
The only thing I still have problems with is the omnicron code-completion. I have tried various things, but if I open the autocompletion in VIM for an object, it shows up a lot of methods and members that don’t belong to the selected object. I think it is easier to setup it for other languages (I will try that soon), but for Haxe it didn’t worked out so fine. If you have any tips for me how to make it work, please let me know.
However, I really like VIM. If you learned the most important shortcuts and commands, you can work very fast.
I will use it for at least one month, then I decide if I continue to code my projects in it or not. It’s already my default texteditor.
Here are some nice resources that helped me to get started (thanks to my twitter followers for recommend them to me):
- vimtutor (type vimtutor in your shell and follow the tutorial)
- Vim Cheat Sheet – Useful to look up the most common shortcuts
- Best Vim Tips
- Alternative Vim Cheat Sheet
- Vimcasts.org – Great tutorial videos
- Youtube: Top Vim Plugins – This video shows some vim plugins in action
- Vim Addon-Manager
- Vim Website
You can find my vim configuration at github.