VIM file editing shortcuts and tips

VIM commands short-cuts and usefull tips  (RPM based Linux)
     VIM is a popular open source text editing tool in Unix like operating systems. Vim can be used to edit all the configuration files in linux.  
Syntax to edit a text file with vim tool: vim<space><filename>
Eg: [root@server ~#]vim /tmp/logfile.txt

#Verify VIM package installed in your machine
[root@server ~#]rpm -q vim-enhanced
#Command to Install the vim package from yum
[root@server ~#]yum -y install vim-enhanced


VIM COMMANDs AND SHORTKEYS (Quick reference)



Command/ key. Action

SAVING AND EXITING
1 :x Save with all changes made and exit
2 :wq Save with all changes made and exit
3 :q! Exit without saving changes.
4 :w Save the changes made so far and continue editing
5 :q Quit the editer if no changes made

CURSER MOVEMENTS
6 w Jump to first letter of next word
7 W Jump to first letter of next coma separated word
8 e Jump to last letter of next word
9 E Jump to last letter of next coma separated word
10 b Jump to first letter of previous word
11 B Jump to first letter of previous coma separated word
12 0 Go to the starting point of current line
13 $ Go to the ending point of current line
14 G Go to the last line of the file
15 L Go to the last line in the screen
16 H Go to the first line in the screen
17 :se nu Set numbers for each lines in the file
18 :n Go the n'th line ( to go to 200th line type :200)

EDITING
19 i or I or a or        "Insert key" Go to insert mode (for editing)
20 O Open a blank line above the current line
21 "Esc" (key) Exit from insert mode
22 dd  Delete the current line
23 X or "Delete key" Delete the letter BEFORE the curser
24 yy Copy the current line
25 nyy   (n = number) Copy the n line.   eg:  7yy for copying 7 lines (from the current line to downwards)
26 p Paste the copied text
27 u Undo
28 Ctr+r Redo
ENCRYPTION
29 :X Encrypt the file with a key
SEARCHING
30 /<keyword> Search the keyword in the file
31 # Search the current word under curser
32 N To display next searched keyword upwards
33 n To display next searched keyword downwards

Replacing words

Switches Purpose
34 c Confirm each action
35 i Ignore case sensitivity
36 % Consider the whole file
37 n Consider the n'th line only

Examples
38 :%s/Jan/new/g Replace every word  "Jan" with "new" in the whole file 
39 :11s/Jan/new/g Replace every  word  "Jan"  with  "new"  in the 11th line of the file
40 :%s/Jan/new/gi Same as above but not case sensitive
41 :s/Jan/new/g Replace every  word  "Jan"  with  "new" only in the current line
42 :%s/Jan/new/gc Replace every  word  "Jan"  with  "new"  in the whole file with confirmation before replacing.

Was this helpfull ?

0 comments:

Related Posts Plugin for WordPress, Blogger...

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Coupons