Vim Command Daquan

Source: Internet
Author: User

Three command-line mode operation

1. Enter insert mode

Press "I": Enter the file starting at the cursor's current position.
Press "I": Insert at the beginning of the line where the cursor is located.
Press "a": Enter text from the next position where the cursor is currently located.
Press "A": Insert at the end of the line where the cursor is located.
Press "O": Insert a row below
Press "O": Insert a row above.
Press "s": delete one character after the cursor and enter insert mode.
Press "S": Delete the line where the cursor is located and enter insert mode.

3. Move cursor

"H", "J", "K", "L" respectively control the left, bottom, upper and right of the cursor to move one cell.

"W": the cursor jumps to the beginning of the next word.
"E": the cursor jumps to the end of the next word.
"B": the cursor returns to the beginning of the last word.
"NL": the cursor moves the nth position of the row, for example: "5l" represents the 5th character moved to the line.

"Ctrl+b": the screen moves backward one page.
"Ctrl+f": the screen moves forward one page.
"Ctrl+u": the screen Moves backward half-page.
"Ctrl+d": the screen moves forward half a page.
-Number "0": moves to the beginning of the text.
"G": Moves to the end of the file.
-"$": Moves to the end of the line where the cursor is located.
"^": moves to the beginning of the line where the cursor is located.

4. Delete text

"X": Deletes the following character at the position of the cursor every time it is pressed.
"NX": for example: "6x" means the deletion of 6 characters after the cursor position.
"X": Deletes the previous character in the position of the cursor every time it is pressed.
"DD": Deletes the line where the cursor is located.
"NDD": Deletes n rows starting at the line where the cursor is located. For example: "4DD" means deleting 4 lines of characters from the line where the cursor is located.

5. Copy

"YW": copies the character of the cursor at the end of the word into the buffer.
"NYW": copies n words to buffer.
"YY": Copies the line of the cursor to the buffer.
"Nyy": for example: "6yy" means that the copy starts at 6 lines of characters from the line where the cursor is located.
"P": writes the characters in the buffer to the location of the cursor.

8. Change

CW: Changes the word-to-tail at the cursor location.
"CNW": for example: "c3w" means change of 3 words.

9. Jumps to the specified row

"Ctrl+g": Lists the line number of the line where the cursor is located.
"NG": for example: "15G", which means moving the cursor to the beginning of the 15th line of the file.

Other:

"ZZ": Save and exit
"ZQ": Do not save the disk to exit
"R": replaces the character at which the cursor is located.
"R": replaces characters that are everywhere in the cursor until the ESC key is pressed.
"U": Undo Last Action

Four Last-row mode operation

Before using the last row mode, remember to press the "ESC" key to determine that you are already in command-line mode, and then press the colon ":" to enter the last line mode.

"Set nu": List line numbers
"Set Nonu": un-listing line numbers
"Set IC": ignoring case when searching
"Set Noic": Cancels ignoring case when searching.
"N": jumps to a line in the file, "n" represents a number, such as enter the number 15, and then enter the text will jump to the 15th line.
"!cmd": Run shell command cmd.

Find characters :
"/keyword": First press "/", then enter the character you want to find, if the first search for the keyword is not desired, you can always press "n", looking for a keyword.
“? Keyword ": Press first?" Key, and then enter the character you want to find, and if the keyword you first searched for is not what you want, you can always press "? , look for a keyword later.

Replacement characters :
"S/sparch/replace/g": replaces the search word in the row where the current cursor is located, and highlights all search.
"%s/sparch/replace": Replaces all search in the document with replace.
"N1,n2 s/sparch/replace/g": N1, N2 represents a number that represents a row from N1 to N2, replacing search with replace.

Five command-line Content description

