vim command in Linux

vim command – vim is a text editor command in Linux that is use to create and edit files.

vim command has three main modes:
1. Insert Mode: You can type text, erase & update in file, like in a normal editor.
2. Command Mode: You can enter commands to edit, delete, copy, paste, search & replace etc.
3. Exist Mode: To exist from file.

Some useful vim commands:

Vim commandDescription
iInsert
EscPress esc in keyborad to go to command mode
:wqSave & Quit
:qQuit from file
:q!Quit forcefully without save
:wq!Save & quit forcefully
:wSave and stay in file
yyCopy one line
1yyCopy one line
2yyCopy 2 line
pPaste the line
ddDelete one line
2ddDelete two line
uUndo
:set nuShow lines in file
:5Go to line no 5
dwDelete word
press bGo back to one keyword in line
press wGo right one keyword in line
/search_keywordSearch keyword from file
:%s/search/replace/gSearch & Replace keyword in line
:g/^$/dDelete all blank lines (^$ – from start to end)
:%s/^/Start_keyword_here /gAdd keyword start of line
:%s/$/End_keyword_here/gAdd keyword end of line
:1,5dDelete line from 1 to 5 line in file
:5,$dDelete line from 5 to end line

Leave a Reply

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