Vi Editor Shortcuts

As we are aware, VI editor works in two mode . One is the Command mode which runs when we press Escape button and give commands and the other one is the insert mode which runs when we press i and type something up.

For a single window option we can always press : and type our command to be executed. One common command is :se nu. Which is the set line number commmand . But, once you quit the window and come back . It will be gone forever.

For making the changes permanent we need to put the commands in .vimrc file. Just type cd to move on to your home folder and open the file .vimrc .

$vi .vimrc
set number

We can also set abbreviations in vimrc file. Some of the frequently used words can be set here.

For example : select * from

When writing queries we will be using select * from quite often . Hence just set the abbreviation in vimrc file as below

iab sel select * from

Once you type sel and hit a space , vi will replace it to select * from .

vimrc file will be invoked when the terminal is loaded. For the effects to be applied on the same terminal where we changed vimrc we need to give the source command

source .vimrc

Or we can just close the existing terminal and open a new one.

Find and Replace Vi

Lot of times we Will be in a situation to find and Replace some characters in a file.

say my file contains


and now i need to remove all quotes from the file , use the following substitution vi command


Explanation :

– press escape to move into command mode

1 – start range
2 – end range
s – substitution

” – the character that needs to be retraced. remember , whenever we are using a special character we need to precede it with back slash

now the file looks like


hence the general pattern Will be

:start,end s/text to find/text to replace

another simple example