Vim modes – normal, insert and visual

This article covers all the basic modes of vim. commands or mappings supported in each mode and what commands we can use to jump between them. Or if you are looking for a well configured vim you can visit my github repo here.

There are mainly three modes in vim

  1. Normal mode
  2. Insert mode
  3. Visual mode

Normal mode

The normal mode is the default mode of vim. This mode of vim is mainly used for traversing in the file or to use the normal mode mappings which might have defined in the ~/.vimrc file. Lets take a look at default mappings of normal mode.

Keys to jump between the line.

To jump multiple line you can use the numbers followed by the j,k,l,h or the arrow keys. For example lets say I want to go 10 lines down from the current line then
I will type 10j(down arrow key).

Keys to traverse word by word

You can use the above commands with numbers as well. For example if I want to jump 4th word from the cursor position I will type 4w

Keys to cut, copy and paste

Use Cases

  1. To delete a line in vim you can use dd command and to paste that line somewhere else just type p You can use the dd and p command with the numbers as well.
  2. If you want to delete 10 lines including the current line just type 10dd
  3. To paste one line 10 number of times type 10p it will paste the copied lines or text 10 times
  4. To copy multiple lines use yy with numbers. e.g 10yy

Insert Mode

Insert mode is mainly used for entering the text, This is where you really update the file.
Ways to enter the insert mode –

Visual Mode

Visual mode is mainly used for selecting some text and do something with it.
Keys to enter visual mode

v – will just allow you to enter the visual mode, after that you can use normal mode’s traversing commands(w,e,b,j,k,l,h or arrow keys ) to select the text fast.
ctrl + v – This is used when you want to select a block of text and do something with it, e.g. delete, copy etc. This has lot of mapping of itself maybe I will write a separate article for it.
V  This is used when you are in normal mode and you want to select the current line, and after it if you use arrow up or down it will select the whole above or below line.

Delete, cut and copy in visual mode –

  1. Delete – select the text you want to delete and press d
  2. Copy – select the text using above commands and press y
  3. Cut – You can use the delete commands(d) to cut and use to paste

About Ajit Singh

Hi, I am Ajit Singh, author of singhajit.com. I work on a lot of different technologies and tools. I started my career as a software engineer in Chennai (India) and recently I moved to Gurgaon near to my home town. I like reading and writing about technology.

Leave a Reply

Your email address will not be published. Required fields are marked *