The VIM editor for Linux
Vim is a text editor developed from VI. VI is the old-fashioned word processor, but the function is very complete, but there is still a place to improve. Vim can be said to be a very useful tool code for program developers to complete, compile and error jumps and other convenient programming features are particularly rich, in the programmer is widely used.
Basically, Vim is divided into three modes, namely, General mode, edit mode, command-line mode (also known as the last-row mode). The three modes of action are:
General mode:
Open a file with VI directly into the general mode (also the default mode). In this mode, you can use the (up or down) button to move the cursor, you can use (delete character) or (delete the entire line) to process the file content, you can also use (copy, paste) to process your file data.
Edit mode:
In general mode can be deleted, copied, pasted and so on, but can't edit the contents of the file! Wait until you press any of the letters (I, I, O, O, A, a, R, r) to enter edit mode. Note: Usually in Linux, when you press these keys, the words insert or REPLACE appear at the bottom left of the screen, so you can edit them. If you want to go back to normal mode, you must press ESC to exit edit mode.
Instruction-column Command mode (or last-line mode):
In the general mode, enter (:/? Any one of the three buttons, you can move the cursor to the bottom row. In this mode, you can provide the action of the search data, and read, save, a large number of substitution characters, open VI, display line number and so on.
Briefly reflect the above description:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/8B/wKioL1XmjeCjg64RAADXtYc2jC8505.jpg "title=" Figure 1.jpg "alt=" Wkiol1xmjecjg64raadxtyc2jc8505.jpg "/>
Common Operation Guidelines:
Move Cursor Movement
h or LEFT ARROW key (←): The cursor moves one character to the left
J or DOWN ARROW key (↓): Move the cursor down one character
K or Up ARROW key (↑): The cursor moves up one character
L or right ARROW key (→): The cursor moves one character to the right
[Ctrl] + [f]: Screen moves down one page, equivalent to [PAGE DOWN] key (common)
[Ctrl] + [b]: Screen moves up one page, equivalent to [PAGE UP] key (common)
[Ctrl] + [d]: Screen moves down half page
[Ctrl] + [u]: Screen "Up" move half page
+: Cursor moves to the next column of non-whitespace
-: Cursor moves to the previous column of non-whitespace
H: The first character of the line that the cursor moves at the top of the screen
M: The first character of the line that the cursor moves to the center of the screen
L: The first character of the line that the cursor moves to the bottom of the screen
G: Move to the last line of this file
GG: Move to the first line, equivalent to 1G
Search and replace
/pattern: Looks down the string.
? PATTERN: Find a character up
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/8F/wKiom1Xmi-PBv2QOAAIQ1Q8WuSU181.jpg "style=" float: none; "title=" 2.jpg "alt=" Wkiom1xmi-pbv2qoaaiq1q8wusu181.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/8B/wKioL1XmjgWxIpiQAAHjKLPT9IM942.jpg "style=" float: none; "title=" 2-1.jpg "alt=" Wkiol1xmjgwxipiqaahjklpt9im942.jpg "/>
: N1,n2s/pattern1/pattern2/g,n1 and N2 are numbers. Look for the string PATTERN1 between N1 and N2, and replace the string with PATTERN2;
Example: In a/tmp/log/a.t file, search for umask between 1 and 20 rows and replace it with Umask:
: 1,20s/umask/umask/g
: 1, $s/pattern1/pattern2/g, look for the PATTERN1 string from the first row to the last line, and replace the string with PATTERN2
: 1, $s/pattern1/pattern2/gc, look for the PATTERN1 string from the first row to the last line, and replace the string with PATTERN2 and display the prompt character before the substitution to confirm (confirm) whether a replacement is required
Delete, copy and paste on
X, x:x to remove a character backwards, X to remove a character, NX, to remove n characters consecutively (n for numeric values)
DD: Deletes the row in which it is located. NDD, delete n rows down.
D1G: Delete all data from the first row of the cursor
DG: Remove all data from the last row of the cursor
d$: Delete the last character of the line to which the cursor is located
D0: Deletes the first character of the line to which the cursor is located
YY: Copy cursor line, NYY copy cursor down n line
Y1G: Copy all data from the row to the first row of the cursor
YG: Copy all data from the row to the last row of the cursor
Y0: Copies all data from the same character as the cursor to the beginning of the line
y$: Copies all data from the same character as the cursor to the end of the line
P, p:p the copied data on the next line of the cursor, p is affixed to the cursor line
U: Undo Previous Action
.: Redo the previous action
End of line: $
Beginning of line: ^
Space: \s
Line End Space: \s\+$
Line Start space: ^\+\s
Enter an insert or replace edit mode
I, I: Enter insert mode: I insert from the current cursor position, I begin inserting at the first non-space character of the row before the current one
A: Enter insert mode: A inserts from the next character at the current cursor position, and a starts at the last character of the line where the cursor is located
O: Enter insert mode: o insert a new line from the next line where the current cursor is located; o Insert a new line at the previous line where the current cursor is located
R, r: Enter replace Mode: R replaces or replaces the one character where the cursor is located, and R will always replace the text of the cursor until ESC is pressed
These keys are in edit mode and the words "--insert--" or "--replace--" appear in the lower left corner.
[ESC]: Exit edit mode
Save, leave, etc commands
: w: Save the edited data
: w!: Forcing the document to be saved
: Q: Exit vim
: q!: Forced exit vim
: Wq: Save and exit. : wq! Save and Force exit
ZZ: The file does not change, do not save the exit, if the file has been changed, then save and exit
: w [filename]: Save the edited file to a new file
Example: Saving edits in/tmp/log/a.t to f.t
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/8F/wKiom1XmjHnyCYpYAAbcyF38EK8668.jpg "title=" Figure 4.jpg "alt=" Wkiom1xmjhnycypyaabcyf38ek8668.jpg "/>
: R [FileName]: In the edited line, read into the data of another file
: n1,n2 w [filename]: Save the contents of N1 to N2 as filename for this file
:! Command: Temporarily leave vim to the command mode to perform the displayed results, such as: (:! Ls/home) To view the file information in the/home directory in vim
Open multiple file Applications (vim file1 file2)
O: Open the file and display it horizontally
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/8B/wKioL1XmjrTzEquvAAVPCVtBJME267.jpg "title=" 5.jpg " alt= "Wkiol1xmjrtzequvaavpcvtbjme267.jpg"/>
-O: Open file and display vertically
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/8F/wKiom1XmjKTBjw-YAAR2weaxSWA505.jpg "title=" Figure 6.jpg "alt=" Wkiom1xmjktbjw-yaar2weaxswa505.jpg "/>
: vs File path/file name: Multi-window open and vertical split screen
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/8F/wKiom1XmjLzym1dGAAMzlZa_fvA091.jpg "title=" Figure 7.jpg "alt=" Wkiom1xmjlzym1dgaamzlza_fva091.jpg "/>
: SV file Path/file name: Multi-window open horizontal split screen
Ctrl+6: Next file (a window, but with multiple files open)
: Bn: Next file (one window, but multiple files open)
: BP: Previous file (one window, but multiple files opened)
ctrl+w+ arrow key: Switch to front/bottom/up/back (multiple windows open)
ctrl+ww-: Switch back to the next window (multiple windows open)
Single File: Q
Close all: QA
Setting of the VIM environment
: Set Nobackup: Never Back up
: Set autoindent: Auto Indent
: Set Hlsearch: Search verbatim Fugauliang, Nohlsearch search per character not highlighted
: Set Showmatch: Highlight matching brackets; Noshowmatch do not highlight matching parentheses
: Set Nu: Display line number: Nonu: Cancel line number
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/8B/wKioL1XmjvKiosLIAANVFVx4zRg135.jpg "title=" Figure 8.jpg "alt=" Wkiol1xmjvkiosliaanvfvx4zrg135.jpg "/>
: Set syntax on: automatic syntax highlighting
: Set ignorecase smartcase: Ignore case when searching
The above are temporary settings, if you need permanent settings to take effect, you need to edit the configuration file:
Global configuration file:/ETC/VIMRC
Example: Set all users to display line numbers when vim edits a file
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/8B/wKioL1XmjwKzgRODAAWUzO-DLwM639.jpg "title=" 9.jpg " alt= "Wkiol1xmjwkzgrodaawuzo-dlwm639.jpg"/>
User profile: ~/.VIMRC
Read more about the Vim editor to see the vim built-in Tutorial input command: Vimtutor
Comprehensive Example:
1, copy the/etc/grub2.cfg configuration file to the/tmp directory, use the Find replacement command to delete the/tmp/grub2.cfg file at the beginning of the blank character;
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/8B/wKioL1Xmjymgo1bwAAWbc7VYMUc657.jpg "style=" float: none; "title=" Figure 10.jpg "alt=" Wkiol1xmjymgo1bwaawbc7vymuc657.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/8F/wKiom1XmjQryWNO0AAV083Smwok096.jpg "style=" float: none; "title=" Figure 11.jpg "alt=" Wkiom1xmjqrywno0aav083smwok096.jpg "/>
Note: The%s/^\+s\//command indicates that the range is "%", so this works on the entire file. The match pattern for the "substitute" command is "^\+s\". This represents one or more (\+) spaces (\s) before the beginning of the line (^). The "to" part of the Replace command is empty: "//". This will delete those matching whitespace characters.
2. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and add a # to the beginning of the line beginning with a blank character for each line of/tmp/functions with the find replacement command; The original whitespace character is reserved;
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/8B/wKioL1Xmj0PSiV-cAAPdOjN1Djs534.jpg "title=" Figure 12.jpg "alt=" Wkiol1xmj0psiv-caapdojn1djs534.jpg "/>
3, replace the/etc/sysconfig/init in/tmp/functions file is/var/log;
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/8F/wKiom1XmjTuCQXGQAAMcF3LfKP4131.jpg "style=" float: none; "title=" Figure 13.jpg "alt=" Wkiom1xmjtucqxgqaamcf3lfkp4131.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/8B/wKioL1Xmj17wQqAIAAPQ7yeSKcg350.jpg "style=" float: none; "title=" Figure 14.jpg "alt=" Wkiol1xmj17wqqaiaapq7yeskcg350.jpg "/>
4. Delete all lines beginning with # in the/tmp/functions file with # followed by at least one white space character at the beginning of the line #;
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/8F/wKiom1XmjVfjT54qAAJhpzb5EvQ503.jpg "title=" Figure 15.jpg "alt=" Wkiom1xmjvfjt54qaajhpzb5evq503.jpg "/>
This article is from the "10,000-hour Law" blog, be sure to keep this source http://daisywei.blog.51cto.com/7837970/1690778
The VIM editor for Linux