Here is list of basic commands to work on Vim editor in unix environment. Hope this would help new learners and people preparing for interviews.
Best way to learn these commands is using -
vimtutor
go to unix shell and type command vimtutor. Follow instructions on this tutorial and practice it hands-on.
Start Vim
Exit Vim
<ESC> key is used to return to normal mode. (you might be in editing mode)
Move Cursor
Motions
Undo
Delete character, word, Line
Insert and Append text
Search
Replace/substitute
These are few basic commands to begin and practice.
Please leave your comments here and let us know if this helps.
Best way to learn these commands is using -
vimtutor
go to unix shell and type command vimtutor. Follow instructions on this tutorial and practice it hands-on.
Start Vim
vim [filename] | To start Vim from shell prompt |
Exit Vim
<ESC> :q! | exit without saving changes |
<ESC> :wq | saving changes and exit |
<ESC> key is used to return to normal mode. (you might be in editing mode)
Move Cursor
h | left |
j | down |
k | up |
l | right |
Motions
w | first character of next word |
e | last character of next word |
$ | last character of line |
move faster - | |
0 (Zero) | To move to start of line |
nw e.g. - 2w | Move forward by n words (e.g. - 2 words) |
gg | move to start of the file |
G | move to bottom of the file |
Undo
u | undo last command |
U | undo changes on whole line |
Delete character, word, Line
x | delete character at cursor |
dw | delete word, including last character (place cursor on first character of word) |
de | delete word, excluding last character (place cursor on first character of word) |
d$ | delete words from cursor position till end of line |
dd | delete line |
delete more - | |
nd[motion] e.g. - 2dd | delete n lines from cursor position (e.g. - delete 2 lines) |
Insert and Append text
i | insert before cursor (press <ESC> after, to return to normal mode) |
A | append after the line (press <ESC> after, to return to normal mode) |
Search
/[phrase] | search pharse in file |
n | go to next match |
N | go to previous match |
Replace/substitute
s/old/new | on current line, substitute first occurence of old with new |
s/old/new/g | substitute all old with new on current line |
%s/old/new/g | substitute all old with new in file |
%s/old/new/gc | substitute all old with new in file, ask for confirmation |
These are few basic commands to begin and practice.
Please leave your comments here and let us know if this helps.