How to use VI or VIM in Linux/Unix ?

VIM EDITOR                            


·                                      VI
— Visual display editor
·                                      VIM
— Visual Display Editor Improved

Description

Vim is a text editor that is upwards compatible to
Vi. It can be used to edit all kinds of plain text. It is especially useful for
editing programs.
This is command mode editor for files. Other editor
in Linux are emacs, gedit.
Vi editor is most popular editor in Linux/Unix.

There
are 3 modes in Vi editor:

1                   
Command Mode
2                   
Insert Mode (Edit Mode)
3                   
Extended command Mode
Note:
When
you open the vim editor, it will be in the command mode by default.
In the command mode the cursor’s can be used as
h/l/k/j to move curser left/right/up/down.
If
the file you want to edit is /etc/passwd, type in the Terminal window:

# vim
<file name>

[root@rahul
~]# vim /etc/passwd
Vim will open this file into the terminal with that
file contents. Vim is a terminal program, not a graphical system program.
Command
Mode:

gg
To
go to the beginning of the page
G
To
go to end of the page
w
To
move the cursor forward, word by word
b
To
move the cursor backward, word by word
nw
To
move the cursor forward to n words (10w)
nb
To
move the cursor backward to n words (10b)
u
To
undo last change (word)
U
To
undo the previous changes (entire line)
Ctrl+R
To
redo the changes
yy
To
copy a  line
nyy
To
copy n lines (5yy or 14yy)
p
To
paste line below the cursor position
P
To
paste line above the cursor position
dw
To
delete the word letter by letter ( Like Backspace)
X
To
delete the word letter by letter (like DELETE key)
dd
To
delete entire line
ndd
To
delete n no. of lines from cursor position(10dd)
/
To
search a word in a file
Insert
Mode:

i
To
begin insert mode at the cursor position
I
To
insert at the beginning of line
a
To
append to the next word’s latter
A
To
append at the end of the line
o
To
insert new line below the cursor position
O
To
insert new line above the cursor position
Extended
Mode: (Colon Mode)

Extended mode is used for save and quit or save
without quit using “Esc” key with “:
Esc+:w
To
save the changes
Esc+:q
To
Quit (Without Save)
Esc+:wq
To
Save and quit
Esc+:w!
To
save forcefully
Esc+:wq!
To
save and quit forcefully
Esc+:x
To
save and quit
Esc+:X
To
give password to the file and remove password
Esc+:20(n)
To
go line no 20 or n
Esc+:se nu
To
set the line numbers to the file
Esc+:se nonu
To
remove the set line numbers


Leave a Reply

Your email address will not be published. Required fields are marked *