Although I am a Linux user from 1995, which is over 20 years now, I never understood Vim. Sure, I knew how to do simple
edits and how to quit the editor, but it never clicked with me. I also felt that the editor was over-engineered for what I
used it for, which was simple edits in configuration files. For programming I used Integrated Development Environments (IDE)
and for my school work I used StarOffice (now OpenOffice), and a graphical editor.
Although I’ve compiled my kernel, built Linux from scratch, had a dual boot Windows/Linux and even replaced Windows entirely
with Linux, I avoided Vim. Vim is almost always available on Linux systems, so I had to install alternate text editors on Linux systems,
so that I could edit files. But now that I’m a Cloud Consultant, I have a lot of console work, and my past comes back to haunt me
which motivates me to bust that ghost!
Vim or Vi-improved is a command-line text editor for Linux and Mac. The text editor was originally created by Bram Molenaar
in 1988 for the Commodore Amiga, but is now available as the standard editor in most Linux and Mac systems. Vim uses a text
user interface to edit text through the command line and keyboard. What makes Vim different than text editors like Sublime Text,
Visual Studio Code, or Nano is that it provides a grammar for editing text. Once provisioned with the vocabulary, it becomes
very easy to edit text with a minimum of effort and without even touching the mouse.
Vim is a very different editor than we are used to. Vim speaks a language to edit text. The language consists of
verbs, modifier and noun. These can be combined to create sentences in the form of ‘verb modifier noun’ that Vim
understands to edit text.
Verbs are actions for example:
- Visual (v),
- Copy (y),
- Paste (p),
- Change (c),
- Delete (d),
Nouns are things in the document for example:
- The current line (0),
- The end of the current line ($),
- The line below the current line (j),
- The line above the current line (k),
- A word (w),
- A sentense (s),
- A paragraph (p),
Modifiers define how Nouns should be interpreted, for example:
- inside (i),
- around (a),
- find (f),
- search (/),
The Vim verbs, modifier and nouns can be combined to create edit sentences. For example, if we want to delete a
word the sentence to create is delete, inside, word, which translates to diw. To edit the current sentence
from the first capital to the dot, we would say change, inside, sentence which translates to cis. To select
a whole paragraph of text, the sentence becomes visual, inside paragraph, copy which translates to Vipy
If we would type these sentences into a normal editor you would see eg. ‘diw’ in your text and nothing would happen.
This is because a normal editor doesn’t have a ‘normal’ mode. A normal mode is special to Vim, which is the mode where
it interprets sentences you type into the editor. Because Vim starts in the normal mode, it trips beginners, like me,
because they don’t understand the language of Vim, and when users start to type, the sentences do not make sense to Vim.
Vim provides different ‘modes’ where the editor behaves differently on user input. In the ‘normal’ mode, Vim interprets
the Vim sentences, which are great for fast and efficient editing. In the ‘insert’ mode, Vim behaves like any other
editor and allows free form text editing. The ‘visual’ mode is for text manipulation and text selection. The ‘command’
mode lets you type commands like ‘:q!’ to exit Vim without saving. There are a lot more modes but these three are the
basic modes you need to know.
There are a lot of resources on the internet like vim adventures, which is an online
adventure game that teaches the basics of the Vim language, navigation, selection and editing. On the console, you can
vimtutor that launches a tutorial that teaches the basics of Vim. When you have learned the basics of Vim, the
integrated ‘:help’ system is a great resource on verbs, nouns, modifiers, modes and so on.
The Vim language is intriguing, and for a programmer like me, a challenge. To learn a language, you have to speak it
often and try out sentences and see what the result is. It would be a shame if so much power is only available on the
command-line. Fortunately there are graphical editors that have Vim support like the products from Jetbrains like
PyCharm, IntelliJ, GoLand and so on. By installing ‘IdeaVim’ plugin, the editor supports the ‘normal’, ‘insert’, ‘visual’
and ‘command’ mode and all of the Vim vocabulary to start creating sentences.
What motivates me to learn Vim is a standard way of editing text. The Vim language provides a solution for encoding
editor functions as a language. A language is easy to learn for humans, and provides a way to communicate complex behaviors
in a simple way. Because editing text is like communicating behavior, by learning a language, we can communicate complex
editing behavior. A language also allows for communicating the behavior with a minimum of words. By just learning a few
verbs, modifiers and nouns, we can encode hundreds of operations.
The downside of normal editors is that they use shortcuts for a single behavior. Because shortcuts are limited,
editors do not provide much of editing behavior at all. To make things worse, these shortcuts change across editors
so for every new editor you have to learn the shortcuts all over again.
Because a Vim plugin is available for most editors, learning the Vim language provides a standard across editors.
Where to start
The verbs, modifiers and nouns shown at the top is enough to get going. Write down the sentences you use the most when
editing text and try to make sense out of the sentence. Do not learn the letters but say them quietly in your head.
In my opinion, the biggest hurdle to Vim is to get used to a new way of navigating. Once you get used to navigating
and the Vim language, try to install the ‘IdeaVim’ plugin and try out some development using the Vim language. Chances
are that you like the new way of editing text.
Vim is a very interesting editor. By combining verbs, modifiers and nouns, you can communicate with Vim. The language
expresses operations, text objects and motion, which controls the editor flow. I’m still very new to Vim, but as you can
read I am very excited about the editor and most importantly, I have busted my ghost!