Some of the commands commonly used by vim

Source: Internet
Author: User

Vim commands a lot, it is difficult to remember the whole, so combined with my usual practice, often to use the command has been marked with red body word. If there are any errors, please note.

?three different states
Command: Any input will be used as an edit command without appearing on the screen and any input will cause immediate reflection
Insert: Any input data is placed in the edit register, press ESC to jump back to command mode
Escape: An instruction preceded by ":" or "/" appears on the bottom line of the screen, and any input is treated as a special instruction.
?Leave VI
: q! Leave VI and discard the content you just edited within the buffer.
: Wq writes the data in the buffer to disk and leaves VI.
: X with Wq.
(Note that--:x is file encryption, be sure to match with: X to save the exit)
? Enter input mode
A (append) is joined by the cursor after the data.
A by the end of the bank to add information.
I (insert) is joined by the cursor before the data.
I shall add the information to the first of the bank.
O (Open) adds a new line below the line for the input data.
O add a new line to the row for input data.
? Delete and modify
x Delete the character where the cursor is located.
X Delete the character before the cursor is located.
R replaces the character of the (replace) cursor with the character followed by this instruction. For example, RA replaces the character of the cursor with a.
R enters the replacement state until ESC is reached.
s deletes the character that contains the cursor and enters input mode until ESC.
S deletes the row data for the cursor and enters the input mode until ESC.
? The movement of the cursor
m<a-z> setting Bookmarks <a-z>
' <a-z> move to bookmarks <a-z>
0 move to the top of the line
$ move to the end of the line.
e moves to the last letter of the next word
W moves to the first letter of the next word.
b moves to the first letter of the previous word.
^ Moves to the first character of the line.
H moves to the first line of the window.
M moves to the middle row of the window.
L move to the last line of the window.
G moves to the last line of the file.
+ Move to the first character in the next column.
-Moves to the first character in the previous column.
: N moves to the nth column of the file.
N+ moves to the nth column after the cursor position.
N-Moves to the nth column before the cursor is located.
<Ctrl><g> Displays the line number, file name, line number of the last line in the file, and the row number of the cursor that is the percentage of the total number.

(VIM) Cursor Movement basic usage pee:
(This is as long as the combination of the above functions can be understood, no more one by one to explain it!) )
GE b W E
←←---→--→
This is-a line, with Special/separated/words (and some more).
←-←-------------------→---→
GE B W E

? The movement of Windows
<Ctrl><f> Windows scroll down one page.
<Ctrl><b> window to roll up a page.
<Ctrl><d> Windows scroll down half page.
<Ctrl><u> window to roll up half a page.
<Ctrl><e> Windows scroll down one line.
<Ctrl><y> windows to roll up a row.
? Cut, copy, delete
Operator + Scope = command
? Operator
D cut
y copy.
p paste, with D and Y and use. The data of the last D or Y can be placed under the row of the cursor position.
c Modify, similar to delete with Insert group and. Delete a word group, sentence and other information, and insert new data.
? The whole operation was made
DD deletes the entire row.
D deletes all the characters after the cursor in the behavior unit.
cc modifies the contents of the entire line.
yy copies the row where the cursor is located to the memory buffer.
? Cancel a previous action (Undo)
U restores the result before the last instruction.
U restores all changes to the row of the cursor.
(VIM) u can undo the instruction multiple times and undo one operation at a time until the start of the operation.
(VIM) Ctrl+r can revert to the pre-undo content, and can be recovered multiple times by multiple times.
? Find and replace
/String to search for the string after the cursor.
The string looks for the string before it is moved to the cursor.
N continue searching for the next identical string.
N continue looking for the next identical string.
% lookup "(", ")", "{", "}" for the pairing.
s search for a range of rows.
G Search data for the entire edit buffer.
: 1, $s/old/new/g change all the "old" in the file to "new".
: 10,20s/^//Insert 5 blanks at the front of line 10th through 20th.
(VIM)
/string after the input query content can be saved to the buffer, can be used to ↑↓ the previous content selection.
Also: Move the cursor below the selected word to press *, you can select this word as the query character, you can avoid the trouble of entering a long string of characters.
? (VIM) case-sensitive replacement
First Use press V to open the selection function, and then use the ↑↓←→ key to select the character to be replaced, if lowercase to uppercase, then press U;
If you select a word, you can press V, press W, and finally press u/u, so you can change the size of the word Fu without deleting and re-typing.

? Connection of data
J the connection of the sentence. Connect the row below the cursor to the cursor after the row.
? setting of the environment
: Set all to set the list of environment variables
: The current value of the SET environment variable
: Set Nu Sets the line number of the data.
: Set Nonu cancels line number setting.
: Set AI automatically shrinks.
: Set NOAI cancels auto-indent.
(VIM)
: Set ruler will display the current cursor position in the lower right corner of the screen, and change with the light movement, occupy the screen space is small, use is more convenient, recommended use.
: Set Hlsearch will highlight all matching content when using the Find function.
: Set Nohlsearch to turn off this feature.
: Set Incsearch enables VIM to position the matching point in the input string while the cursor is positioned to display it.
: Set Nowrapscan turns off the Find auto loopback function, which is to find the end of the file, end the lookup; The default state is auto loopback

? Ex Instruction
? Read and write Data
: 10,20w Test writes the data from line 10th to line 20th to the test file.
: 10,20w>>test adds the data from line 10th to line 20th after the test file.
: R test reads the data from the test file into the end of the edit buffer.
: e [filename] edits a new file.
: e! [FileName] Discards the currently modified file and edits the new file.
: SH enters the shell environment, exits with exit and returns to the editor.

!cmd: After running command cmd, return to the editor.
? Delete, copy and move
: 10,20d Delete data from line 10th to line 20th.
: 10d Delete data from line 10th.
:%d deletes the entire edit buffer.
: 10,20co30 copies the data from line 10th to line 20th after line 30th.
: 10,20mo30 the data from line 10th to line 20th after line 30th.

Some of the commands commonly used by vim

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.