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 command | Description |
i | Insert |
Esc | Press esc in keyborad to go to command mode |
:wq | Save & Quit |
:q | Quit from file |
:q! | Quit forcefully without save |
:wq! | Save & quit forcefully |
:w | Save and stay in file |
yy | Copy one line |
1yy | Copy one line |
2yy | Copy 2 line |
p | Paste the line |
dd | Delete one line |
2dd | Delete two line |
u | Undo |
:set nu | Show lines in file |
:5 | Go to line no 5 |
dw | Delete word |
press b | Go back to one keyword in line |
press w | Go right one keyword in line |
/search_keyword | Search keyword from file |
:%s/search/replace/g | Search & Replace keyword in line |
:g/^$/d | Delete all blank lines (^$ – from start to end) |
:%s/^/Start_keyword_here /g | Add keyword start of line |
:%s/$/End_keyword_here/g | Add keyword end of line |
:1,5d | Delete line from 1 to 5 line in file |
:5,$d | Delete line from 5 to end line |