Here are some commands of vi editor that are really useful and which I personally use all the time
- Cursor Movement
0 - moves the cursor to beginning of the current line
$ - moves the cursor to end of the current line
w - moves the cursor to beginning of the next word
b - moves the cursor to beginning of the previous word
e - moves the cursor to the end of the next word
H - moves the cursor to the top of the screen
M - moves the cursor to the middle of the screen
L - moves the cursor to the bottom of the screen
:0 - moves the cursor to first line in file
:n - moves the cursor to line number n
:$ - moves the cursor to last line in the file
- Manipulating Text
dd - delete the current line
Ndd - delete N number of lines, starting from the current line
yy - copy the current line to be pasted
Nyy - copy N number of lines to be pasted starting from the current line
p - paste the content which was copied
- Searching Text
/<search text> - start searching forward for the search text starting from the current line
?<search text> - start searching backward for the search text starting from the current line
n - move to next occurance of the search text
N - move to previous occurance of the search text
% - searches for the matching pair of paranthesis - ( ) / { } / [ ]
- Find/ Replace
:%s/fff/rrrrr/- - For all lines in a file, find string "fff" and replace with string "rrrrr" for the first instance on a line
:%s/fff/rrrrr/g - For all lines in a file, find string "fff" and replace with string "rrrrr" for each instance on a line
:%s/fff/rrrrr/gc - For all lines in a file, find string "fff" and replace with string "rrrrr" for each instance on a line. Ask for conformation
:%s/fff/rrrrr/gi - For all lines in a file, find string "fff" and replace with string "rrrrr" for each instance on a line. Case insensitive
- By Joohi Sinha
Stay tuned for more.....
Stay tuned for more.....