Visual Interface
To open a file use vi <filename>
# vi test.txt
i - inserts the text at current cursor position
I - inserts the text at beginning of line
a - appends the text after current cursor position
A - appends the text at end of line
o - inserts a line below current cursor position
O - inserts a line above current cursor position
r - replace a single char at current cursor position
Commands at execute mode
:q - quit without saving
:q! - quit forcefully without saving
:w - save
:wq - save & quit
:wq! - save & quit forcefully
:x - save & quit
:sh - Provides temporary shell
:se nu - Setting line numbers
:se nonu - Removing line numbers
:84 - Press enter goes to line 84
To move the cursor, press the h,j,k,l keys as indicated.
^
^
k Hint: The h key is at the left and moves
left.
< h l > The l key is at the right and moves
right.
j The j key looks like a down arrow
v
w forward word to word
b back side word to word
Command's at command mode
dd - Deletes a line
2dd - Deletes 2 lines
yy - Copy a line
2yy - Copies 2 lines
p - put (deleted or copied text)
u - Undo (can undo 1000 times)
Ctrl+r - R edo
G - Moves cursor to last line of file
5G - Moves cursor to 5th line of file
Shift+ZZ - save & quit
/<findword> - locate word
To find and replace words
:1,$s/<findword>/<replaceword>/g
:1,$s/world/universe/gc
1-- To start the search at from 1st line
$ -> End of File
s -> substitute
$ -> End of File
s -> substitute
c -> confirmation
g -> global
No comments:
Post a Comment