Command line mode: How to move the cursor
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 keys (↑) Move the cursor up one character
L or right ARROW key (→) The cursor moves one character to the right
If you want to move multiple times, for example, to move down 30 rows, you can use the combination of "30j" or "30↓", which is the number of times (numbers) you want to do.
[Ctrl]+[f] Screen "Down" to move one page, equivalent to [Page DOWN] button
[Ctrl]+[b] Screen "Up" to move one page, equivalent to [Page UP] button
[Ctrl]+[d] Screen "Down" to move half a page
[Ctrl]+[u] Screen "Up" move half page
Command line mode: How to move the cursor
+ Cursor moves to the next line of non-whitespace
- Cursor moves to the previous line of non-whitespace
N<space> N means "number", for example 20. When you press the number and then press the SPACEBAR, the cursor moves the line n characters to the right. For example, the cursor moves 20 characters away from the back of the 20<space>
0 This is the number "0": Move to the front of the line prompt (common)
$ Move to the last face of this line prompt (common)
H The cursor moves to the top of the screen, which line
M Which line the cursor moves to the center of the screen
L The cursor moves to the bottom of this screen which line
G Move to the last line of this file (common)
NG N is a number. Move to the nth row of this file. For example 20G moves to line 20th of this file (mates: Set Nu)
Gg Move to the first line of this file, equivalent to 1G (common)
N<enter> N is a number. Move the cursor down n rows (common)
Command-line mode: Search and replace
/word Starting at the cursor position, look down for a string named word. For example, to search within a file Vbird this string, enter/vbird (common)
? word From the cursor position, look up for a string named word
N N is the English key. Represents "repeating the previous search action." For example, if you just executed/vbird to search for the Vbird string, pressing N will continue searching down the next string named Vbird. If the Vbird is executed, then pressing N will continue to search for a string with the name Vbird.
N This n is the English key. In contrast to N, the previous search operation is for "reverse". For example/vbird, pressing n means "up" search Vbird
Command-line mode: Search and replace
: N1, n2s/word1/word2/g N1 and N2 are numbers. Look for the string word1 between N1 and N2, and replace the string with Word2. For example, search for vbird between 100 and 200 rows and replace with Vbird: ": 100, 200s/vbird/vbird/g" (Common)
: 1, $s/word1/word2/g Find the Word1 string from the first line to the last line and replace the string with Word2 (common)
: 1, $s/word1/word2/gc Look for the word1 string from the first line to the last line and replace the string with Word2. and display the prompt to the user before replacing (conform) need to replace (common)
command line mode: Delete, copy and paste
p,p p to paste the copied data to the next line of the cursor, p is a row attached to the cursor. For example, the current cursor is in line 20th, and 10 rows of data have been copied. When P is pressed, the 10 rows of data will stick to the original 20 lines, starting with 21 lines. But if you press p, then the original 20th line is turned into 30 rows (common)
j /tr>
c repeatedly deleting multiple data, such as deleting 10 rows down, [10CJ]
U revert to previous action (common)
[ctrl]+r Redo last action (common) /td>
u with [Ctrl]+r is a very common command. One is recovery, the other is redo. With these two function buttons, you can edit them handy.
command-line mode: Delete, copy and paste
This is not a few points. It means repeating the previous action. If you want to repeat the deletion, repeat pasting, press the decimal point "." You can (common)
Insert mode
I, I Insert: Inserts input text at the current cursor where the existing text is backward, where I is "inserting from the current cursor", and I is "inserting at the first non-whitespace space in the current row" (common)
A, a A is "insert from the next character where the current cursor is located" and A is "start at the last character of the line where the cursor is located" (common)
O, O This is the case of the English letter O. o Insert a new line at the next line where the current cursor is located, o insert a new row on the previous line where the current cursor is located (common)
R, R Replace: R replaces the character where the cursor is located, and R will always replace the text in the cursor until the ESC key is pressed (common)
When using these keys, the words "-insert--" or "-replace--" will appear in the lower left corner of the VI screen. You know what the operation is by name. Special attention, also mentioned above, want to enter characters in the file, be sure to see insert/replace in the lower left corner to enter.
Esc Exit insert mode, back to command line mode (common)
Last-line Command mode
: W Writing edited data to a hard disk file (common)
: w! If the file property is read-only, the file is forced to be written. However, in the end can write, and file permissions related
: Q Leave VI (Common)
: q! If you have modified the file, do not want to store, use! Do not store files for forced leave
Notice that the exclamation point (!) is often "mandatory" in VI.
: Wq Save after leaving, if: wq! is forced storage after leaving (common)
: e! Restore a file to its original state
Zz If the file is not changed, it is not stored and left, and if the file has changed, the store leaves
: W[filename] Store edited data as another file (similar to saving new files)
: R[filename] In the edited data, read the data from the other file. Add the file "filename" to the following line of the cursor
: N1, N2 W[filename] Store N1 to N2 content as a filename file
:!command Temporarily leave VI to command mode to perform the display of the commands. For example, ":! Ls/home ", you can view the file information in/home with LS output in VI
: Set Nu Displays the line number, after which the line number is displayed in the prefix of each row
: Set Nonu In contrast to set NU, the line number is canceled

In particular, in VI, "number" is very meaningful. A number usually means repeating a few times. It is also possible to indicate where to go. For example, to delete 50 rows, use "50DD". The number is added before the action. To move 20 rows down, use "20j" or "20↓".

Mastering these commands is good, because the commands you use are probably only half the same. Usually the command of VI in addition to the above the author noted the usual several, the other do not use the back, you can do a simple command table, when there is a problem can be immediately queried.

Vim Command Daquan

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.