{ bookie

First steps in Vim

TL;DR: To quit Vim, use :q

During lockdown I’ve had plenty of time to mess around with new tools and change my terrible work habits; but most of all, I discovered Vim and started using it as my primary text editor and IDE.

In this article, I will explain how vim was born, and how you can start using it yourself with a few tips! I will mostly focus on how to use it properly rather than doing an in-depth tutorial.

It all starts with vi

vi is a lightweight & super fast text editor created by Bill Joy in 1976, and has become the standard text editor of Unix, which means you’ll be able to launch vi on basically any linux machine you encounter.


Vim, or Vi IMproved, is a highly customizable fork of vi which first version was released in 1991 by Bram Moolenaar. It features syntax highlight, many plugins and options, a bountiful documentation (:help) and a significant amount of StackOverflow questions.

It also has its own language, vim script, made especially for customization and plugin development.
Since March 2006, Vim’s profit and donations are redistributed to help children in Uganda (see more here).


Neovim is the fork of Vim I’m currently using. Its primary goal is to improve Vim’s maintainability, code readability, and to encourage more developers to participate to the Vim project.

What’s so special about Vim?

That’s right, why not use a standard text editor like mousepad or gedit?

There are many advantages to using Vim:

If you use someone else’s Vim config, there are chances that you won’t be able to use it, because that’s what makes Vim great: to be completely at ease with it, you have to make it your own!

This comes with some downsides: sometimes you will be frustrated by it, and you’ll have to spend a good amount of time practicing before being as fast as with your usual IDE, but it’s all worth it! The payoff is huge.

Learning Vim

Vim is keyboard-based, meaning that your hand movements will be greatly reduced, and you won’t even need your mouse to do anything!


There are 4 “basic” modes in Vim (there’s actually plenty more):

You usually switch modes all the time, so you should remember what all modes do, and be able to switch between them quickly. It will come with practice, and faster than you’d think!

Learning the basics

How do I quit??

Beautiful meme
The age-old question! How the hell am I supposed to exit Vim??
The answers are very simple. Make sure you’re in normal mode by pressing <ESC>, and try the following:

Keys Description
:q quit
:w <file> saves to file (the filename is optional)
:wq quit and save
:q! “force” quit
:wqa quit all tabs/panes and saves them
ZZ quit and save if modified

How do I move?

There are LOADS of ways to move within Vim, the most common is the dreaded hjkl!
In normal mode, the hjkl keys behave like directional arrows, with the following configuration:

HJKL layout

The advantage here is that you don’t have to move your fingers from the home row. It might seem a bit impractical at first, but believe me it’s way better than moving your hands to the arrow keys and back.

A good way to get used to the hjkl keys is to unbind the arrow keys (see here). And you can install the HJKL plugin to learn them with a little maze game!

But movement in Vim doesn’t stop here! You have many options to move forward or backwards, and you can even remap them to new keys. Below is a little list (use in normal mode):

Keys Description
$ jumps to the end of a line
0 jumps to the first character of the line
Ctrl+D jumps 30 lines down
Ctrl+U jumps 30 lines up
Ctrl+o jump to the last place your cursor has been to (restores last buffer
e jumps to the end of the next non-whitespace word (w for the beginning)
b jumps to the beginning of the previous non-whitespace word
f<char> jumps to the first occurence of char FORWARD
F<char> jumps to the first occurence of char BACKWARDS
/<str> Searches for str and jumps to the next occurence with n (next) and N (previous)
<int>G jumps to the int line
gg jumps to the beginning of the file
G jumps to the and of the file
Ctrl+i jump to the next place your cursor has been to (opposite of Ctrl+o)

Of course, you can enhance your movement within Vim with the help of plugins.

Text editing

The thing you do most besides writing and moving is probably selecting text and editing it.
Like every feature in Vim, there are hundreds of ways to edit text, I made you a little list of the important basic ones:

Keys Description
x Deletes a character right on the cursor
X Deletes a character right before the cursor
r Replaces a single character on the cursor
R Replaces multiple characters (enter REPLACE mode)
d<motion> deletes motion characters
dd deletes the current line
c<motion> deletes and goes into insert mode
y<motion> yanks (copy) motion characters
yy yanks the current line
p pastes the content of the clipboard right after the cursor
P pastes the content of the clipboard right before the cursor
>> or << indent or unindent selection
:s/first/second/ replaces first with second (once)
:%s/first/second/ replaces first with second (all of them)
:r!<file or command> prints the content of the command or file

NOTE : when you delete something, it gets stored in your Vim clipboard, so you can paste it somewhere else!

And as any editor does, there are undo and redo commands. Please note that when you go to INSERT mode, write text and go back to NORMAL mode, it will count as one entry on the undo stack (see more here).

Keys Description
u undo the last edit command
U undo the changes made to a line
Ctrl+R redo the last undo

Vim commands, operators and motions

Most commands and keybindings that transform text use an operator and a motion to work. Let’s take the example of the d command key; it is used for deleting characters.

By pressing d<motion>, the deletion will be extended to the motion.

For example:

You can also add numerals to your command:

Text selection

Let’s learn text selection now. For this, you have to switch to VISUALmode, here’s how it works:

Every character that’s selected by the visual mode will be affected by the x, d commands (we can say that the deletion is extended to the selection).

It would look like this:

Also, if you want to insert text in multiple lines at once, just select them and press I. When you come back to insert mode, the lines will appear in all the lines you selected.

Some more commands!


Windows (or splits) are one of the features you just can’t live without if you’re working on big projects where you need to edit multiple files quickly.

For these, we will use the Ctrl+w prefix, then one of the following commands:


Ok, windows are cool, but do you know what’s even cooler? TABS! In Vim, they are strictly controlled by commands.

You can choose to open multiple files in tabs by using the -p vim option:

vim -p file1 file2

And move between the two by using the :tabnext and tabprevious commands:

You can close tabs by using :q or :tabclose, and create new ones with :tabnew.

Although it sounds simple, it remains VERY tedious to enter command mode and type this every time you want to change views! How would you solve this problem? The answer is keybindings!


As said before, customization is a big part of why you should use vim. Everything from colors, keybindings, modes, macros, etc. can be changed one way or another. The first way is by using the command mode, like when you type the following while in NORMAL mode (try it for yourself!):

:set number

Impressive! But when you quit Vim, the setting will be reset. 😔

To make the changes persistent, you have to write them in your configuration file. If you’re using Vim, it’s in ~/.vimrc, and if you use Neovim, it’s probably in ~/.config/nvim/init.vim.

(NOTE: if you write something in the configuration file, don’t forget to remove the :, it’s only specific to the command mode).


Literally any action and command can be assigned to a key, and it is a big part of why Vim is said to be “programmable”. Let’s take a walk through the basics of what you need to know, starting with the map keyword.

Mapping something to a key means that when you press that key in a specific mode, it will execute said thing. it follows the syntax:

map <key(s)> <commmand>
unmap <key(s)>

map will bind the command to a key in a mode.

Here are some of the different map types to put in your .vimrc or init.vim file:

keyword modes affected unmapping
nmap NORMAL nunmap
imap INSERT COMMAND iunmap
vmap VISUAL vunmap
cmap VISUAL cunmap

A few useful examples:

map \| :r!ls

This line will bind the | key to “printing whatever the ls command puts out”. Note that the result will be printed inside the buffer you’re working on.

The “Leader key”

The leader key is something I discovered fairly recently. It will act as a prefix, and it can be almost any key. You can set it by writing the following line to your configuration file:

" Unmapping 'key' and mapping it to leader
nnoremap <key> <Nop>
let mapleader="<key>"

What it does is simply add a whole new way to make keybindings. Let’s take an example from my config file; the yy command copies the entirety of the current line, including any linebreak \n. If I want to be able to copy the current line without that linebreak, I will add the following:

" ^ goes to the beginning of the line
" d$ deletes everything until the last printable character of the line
map <leader>dd ^y$

When you press your leader key, followed by dd, it will delete the line without deleting the newline!

I have it set to <space> because I feel like the leader key should be accessible at all times, and the <space> isn’t used for something important in NORMAL mode. Therefore it looks like this:

nnoremap <Space> <Nop>
let mapleader=" "

You can make bindings with the leader key like this:

" Map <leader><tab> to 'switch to next tab'
map <leader><tab> :tabn<CR>

It’s quite useful: if you happen to change your leader key, every binding made that include that key will be changed too, so don’t fret too much about which one you’ll use!


I won’t be getting too deep into plugin territory, because it’s easy to get lost and list them for hours.

Plugins are a quick way to add a considerable amount of new features to your Vim config, and some of them can completely change your use of Vim!


The simplest way to install plugins is through a plugin manager. I myself use vim-plug because it’s incredibly quick and you barely have to remember 2 or 3 commands to use it properly.
Check out how to install it here or find your own one.
When vim-plug is installed, all you have to do is add these lines to your configuration file:

" Plugins will be downloaded under the specified directory.
call plug#begin('~/.vim/plugged')

" Put your plugins list here
Plug 'easymotion/vim-easymotion'
Plug 'itchyny/lightline.vim'

" List ends here. Plugins become visible to Vim after this call.
call plug#end()

When you want to add a plugin, just add it to the list and use the :PlugInstall command! On the contrary, if you need to remove a plugin, erase it from the list and run :PlugClean to remove the downloaded files.

It’s that simple!


The very first thing you want to do is to put the following line into your configuration file:

syntax on

With this on, everytime you open a filetype that support syntax highlight, Vim will color it for you! (thanks Vim!!).

You can change colorschemes by using the :colorscheme command, for example:

You can also prettify your Vim with plugins (duh), for example Colorline and Conoline (Both are great!).


Good luck! :q

And that’s it! I’ve never experienced such sudden interest for a tool than when I discovered Vim, and if I did my job right, you too should be scrolling through documentation and top plugins lists to create your own working environment, and as the years pass you will only get better at it :)

Other good ways to learn Vim

I will probably make a follow-up article on the plugins I use, how I use them and why i use them.
Take care, and stay safe!