Introducing Vim Editor
It is a standard Linux text editor. The default editor is vi.
There are three main modes in vim:
1. Command mode: the default mode. Allows keys to be used for cursor movement, copying, cutting and pasting text.
2. Insert mode: allows keystrokes to be inserted into the document.
3. Ex mode: allows keys to be used to save, save as and quit the document.
Editing
commands
|
Keystrokes
|
Action
|
i
|
Insert
at cursor
|
a
|
Append
after cursor
|
A
|
Append
at end of line
|
ESC
|
Terminate
insert mode
|
u
|
Undo
last change
|
U
|
Undo
all changes to entire line
|
o
|
Open
a new line
|
dd
3dd
|
Delete
line
Delete 3 lines. |
D
|
Delete
contents of line after cursor
|
C
|
Delete
contents of line after cursor and insert new text. Press esc key
to end insertion.
|
cc
|
the
cc command will change a line, it will delete the current line and
place you into insert mode to enter the replacement
|
cl
|
the
cl command will delete the current character and place you in
insert mode.
|
cw
|
the
cw command will delete the current word and place you into insert
mode.
|
dd
|
the
dd command deletes the current line, leaving you in command mode.
|
yy
|
copy
a one line
|
y1
|
copy
a letter
|
yw
|
copy
a word
|
Terminate
session
|
|
:
ZZ
|
Save
changes and quit.
|
:wq
|
Save
(write) changes and quit.
|
:w
|
Save
(write) changes without quitting.
|
:q!
|
Ignore
changes and quit. No changes from last write will be saved.
|
:qa
|
Quit
all files opened.
|
Moving
Around the File
Ctrl+f
|
Page
ahead, one page at a time.
|
Ctrl+b
|
Page
back, one page at a time.
|
Ctrl+d
|
Page
ahead one-half page at a time.
|
Ctrl+u
|
Page
back one-half page at a time.
|
G
|
Go
to the last line of the file.
|
1G
|
Go
to the first line of the file. (Use any number to go to that line
in the file.)
|
Search and replace-
To search for a string of text, use the / or ? Command.
#vim filename
:/hello and then Enter
press n/N for next search :?llo and press Enter
Once the first match is found, you can find the next match with the n command. To reverse the direction of the search uses the N command.
Search/replace operation-
If you want to change one line in the starting
:1s/hello/krishna/ then press Enter
If you want to change all the file
:%s/hello/krishna/g
_____________________________________________________________________________________________