Vim uses Series 2-summarize common Vim operations (update while using)

Source: Internet
Author: User

Author: gnuhpc http://blog.csdn.net/gnuhpc/

1. move the cursor

Move the cursor effectively in the current row. Note that these letters can be used with deletion, movement, and other operations.
FX: move the cursor to the next X of the current row. Obviously, X can be any letter, and you can use; to repeat your previous F command.
TX: similar to the preceding command, but it is moved to the left of X. (This is really useful)
FX: it is similar to Fx, but you can look back.

% Jump to matching brackets
[[Jump to the beginning of the code block (but the '{' in the code block must be a separate line)
W: move the cursor forward to a word.
B: Move a word behind the cursor.
0: move the cursor to the beginning of the current row.
^: Move the cursor to the first letter of the current row.
$: Move the cursor to the end of the row.
): Move the cursor to the next sentence.
(: Move the cursor to the previous sentence.
''Jump to the position where the cursor was stopped last time. It's two '', not one"
GD arrives at the position where the cursor is located, where the function or variable is defined.
GF jumps to the corresponding header file. The solution to the failure to find the header file is: set path + = xxx, and XXX is the directory where the header file is located.
K finds the word at the current position of the cursor in man.
CTRL + B: Move the screen down.
CTRL + F: Move the screen up.
G: to the end of the file
Numg: move the cursor to the specified row (Num ). (For example, 10 Gb is to 10th rows)
GG: to the beginning of the file
H: move the cursor to the screen
M: move the cursor to the center of the screen
L: move the cursor to the screen
*: Read the string at the cursor and move the cursor to where it appears again.
#: It is similar to the above, but it is looking in the opposite direction.
J down
K up K
L to the right H l ==> hjkl <=> upper left and lower right
H To left J

 

2. Search

/Pattern: Search for pattern from the beginning of the cursor to the end of the file
? Pattern: Search for pattern from the beginning of the cursor
N: Repeat the previous search command in the same direction.
N: Repeat the previous search command in the reverse direction.
: S/source string/Target string/g replace all matching strings in the current row
: Line number 1, line number 2 S/source string/Target string/g Replace in the specified line
: % S/source/target/g full-text replacement
MA: Mark a bookmark at the position of the current cursor. Its name is. Only lowercase letters are allowed. You can't see the existence of bookmarks, but it is already there.
'A: To bookmarks. Note that this is not a single quotation mark. It is generally located on the left of 1 of most keyboards.
'.: The last time you edited the file. This command is useful, and you do not need to mark it yourself.
: Marks

3. Copy, paste, and cut

Valid text for moving large segments
V: select by character.
V: select by row. This is especially useful when you want to copy or move many lines of text.
CTRL + V: select by block.
VI [select all characters in a pair []

VI (select all characters in a pair ()

VI <select a pair of <> All characters
VI {select all characters in a pair {}
Vit Selects all characters inside the HTML/xml tag
When selecting a mode, use the arrow keys and commands described above (motion ). For example, vwww highlights the three words in front of the cursor. Vjj will highlight the current line and the following two lines.
Once you highlight the selection area, you may want to perform some operations:
D: paste the selected content to the clipboard.
Y: copy the selected content to the clipboard.
C: paste the selected content to the clipboard and enter the insert mode.
If you know exactly what you want to copy or cut, you do not need to enter the visual selection mode. This will save time:
D {motion}: Cut the characters crossed by the motion command to the clipboard. For example, DW cut a word and DFS cut the character from the current cursor to the next S to the clipboard.
Y {motion}: similar to the above, but it is a copy.
C {motion}: similar to d {motion}, but enters the insert mode.
DD: Cut the current row.
YY: copy the current row.
Cc: Cut the current row and enter the insert mode.
D: cut from the cursor position to the end of the row to the clipboard.
C: similar to D, and finally enters the insert mode.
X: Cut the current character to the clipboard.
: Similar to X, but enters the insert mode at last.
Y + W: copy the cursor to the entire word.

Use multiple clipboard
Many editors only provide one clipboard. There are many Vim instances. The clipboard is called a register in vim ). You can list all register names and their contents defined currently. The command is ": Reg ". It is best to use lower-case letters as the register name, because some of the upper-case letters are occupied by VIM. The register command is double quotation marks ".
For example, we want to copy the current row to register K. You should press "kyy. (You can also use v "Ky. Why ?) Now the current row should already exist in register K until you copy something into Register K. Now you can use the "kp" command to paste the content in register K to the desired position.
"Ayy copies the current row to register
"AP pasted the content in register a after the cursor
L: registers view the content of all registers
L generally, the register + ("+ Shift + =) corresponds to the clipboard under X. You can use "+ P to paste the copied content in other programs into Vim. In vim, you can use" + Y to copy the content to the clipboard and then paste it into other programs.
L if no register is specified, VIM uses "anonymous register" to store the content

4. Delete (the C and D commands have a different insert operation)

C {motion}: delete Motion
Enter the insert mode. For example: C $, this will delete the characters from the cursor position to the end of the line and enter the insert mode. CT !, This will delete the exclamation point from the cursor position to the next one (but not the package
And then enter the insert mode. The deleted character is stored in the clipboard and can be pasted out.

For example, CW: delete the word at the cursor and insert it. (C -- change)

D {motion}: similar to the above, but does not enter the insert mode.
Commonly used delete text commands in VIM:
C + C Delete the row and insert
D + D: press d twice to delete the row where the cursor is located. If the row is deleted consecutively, press and hold D.
D + W: delete the word where the cursor is located. If the cursor is between two words, delete the word after the cursor.
D. Delete all words behind the row where the cursor is located
X deletes the last character from the cursor location.
X deletes the character before the cursor position
DAW deletes common words and spaces behind the cursor.
CIW deletes "Words" separated by spaces under the cursor and enters the insert mode (I indicates inner, without deleting spaces after words)
CI [deletes all the characters in a pair of [] and enters the insert mode
Ci (delete all the characters in a pair of () and enter the insert mode
CI <deletes all the characters in a pair <> and enters the insert mode
CI {Delete All characters in a pair {} and enter the insert mode
CIT deletes all characters in an HTML/xml tag and enters the insert mode.

5. Insert

Switch the command line mode to the input mode in VIM for insertion:
I: insert it to the left of the Current Character
I: insert at the beginning of the current row
A: insert it to the right of the Current Character
A: insert at the end of the current row
O: Insert a new row under the current row.
O: Insert a new row on the current row.
: AB substitution operator original information-custom scale-down symbol. For example: AB mymail warmbupt@gmail.com in any place after entering mymail and then press the space to insert this information

6. Modify

R: Modify the character of the cursor
R: Modify the character at the cursor position. You can always replace the character and Press ESC.
U indicates restoration.
U cancels all changes made to the row
> Indent all selected Codes
<Similar to the preceding but not indented
: 1st S/^/\ // G continuous line comment, comment 20th rows to rows. ("^" Indicates insert at the beginning of the line, "//" indicates the character to be inserted (escape), and "G" indicates that the replacement is not confirmed)
: R file name directly imports other files or command execution content into the current file (write the current system kernel information in the comment, just: R! Uname-)
V % = press this key combination at the parentheses. The content in the brackets is selected and scaled down according to the C language format. The cursor will automatically jump to the definition of the xxxx () function, variable, structure, macro, and so on.
V is the visual mode, % is to jump to the matched place, = format the source file.
Exchange two characters before and after XP
DDP swap up and down two rows (these two lines are quite understandable)
Add Note: (one operation is applied on multiple rows) Ctrl + V
Locate the start line, select the required line, run the I command, enter # Or //, and then press
Run the ESC key twice to apply the comment operation to all selected rows. Remember that you cannot use the V command instead of the CTRL + V command.
(Refer to the above method for clearing comments) (V is selected by row, CTRL + V is selected by column)
: Line1, line2s! \ S *//.*!! Remove the // annotation between line1 and line2
: Line1, line2s! \ S */\ * \ _. \ {-} \ */\ s *! ! Remove/**/comment between line1 and line2
: S %/^ m // G converts the DOS text to UNIX text. ^ m must be Ctrl + V + m at the same time to press Enter.

7. File Operations

E. Create a new file.
N load new files
W writes the file. It is saved to the temporary file and exits directly. It is not saved to the file.
W! If you want to write a read-only file, use it to forcibly write the file.
Q! Force exit without asking if you want to save the file
Set can set certain Vim features. Cancel settings and use set none
Z + z save and exit Vim

8. Macro

You can record a series of operations into a macro and then execute it.
Q <macro name> starts recording macros. Macro name is a character
In Q recording, press "Q" To End recording.
@ <Macro name> execute macro
You can run the: registers (register list) command to view the recorded macros.

9. Statistics:

Full text words: G + Ctrl + G
The percentage of the number of articles and the total number of lines at the current position: Ctrl + G

10. Tips in VIM
TIPS:
1. If you do not know whether you are in the editing or command mode, you can use the ESC key to exit the command mode and then perform the operation.
2. When using vim, you can use the recovery command in case of system power failure or sudden shutdown, such as the recovery command after sudden power failure or system crash when editing the file: $ VI file-R
3. Use vim-U/root/vimrc. Vim when starting vim, and use vertion to view the vimrc configuration file and vimrc configuration file path.
4. To view the set shortcut key, enter map.
To cancel this shortcut, enter the command: unmap ^ P
5. In this case, & XXX denies the xxx variable and can be used to write vimrc functions. For example, the highlighted function is:
Function togglehlsearch ()
If & HLS
Set nohls
Else
Set HLS
Endif
Endfunction
Call function: Call togglehlsearch ()
6, abbreviations: AB sammail sam@163.com in input mode input "sammail", and then any letter or enter a space, "Sam @ 163.com"
7. run Unix/Linux commands without exiting Vim/VI :! Command
8,: H quickref go to the vim Quick Reference page (useful !).
9. The environment variable % indicates the current file name.
10, # encryption (use it with caution and do not forget the password)
: X: Then Vim will prompt you to enter the password
: WQ (it takes effect only when the password is saved)
11. Using numbers is also a powerful and time-saving feature of vim. You can use a number before many Vim commands. This number will tell Vim how many times this command needs to be executed. For example:
* 3j moves the cursor down three rows.
* 10 DD will delete 10 rows.
* Y3 "copies the content from the current cursor to the third quotation mark to the clipboard.
Numbers are very effective methods to extend the scope of the motion command.
12, G count

Summary of VIM mode (http://denven.blog.hexun.com/11922673_d.html)

Part1. six basic modes:

1. In nomal mode, all common editing commands can be entered. After the editing is started, the normal mode is used by default and the editing command is accepted.

2. insert mode the input content in insert mode is inserted into the current buffer zone. This is the editing mode of the common editor that we are most familiar.

3. The visual mode is similar to the normal mode, but moving the cursor time mark expands the highlighted area. A non-cursor command can act on the highlighted area.
I will divide it into three specific situations to understand. (In the figure, $ indicates the end of the row)

3.1. Normal visual mode. Enter by V. It does not apply to rows or columns separately. The range is the content between the initial position of the cursor and the current position of the cursor.
... Cursor starts here | --------------------------------------------------------------------- $ |
+ Region $ |
| Items $ |
+ ------------------------------------- | The cursor stops here, maybe some content continued

3.2. Visual "row" mode. Press V to move the cursor to the entire line.
If the row where the cursor starts is "I", the selected row number is "J.
The content is the content of the [I, j] Line. :

+ ------------------------------------------------------------ Starts here | -------------- $ |
| Items $ |
| Items $ |
+ --------------------------------------- $ | The cursor stops here

3.3 visual block mode. Enter by CTRL-V, and gvim enter by CTRL-Q (capital.
The selected range is within the rectangle block determined by the cursor's initial position and position after the cursor moves.

Cursor begin | ------------- ++ ---------------- | End
| ------------- | ---------------- |
| ------------- | ---------------- |
| ------------- | ---------------- |
+ ------------- | End begin | ---------------- +

Exmaple 1 Example 2

4. In command mode, you can enter a line of command in the base line, also known as the base line mode. Press the colon to enter the command line mode. I usually think of it as a special case of common mode. Because there are too few executable commands.

5. The ex mode ex editor mode starts with the ex mode, which is similar to the command line mode. However, after the command is completed, it will continue to stay in this mode.

6. In select mode gvim, the selected part of the mouse will be prompted as "select ".

Part2. five additional modes:

1. Operator wait mode: I have not understood what the so-called operator refers.
2. Replacement mode: it can be considered as a special case of insertion mode.

In the insert mode, press to return to a critical normal mode. In this case, you can switch to another mode and run the command. However, after the command is completed, it is immediately returned to the insert mode. For example:

3. Insert the normal mode and run the edit command (even if it is not a, I, A, I, O, O and other commands) to enter the insert mode.
4. After you press the insert visual mode button, the edit command is not executed, and the buttons enter the visual mode. After the visual selection, a command (same as above) is executed and the result is returned to the insert mode.
5. After you press the insert selection mode, you can use the mouse to select the mode. After the selection ends (click the mouse), the insert mode is returned.

 

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/gnuhpc/archive/2010/02/01/5276368.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.