1, the concept of vim and basic operation
VI command line below the text Editing tool, Vim is VI's enhanced version. Command vim to start the Vim editor. Vim can generally be used in the form of a vim+ destination file path. If the destination file exists, Vim opens the file, or creates a new file if the destination file does not exist. 1.1 VI has three modes: Command mode, insert mode, and ex mode
1, any mode can be returned to the command mode by ESC key;
2, in the command mode press "I" key can enter into the insert mode, in the Insert mode press ESC can return to command mode;
3, in the command mode Press ":" can enter the ex mode, in the ex mode can save, modify and exit
Command mode is commonly used for the following commands:
1. I insert text before the cursor
2, o insert a new line below the current line
3, DD Delete positive line
4. U Undo Last Action
5, YY replication when the forward
6, N+yy first Press 5, then press YY, then 5 rows of content to copy
7, p paste
8, R replace the current keyword
Ex Mode
1.: W Save Current modification
2.: Q exit
3.: q! Force exit
4.: x Save and exit (general use: wq!)
5.: Set NU Display line number (VIM/ETC/VIMRC add set Nu at the end of this file to automatically display line number)
6,:! Execute a system command and display the results
7,: SH switch to the command line, using ctrl+d switch back to VIM
8,: 1 To file header
9.: $ to end of file
10. Ctrl+b PAGE Up
11. Ctrl+f PAGE Down
12,/Find the key words
13.: Noh eliminate find highlight 2. Copy cut move multiple lines Delete 2.1 in vim , copy
1, use YY to copy a line;
2, using line number N+YY copy n line;
3, using p to paste the copied rows; 2.2, Cut
1, the use of DD cut a row;
2, use row number N+DD cut n row;
3, use p to paste the cut rows. 2.3, Mobile
1, VIM uses the digital +g to move the line, for example you want to move to 342 lines, that is 342G. 2.4, multiple lines delete
First in command mode, enter ": Set Nu" To display the line number, and the line number to determine the line you want to delete; the command type ": 32,65d", enter, and 32-65 lines are deleted. 3, Vim in the replacement of strings
Vim is available in the: S command to replace the string, as follows:
1,: s/str1/str2/Replace the current line the first str1 for STR2
2.: S/str1/str2/g replaces all str1 in the current line as str2
3.: m,ns/str1/str2/replaces the first n line to the str1 of each line in the last line as str2
4.: M,ns/str1/str2/g replaces the first n line with all str1 in the last line as STR2 (note: M and n are digits, if M is., the current line begins; If n is $, then the last line ends)
5, if the use of # as a separator, the middle appears/not as a separator, such as:
6.: s#str1/#str2/# Replace the current line the first str1/is str2/
7.:%s+/oradata/apras/+/user01/apras1+ (use + to replace/):/oradata/apras/replaced with/user01/apras1/
8, Other:%s/str1/str2/(equivalent to: g/str1/s//str2/) Replace the first str1 of each row for str2
9.:%s/str1/str2/g (equivalent to: g/str1/s//str2/g and: 1,$ s/str1/str2/g) Replace all str1 in the article str2
As you can see from the substitution command, G is placed at the end of the command, indicating that each occurrence of the search string is replaced;