Vim can be quite confusing for beginners (just look at the upvotes).
But it’s actually not that hard and if you’re getting used to it, you might just x10 your efficiency.
If you’re typing for a few hours a day, it is definitely a good idea to spend some time becoming more efficient at what you’re doing. Typing somewhat near your speed of thought is also way more fun than always having to wait for your fingers to type what you thought about 10 seconds ago…
Getting used to the vim key bindings (or any uniform key binding scheme) doesn’t only enable you to edit text much faster and efficient, but is also essential for the use of any tiling window manager or keyboard controlled program in general.
I’ll only explain the basic concepts here, there’s already someone who gets you started with the actual use of the editor. I especially won’t list all available commands here. However, in order to get better at editing, it’s essential to have enough tools at hand, so go ahead and launch vimtutor!
The most important thing at the beginning is gaining a good overview of what the editor offers.
That’s what I’ll try to do in the following text.
:help <keyword> for finding offline help in the editor itself.
Hint: The commands shown here are to be executed in Normal mode. Press
Esc before entering a command if you’re not sure which mode you’re currently in.
There are 3 main modes in vim:
This is the mode in which you should spend most of your time in.
It’s used for moving around, bulk editing text; this is basically where most of the magic happens.
This is the mode which new users would probably call normal mode.
The only things you have to remember while using insert mode are:
This mode is used for inserting special commands, most times not directly related to editing text.
For example, you’d use this mode to toggle settings, use find&replace or execute commands in the shell without having to leave vim.
It’s also used for quitting vim (
Editing text could be done by moving to the position you want to edit, pressing
i for entering insert mode and
Esc for going back to normal mode after editing.
But if we wanted to be slow and boring, we’d just use nano, right?
Instead of just using
l and counting, you can (and should) use movement keys like
find functionality (searching in a line) or searching globally (
/) if you have a bigger distance to move.
The actual inserting happens, of course, in insert mode. However, you’re specifying where the text will be inserted and what text will be replaced in normal mode.
I won’t list all the possiblities here, there are already many resources doing just that (e.g.
:help movement refers to this file).
A typical normal-mode vim command exists of a command, sometimes a quantity and a direction/selection. Examples are:
d3w(delete 3 words) or
cis(change in sentence)
This allows you to become way more effective, compared to just using single keystrokes in insert mode.
Instead of pressing
h for moving left 40 times, you just type
(for vertical movements check out
Instead of pressing
Del 40 times to delete 40 characters, you type
d5B to delete the previous 5 words.
Instead of deleting a word and typing another one, you type
ciw to replace the word all at once.
Instead of using your mouse to select text inside quotation marks, you type
ci" to change exactly that text.
These commands shouldn’t be remembered; Ideally you shouldn’t have to think about how you’re doing something, but only about what you’re doing.
Vim commands are built in such a way, that they can be used as a kind of language:
daw (delete around word),
cit (change in tags),
dw (delete word), …
With some experience, you won’t have to think about which command you’re using to complete a task, it will feel natural to just do it.
There will come a time where you’re editing a bunch of file names in vim and visual mode just isn’t enough, not even block mode (
This is where you should start using macros.
Record a macro by pressing
q and then any key to save the macro as. Do any kind of editing and press
q again to stop recording and save the macro. After that, press
@ and the key you chose for saving your macro under to execute the macro. Of course you can also use the macro in more complex commands too.
Let’s say you have a bunch of lines with a variable amount of words in each line. All the words only consist of lowercase letters. You want to change all the words to start with an uppercase letter. No amount of visual mode is going to help you here, but try the following:
qto start recording a macro, then
1to save the macro at key
~to change the current character to uppercase
Wto jump to the beginning of the next word
qto stop recording the macro
After that you can use your macro as
50@1 to change the first 50 words.
Vim configuration in managed in a file called vimrc. It’s typically located at
There’s a lot to explore here. Look up what other people put into their
.vimrcs, you’ll probably find something you’ll like.
Whenever you’re editing some text and you wish there was a feature which would help you save some time and work:
Just grab your favorite search engine and look up if it exists. Chances are it actually does!
… for the overview. There are a lot of things I didn’t even mention in here. If you find it hard to stick to the good practices, try disabling the arrow keys or use a plugin like hardmode. Now go ahead and type
vimtutor into your favorite shell if you haven’t done so already.
Update 25.07.20: Also check out this nice little talk by Sandy Maguire.
If you want to give me some feedback or share your opinion, please contact me via email.
© Niklas Bühler, 2021 RSS / Contact me