Why I use vim

04 Aug, 2022 (updated: 24 Oct, 2022)
1555 words | 8 min to read | 4 hr, 40 min to write

My editor of choice for over a decade is vim. Initially I was looking to substitute NetBeans (version 6 or 7 back then, if I’m recalling correctly, it was circa 2011 or around that) with something more lightweight. I’ve been working with a very large codebase (around 2 million lines of code including vendor dependencies) and NetBeans would index the code for ages, so I wasn’t happy with it.

People on the Internet were suggesting some other IDEs (I tried all of them, they were either slow or clumsy, or both) and every so often people would suggested vim (and sometimes emacs). After trying all the IDEs I decided to give emacs a shot. It looked to be more powerful than vim. And it is, - people jockingly call it an operating system with and editor not without a reason.

But emacs didn’t feel quite right for me. Instead of explaining why, I will just leave this meme here:

These days I’d probably be okay with something like spacemacs or Doom Emacs, but since I already settled on vim, emacs’ main use remains the same for me - to play tetris (M-x tetris). The other thing that I’d use emacs for would be org-mode, which is fantastic. And I did use it for a while. But the thing with is I’m not very organised as a person, and so the habit didn’t stick. Not sure if I need to mention I later tried evernote, and now using notion and doing marginally better (in terms of being organised).

For all the emacs users who are not using spacemacs or doom, I hope your fingers are still straight ;)

Hate at first sight

So I did try vim and it was… TERRIBLE!

Why, oh my god, WHY would you ever thought modular CLI-based editor could be a good idea? I mean, don’t I want to open up the editor and start editing right away?

I could understand how navigation using hjkl made sense. At least they all are on the home row on the keyboard. I get that. But modes really drove me crazy.

And, of course, first time I’ve opened vim, I couldn’t close it without google’s help.

So, I really absolutely hated it.

Lesser evil

I got back using NetBeans. But the more I used it the more irritated I was with the sluggishness. People on the Internet still suggested vim. I also knew that vim comes with all the major Linux distors, so I thought an implied benefit of learning how to use vim would also be becoming more comfortable editing files on remote machines via ssh.

System admins in the company I was working for did use vim, and I saw them editing files and it didn’t look like they struggle at all. Editing seemed pretty fluid and relaxed.

Habit. I just need to develop a habit and I’ll be fine.

So I did use the vimtutor and got used to the modes and basic editing and it still felt awkward, but hey! I could actually edit files.

I also was amazed by the speed. Compared to my IDE it was BLAZING FAST!

So now, whenever I knew I’d need to edit a big file, I would sometimes do it in vim instead of the IDE. In a couple of weeks I was okay(-ish) with editing files without constantly glancing at a cheatsheet.

Bit by bit, the habit has been building up. But I was missing some IDE features. Such as navigation to a symbol, search in files, code autocompletion, refactoing tools, etc.

I partially solved the issue using ctags (balst from the 2012 down below, haha):

let Tlist_Ctags_Cmd = "/usr/bin/ctags"
let Tlist_WinWidth = 50
map <F4> :TlistToggle<cr>
map <F9> :!/usr/bin/ctags -R --PHP-kinds=cfiv --fields=+iaS --extra=+q --exclude=".svn" --exclude=".js" --exclude=".css" --regex-PHP="/(abstract)?\s+class\s+([^ ]+)/\2/c/" --regex-PHP="/(static\|abstract\|public\|protected\|private)\s+(final\s+)?function\s+(\&\s+)?([^ (]+)/\4/f/" --regex-PHP="/interface\s+([^ ]+)/\1/i/" --regex-PHP="/\$([a-zA-Z_][a-zA-Z0-9_]*)/\1/v/" .<CR>

For searching in files, project tree, svn (this is what my company used back then) and git integration there were plugins and they were okay.

The only thing that was lacking were refactoring tools and a debugger. But I could sacrifice this inconvenience for better performance, and I could always do once-off things in IDE.

In couple of months, I was hooked.

