paint-brush
7 Things You Should Know about Vimby@claudio.santos.ribeiro
5,828 reads
5,828 reads

7 Things You Should Know about Vim

by Cláudio RibeiroFebruary 11th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In this article I’d like to explore some of the things that most people don’t know about Vim. From the reasons why it was developed the way it is, to some of the great hidden features you’re probably not using (yet).

Company Mentioned

Mention Thumbnail
featured image - 7 Things You Should Know about Vim
Cláudio Ribeiro HackerNoon profile picture

In this article I’d like to explore some of the things that most people don’t know about Vim. From the reasons why it was developed the way it is, to some of the great hidden features you’re probably not using (yet).

1 — The original movement keys (h, j, k, l) have a reason to be

At first, it seems random. Why do we use the original keys instead of the arrow keys? In 1976, Vi was created by Bill Joy. Bill used an ADM-3A terminal to develop Vi. The thing is, the ADM-3A keyboard doesn’t have arrow keys. So h, j, k, and l were used as the movement keys.

The ADM-3A keyboard

Also, notice that the <ESC> key was located where we normally have the <TAB> key. This happy coincidence made possible navigation between modes and inside files without moving our hand from the home row. This is one of the great selling points of Vim. Having access to everything without having to move our hands too much. It’s a great productivity hack.

2 — Vim motions are not random

:q:w:c and so on were not chosen randomly. They are actually very intuitive once you realize that q stands for quit, w for write, y for yank (copy) and p for put (paste). d is for delete and a for append. And those are just a couple of possible commands, once we wrap our heads around them it’s possible to start making combinations like di” which stands for delete inside “.

3 — You don’t get the good features unless you turn them on

The standard Vim package allows for a lot of things, but it’s still pretty bland. The .vimrc file is where we enable/disable functionalities. Thins like incremental search (:set incsearch) and highlighting search results (:set hlsearch) must be turned on before they can be used. Even things like line numbers (:set number) fall into this category.

Note that the :set command will enable functionalities for the current session. If we want them enabled for all sessions those need to be added to the .vimrc file.

4 — Word completion

Vim offers very basic word completion out of the box. It is triggered simply by clicking <C-n> after we start typing a word. This form of completion will search the current file and other opened files for possibilities for completion.

There are other forms of advanced file completion that can be used, this is just the simpler one.

5 — Tag completion / Tag navigation

Vim works very well with ctags. ctags is an external piece of software that generates a reference file that holds every word we’re likely to want (like function names) and their location. Because we now know the location of every word, if we have for example a make_struct() function call and want to go to that function definition we can use the <C-]> command on top of the name of the function.

Vim also looks to the tags file for possible word completions.

6 — Registers


Just like the system clipboard, Vim uses a dedicated register to store everything we copy/cut. But Vim goes a little bit further. It has different types of registers that can be used for a lot more flexibility. Numbered registers (0–9) store our copies/cuts chronologically and named registers (a — z) can be used to store anything we want (“ay will copy content to the register a, and “ap will paste that same content). The content of each register can always be consulted with the :registers command.

7 — Sessions

Vim can store sessions. A session encompasses every opened buffer, the cursor position, i.e, the current state of the program. A session is stored in a .vim file and can then be used to restore that same session later. :mks is the command used to store a session.

These are 7 of an endless list of things to know about Vim. All together they make Vim the awesome tool it is.

How about you, do you know something we should know about Vim? Tell us in the comments.

Want to learn more about Vim? Want to learn how to use it as an IDE? Check out my new book An IDE Called Vim. It has everything from basic Vim usage to file finding, auto-completion, file manager and more.