Learn Vim

24-10-2021

I have been a vim user for almost 2 years now and I can no longer live without it. Everybody who does even a bit of text editing on a computer should learn vim.

Why

Vim is nothing like your traditional text editor. It has modes. In one mode each key acts as a command/hotkey while in another it just inserts text like normal. This is the biggest difference between vim and notepad or VSCode. While using vim you might as well throw away your mouse because it becomes obsolete. You thought Ctrl+D or Ctrl+] in VsCode was mindblowing? That's nothing. Vim is also great for the reason that it comes preinstalled on almost every unix or linux system out there. If not vim then vi must be there. I have seen many classmates using nano when sshing to lab machines and that seemed extremely painful, I have tried to liberate them with vim but not many listened.

Here are all the pros vim has:

And here are the cons:

The first 2 cons will go away after you spend a month or 2 with vim so they are no biggie. Basically you have no excuse to not learn it. You might be saying that you don't have time, but that's not true at all. I can guarantee that you waste some time, either by scrolling through reddit or instagram or by watching meme videos. Either way even if you lose some time now learning vim you'll get it back later from the productivity you gain. There are plenty of videos where vim users use macros(a feature in vim that allows you to record a set of commands and allows you to replay them) or different commands to do mass operations on text files.

Something else with which vim helps is that it teaches you to read a manual. Yes online articles and youtube videos are great but the built-in documentation is your best tool. Reading documentation is one of the best skills you can develop, especially if you are a programmer or if you are running linux.

Basic Vim

Here's how you work with vim. Immediately after you launch vim you are in what is called Normal mode. In this mode each key you press does something:

These are only a few examples

Then there's Insert mode which is the mode all editors have by default, where you can input text. Visual mode allows you to select text and Command Line mode allows you to input commands to the little command line at the bottom of vim. In total there are 13 modes but these 4 are the most important, in fact I just learned that there are 13 modes.

Now the absolute basic commands you need to know to start using vim are the following:

After you have learned these, you should start watching vim tutorials and reading articles on how to learn vim. I have some resources I used, linked in this article. Or you can just :help usr_01.txt

Vim has a configuration file called a vimrc which you will slowly start filling up as you progress with different settings and mappings you find useful. You can look at other people's vimrcs for inspiration but as a general rule of thumb you should only copy what you already understand. Vim also has many plugins which you will definitely use. I would recommend you start without any until you learn vim without the extras.

Lastly here are a few recommendations after you pass the beginner stage:

  1. Learn the :g and :s commands
  2. Learn text object operations like diw
  3. Do not under any circumstance use the arrow keys
  4. Use relative numbers
  5. Try to learn vim for at least a couple of months before deciding whether to continue or not
  6. Don't use tabs, use buffers

If you are still not convinced

If you think that you are a VsCode power user and you don't need vim then let me tell you that I knew a guy exactly like you. He pulled out the VsCode hotkey cheat sheet and he knew almost everything in there, it took a lot of convincing to get him to try vim. He ended up loving it. So my advice is try vim for a couple of months and then decide for yourself. Also there are plenty of vim plugins for IDEs so you can start using that before switching to vanilla vim. Finally just read this

Links