Count on the University class Linux contact for four years, but in addition to work contact those, other places are still very water, are not proficient, today turned to look at the previous reading that forget the vim skills, found, such as no years of operation experience, these skills difficult to comprehend. Write it down here for later inspection.
Block selection V-character selection, will be the cursor through the place of the white selection! V (uppercase) line selection, will be the cursor through the line anti-white selection! (commonly used, with the next key around, to make a regional selection, very cool) [Ctrl]+v block selection, you can use the rectangular way to select data y will be anti-white place copy D will be reversed White Place Remove the area selection if you are following the C command, you can delete and paste the area again. Delete operation For character manipulation:
x, x in a line of words, X is the backward deletion of a character (quite the [Del] key),
XTo delete a character forward (rather than [backspace], which is the backspace bar) (commonly used), NX N is a number that continuously deletes n characters backwards. Bowl example, I want to delete 10 characters, "10x" continuously. d$ Delete the cursor at the end of the line, all the characters d0 the row, and all the characters at the beginning of the row are deleted.
For row operations: DD deletes the entire column (common) ndd n is the number of the cursor. Delete the row where the cursor is located n rows down, for example 20DD to delete 20 rows (common) d1g Delete all data from the first row of the cursor the DG deletes all data associated with the last row of the cursor
Line Range
Move to the beginning of the line: GG
Move to end of line: character $
Small bet: The command "G" can be preceded by a number, here, the meaning of the number is not a multiple, but you intend to jump the line number. For example, if you want to jump to the 1234th line of a file, just enter "1234G".
Character 0: First non-null character before
Character ^: first non-null character on
Up or down: H, J, K, L
Small bet: As with many VIM commands, you can add a number to the key before these keys to represent a multiple of the move. For example, "10j" means moving down 10 rows; "10l" means moving the 10 columns to the right.
Page Range
Small bet: ctrl-b and ctrl-f are usually used to page pages, and their functions are equivalent to PageUp and PageDown. ctrl-b and ctrl-f can also be preceded by numbers to indicate how many pages are flipped up or down
Small bet: Move in a file, you may lose your place, then use the "ctrl-g" command to check your location. This command displays the location of the cursor and other information. To avoid getting lost, you can open the line number display, use the ": SetNumbers" command, will be displayed in front of each line travel number, can be more convenient to locate the jump (: Help "number")
Move to the specified character: using the F, T, F, t commands.
Small bet: The "F" command moves to the specified character on the right side of the cursor, for example, "FX", which moves to the first ' X ' character on the right side of the cursor. The "F" command looks in the opposite direction, that is, to the specified character on the left side of the cursor.
Thedifference between the "T" command and the "F" command is that it moves to the right of the cursor before the specified character. For example, "TX" moves to the front of the first ' X ' character to the right of the cursor. The "T" command is a reverse version of the "T" command, which moves to the right of the cursor after the specified character.
These four commands move the cursor only in the current line, and the cursor does not span the carriage return line break.
You can use a number in front of the command to indicate a multiplier. For example, "3fx" means moving to the 3rd ' x ' character on the right side of the cursor.
";" The command repeats the previous input F, T, F, t command, and the "," command repeats the previous input's F, T, F, t command in the opposite direction. You can also use numbers to represent multiples before these two commands.
Related to Replication YY copy cursor in the same row (common) Y1G copy cursor column to the first column all the data YG copy cursor column to the last column all data y0 copy All data y$ The character of the cursor to the beginning of the line. All data recovery and redo operations at the end of the line where the copy cursor is located U restore the previous one. Common [Ctrl]+r redo the last action.] (common) Replacement mode
The key is the "R" substitution pattern, which can quickly replace and insert data (similar to point-and-click in Word).
Finally, focus on the paste copy
With vim so long, always do not know how to use the system in vim in the pasteboard, usually to copy a piece of code on the Internet is first gedit open the file, the middle key paste and then close, and then use vim to open the editor , really uncomfortable; the last forum was asked how to use the system in vim , the impression of a lot of replies, there are several pages of the reply did not solve the problem, today really can not stand and find ways on the Internet, unexpectedly found, posted out to share.
If you just want to use the system pasteboard directly in the input mode by pressing Shift+inset (paste) on it, the following is the basic knowledge of vim paste board, interested can see, should have some gains.
The contents of the vim help document related to Pasteboard are as follows:
- Vim has 12 pasteboard, 0, 1, 2 、...、 9, A, ", +; use: Reg command to view the contents of each pasteboard. In vim , simply use y just copy to "(double quotation marks) in the pasteboard, also paste the same with P is the content of this clipboard
- to be vim Content Copy to a pasteboard, you need to exit edit mode, enter normal mode, select what you want to copy , and then press Ny (note quotes) to complete copy , where n is the pasteboard number (note that you press the double quotation mark and then press Y at the end of the pasteboard), for example, to copy the content to pasteboard A, select the content and press "Ay is OK, there are two points to explain:
- " Paste Board (temporary pasteboard) is more special , press Y directly to copy to the pasteboard, press p to paste the contents of the pasteboard;
- + The pasteboard is the system pasteboard, copy content with "+y" You can use CTRL + V to paste it into other documents (such as Firefox, gedit) after you go to the pasteboard, and, similarly, copy the contents of CTRL + C or right-clicking copy elsewhere. Vim , you need to press "+p" in normal mode,
- to paste the contents of a vim clipboard, you need to exit edit mode, press "Np" in normal mode, where n is the paste plate number, as described above, you can press "5p paste the contents of the 5th-plate paste in, you can also press" +p paste the contents of the system in the global Clipboard.
Note: In my case, only VIM.GTK or vim.gnome can use the system global Pasteboard, the default vim.basic does not see the + sign register. Install vim.gnome using Apt-get install Vim-gnome, then vim automatically links to Vim.gnome.
Here is the basic command for VIM copy and paste:
yy duplicates the row where the cursor is located. or uppercase one Y.
2yy or y2y copy two lines. Sunglass, please extrapolate good or bad! :-)
y^ copied to the beginning of the line, or y0. Does not contain the character where the cursor is located.
y$ copied to the end of the line. Contains the character where the cursor is located.
YW copy a word.
y2w copy two words (words).
YG is copied to the end of the file.
Y1G copy to the top of the file.
P lowercase p represents the post to the cursor (bottom).
The P-capital P represents the front (top) of the cursor. 、
The summary is:
(register) y (range) → The content that will be copied is placed in the specified register. Register includes all numbers and letters; Range is the scope, for example: W, y, and so on. You can also use visual actions to select what you want to copy and then copy it.
(register) p→ Pastes the contents of the specified register to the back of the cursor. The times specifies how often to paste.
Vim Editing Tips