Installation of the VIM editor
VI (VIM) is a very common editor on Linux, and many Linux distributions have VI (VIM) installed by default. VI (VIM) commands are numerous but if used flexibly it will greatly improve efficiency. This article explains the operations that are mainly under CentOS.
After installing CentOS, the default is to install the VI editor, VIM is not installed, so we will be prompted when using vim: Vim command not found this means that CentOS does not have the Vim editor installed, Let's take a look at how to install this editor:
Vim editor needs to install three packages:
Vim-enhanced-7.0.109-7.el5
vim-minimal-7.0.109-7.el5
vim-common-7.0.109-7.el5
1. 查看一下你本机已经存在的包,确认一下你的vim是否已经安装:
输入 rpm -qa|grep vim 这个命令,如何vim已经正确安装,则会显示上面三个包的名称
2. 如果缺少了其中某个,比如说: vim-enhanced这个包少了,执行:yum -y install vim-enhanced 命令,它会自动下载安装。
3. 如果上面三个包一个都没有显示,则直接输入命令:
yum -y install vim*
即可自动安装,完毕后,即可使用vim编辑器。
VI has 3 modes: insert mode, command mode, low line mode.
1. Insert mode: You can enter characters in this mode and press ESC to return to command mode.
2. Command mode: You can move the cursor, delete characters and so on.
3. Low-line mode: can save files, exit VI, set VI, Find and other functions (low-line mode can also be seen as a command mode).
Use of the VIM Editor 1. Open file, save, close file (used in VI command mode)
VI filename//open filename File
: w//Save File
: w vpser.net//Save to Vpser.net file
: Q//Exit editor, if the file has been modified please use the following command
: q! Exits the editor without saving
: Wq//Exit editor, and save file
2. Insert text or lines (used in VI command mode, enter insert mode after executing the command below, press ESC to exit insert mode)
A//Add text to the right of the current cursor position
I//Add text to the left of the current cursor position
A//Add text at the end of the current line
I//Add text at the beginning of the current line (the beginning of a non-empty character)
O//Create a new row above the current line
O//Create a new row below the current line
R//replace (overwrite) the current cursor position and several subsequent text
J//Merge cursor row and next line of behavior (still in command mode)
3. Move the cursor (used in VI command mode)
1, use the upper and lower left and RIGHT arrow keys
2, Command mode: H left, J down, k up, l to the right.
Spacebar to the right, Backspace left, Enter to the next line,-move to the top of the line.
4. Delete, restore characters or lines (used in VI command mode)
X//Delete current character
NX//delete n characters starting from the cursor
DD//Delete when moving forward
NDD//Down Delete the current row, including n rows
U//Undo Previous action
U//Undo all operations on the current line
5. Search (used in VI command mode)
/vpser//Search for Vpser strings under cursor
? vpser//Searching for vpser strings on the cursor
N//down searches for previous search action
N//Up search previous search action
6. Skip to the specified line (used in VI command mode)
n+//Jump down N rows
N//Jump up N rows
NG//jumps to rows with line number n
G//Jump to the bottom of the file
7. Set the line number (used in VI command mode)
: Set nu//Display line number
: Set Nonu//Suppress line numbers
8. Copy, paste (used in VI command mode)
YY//Copy the current line to the buffer, you can also use "Ayy copy," A is a buffer, a can also be replaced by any letter A to Z, you can complete multiple replication tasks.
Nyy//Copy the current row down n rows to the buffer, or you can use "Anyy copy," A is a buffer, a can also be replaced with any letter A through Z, you can complete multiple replication tasks.
YW//Copy the character from the beginning of the cursor to the ending.
NYW//Copy n words starting from the cursor.
y^//Copy the contents from the cursor to the beginning of the line.
y$//Copy the contents from the cursor to the end of the line.
P//Paste the contents of the Clipboard after the cursor, if the previous custom buffer is used, it is recommended to use the "AP to paste."
P//Paste the contents of the Clipboard before the cursor, if the previous custom buffer is used, it is recommended to use the "AP to paste."
9. Replace (use in VI command mode)
: S/old/new//Replaces the first occurrence of old in a row with new
: s/old/new/g//Replace all old in line with new
: n,m s/old/new/g//Replace all old from N to M with new
:%s/old/new/g//Replace all old in current file with new
10. Edit other files
: E otherfilename//edit file named Otherfilename.
11. Modify the file format
: Set Fileformat=unix//modify the file to UNIX format, such as win below the text file under Linux will appear ^m.
Usage summary of the VIM Editor installation command using commands and settings