Getting Started With Vim

Posted onby


Vim (Vi IMproved) is a powerful command-line text editor and as you can already guess, it gives you the ability to edit your files from the command line. There are a lot of command-line editors like Nano, Emacs, Pico, but the reason that we are interested in Vim is because of the efficiency that it gives you and its availability. With Vim, you rarely have to leave your standard typing position. That’s right, you can navigate through the entire file without using the arrow keys.



You can download the .exe file from the official website.


Vim is pre-installed in Mac. To fire it up, enter vim in your terminal.


Vim can be downloaded from your distribution's package tool. For Ubuntu, you can run the following command in your shell.

$ sudo apt-get install vim

Firing up Vim

To see if the installation was successful, enter the following command in your terminal.

$ vim -v

You can type :q! to exit.


Next, enter the following command to get started with editing.

$ vim filename



Unlike any other editor where you directly hop into insert mode whenever you start it, Vim starts with what is called a normal mode and to start editing, you need to press i to go onto the insert mode.

Let's quickly go through the different modes that we have in Vim.

Normal ModeAs discussed, Vim starts in normal mode by default. In this mode, key presses don’t work as one would expect i.e., they don’t insert text into the file. Normal mode can be accessed from other modes by pressing Esc. For starters, this mode can be used for navigations and word movements.
Insert ModeIn insert mode, typing inserts characters just like a regular text editor. You can go into this mode by pressing i.
Command ModeThis mode is used for various commands that come with Vim. You can press : from normal mode to go into command mode.


To start editing, go into the insert mode from normal mode by pressing i. The editing part in Vim is pretty typical and there is nothing much to discuss here.

To save the changes made and exit, press Esc to go into the normal mode and then from there press : to go into the command mode followed by wq( You can think of w as write and q as quit). If you don't want to save any changes and exit, type q!.



The last thing that I want to discuss in this beginner-friendly blog is navigation. To navigate through the file, you have to be in the normal mode. Refer to the following table to understand how basic key bindings work in Vim.

Key bindingDescription
jMove the cursor down by a line
kMove the cursor down by a line
hMove the cursor to its left by a character
kMove the cursor to its right by a character
0 or ^Move the cursor to the beginning of the current line
$Move the cursor to the end of the current line
wMove the cursor to the beginning of the next word
eMove the cursor to the end of the current word
bMove the cursor to the beginning of the previous word
:linenumber or linenumberggMove the cursor to the given line number
Ctrl + fPage down
Ctrl + bPage up

Wrapping up

The things I have discussed are pretty basic when it comes to Vim and will help you in getting started. Vim, as an editor, is highly configurable and extremely powerful and to take the experience to the next level you can do and customize a lot of things. So feel free to explore and adopt new things as you continue your journey with Vim.

Happy Vimming!