How tf do you use arrow keys?

As I was getting more and more into using vim, I was getting more and more out of using any other editors and IDEs.

vim just provided me so much:

  • I can configure vim they way I want (it does take effort, but it worth it long-term)
  • Heck, I can bind anything to any keystroke!
  • There are plugins available for most of the desired things
  • Macros are just fantastic
  • hjkl navigation is SO MUCH better than using arrow keys
  • Slicing and dicing windows (panes in tmux terminology) is a breathe
  • Terminal is always at my finger tips
  • Ability to mark a location and jump back to it at any tim. Why even modern IDEs don’t have this feature, or do they?
  • Much hated modes are an AMAZING design! Navigation is better in navigation (normal) mode. Editing is better in insert mode. Does it not just make perfect sense?

As I was falling in love with vim, I began to realise there is no way back. IDEs felt clumsy. They were monstrous, non-flexible, and sluggish.

But as the time went by, I was still curious how the IDEs are doing. So from time to time I’d check a random IDE that’d be popular at any given time. And boy, it always was a dissapointment! They were faster, yes (probably because my PC was more capable?), but they didn’t tick even half of those things I’ve listed up above. But what REALLY drove me crazy is NAVIGATION.

Without normal mode and hjkl (as well as other things like <N>dd, visual mode, f<symbol>, m<location>, etc) editing was unbearable. You see, when I’m writing an article, it may be fine to do it in something like Microsoft Word or any other word processor or editor. It’s okay since this process is mostly forward-only (left-to-right), no much jumping around. On the other hand, when I’m working with code, I jump between different files, and different parts of those files A LOT.

And this is precisely what vim (well, initially, vi) was built for - WORKING WITH CODE

Mastering vim

This is no vim user out there who’s totally satisfied with their vim setup. Tinkering with .vimrc is almost like a hobby. When I find something that doesnt suit me, I’ll find a solution for it.

For instance, not so long ago I had an itch. Since I’m using github for collaboration a lot, I wanted to have a key-binding that’d take me to the current file (as well as branch and line I’m on) on github.

Soon, after learning a bit of gh’s API I came up the the solution.

nnoremap <silent> <Leader>gh :exe "!gh browse " . shellescape(expand("%:.")) . ":" . line(".") . " --branch (git rev-parse --abbrev-ref HEAD)" <CR>

So, when I do <leader>gh, it will take me to my browser and open up github for the file I’m currently on.

And it’s like this with everything else. You continuously improve your setup. You tailor it to exactly what fits you!

Conclusion a.k.a. Could you also be interested?

If you give vim a chance, you’ll be up to a couple (maybe more) weeks of stuggle.

But unlimately you may find yourself on a very exiting journey perfecting your setup which may be worth it in a long run.

Addendum: Special notes

Special note on neovim

I “dig” nvim (built-in LSP, lua API), and my setup is compatible with both vim and nvim, but I still prefer vim due to exactly 2 reasons:

  • most of the linux distros are shipped with vim (I have my own reasons why this is a legit argument)
  • vim has encryption which I rely on a lot

And for now, I don’t see nvim is too much superior to vim.

I think you can’t go wrong with either.

Special note on vim distributions

There are vim distributions such as spf13-vim, spacevim, janus, and others.

I don’t like any.

Most of them are not maintained anymore. But the main reason I don’t like those is they throw too many things at you, and then you need MUCH more time to “fix” any distro to your personal liking than you’d spend tuning vim from scratch.

VIM is a hackable editor. YOU tailor it to your exact needs and wishes. Those distros, albeit not being bad, are not tailored for you. They are are somebody else’s setup. And it’s not bad to borrow something from somebody, - I did it A LOT myself. Feel free to “steal” anything from my setup. But there is no chance you can simply copy the whole setup of someone’s and be okay with it.

So those distros include plugins you never need. They configure plugins you need not the way you want. They have presets that don’t make sense for your personal use. And since it’s the way it is, good luck fixing all this to suit you.

Special note on gvim