Sun, Mar 21, 2021
Read in 2 minutes
In this blog ,we are going to see about the basic VIM commands. No matter which technology you are working in,you should know basic VIM commands to connect the remote server or edit the bash file.
Modes of VIM:
1.Command mode - When you open a file in VIM editor ,first it will be in command mode. If you want to go to insert mode ,you should press ‘i’ .
2.Insert mode : In insert mode you can edit the content. To come of the insert mode press “esc”.
VIM commands to quit editor :
When you are in insert mode ,Then you can press down arrow or up arrow to go down or up to find the content .
When you are done with the changes ,press “esc” and To save :wq!
To quit without saving - :q!
From command mode ,
if you want to delete a line : dd
To delete a 4 line at a time : 4dd (ndd)
To delete a character : ‘x’
To delete a word : dw
To undo the change : u
Redo the change : ctrl + r
To go to the First line : gg
To go to the last line : ‘G’
How to search or replace a text in VIM editor in Command mode:
Search : /searchtext
And enter will move the cursor to first search result. If you want to go to next search result press “n” . And go backward type “N”.
Find and replace : %s/searchstring/replacestring/g
‘g’ - is to replace all the occurrences.
‘gc’ - to ask and confirm before replace
To set line numbers - press " :set number "
Commands to copy and paste in command mode :
Copy a line : yy
Paste the copied line : p
Commands to edit the VIM commands :
CTRL + a - To go to the beginning of the line in a command
CTRL + e -To go to the end of the line.
ALT + f - moving forward by word
ALT + b moving backward by word
To list out all the commands you typed:
History - to list out all the commands you typed recently.