A moment with vim, a moment with Emacs, the big artifact commands are all confused. For_wind
vimtutor Tutorial
Beginners must see OH.
VIM Tutor
most basic command
Insert: I
Save exit:: Wq
Do not save exit:: q! Ignore The basic concept of forced exit VI
Basically VI can be divided into three states, which are command mode, insert mode (insert modes), and bottom line mode (at last), the functions of each pattern are distinguished as follows:
(1) Command mode.
Controls the movement of the screen cursor, the deletion of characters, words, or rows, the movement of a section and into the insert mode, or the last line mode.
2 Insert Mode
Only in insert mode, you can do text input, press the "esc" key to return to the command line mode.
3 End Line Mode
Also known as ex mode.
To save or exit VI, you can also set up an editing environment, such as finding a string, listing line numbers ... Wait Command mode
(1) I, a, o switch into insert mode. [Super Common]
(2) Moving the cursor
VI can be used directly on the keyboard to move around the cursor keys, but the normal VI is a lowercase letter h, J, K, L, respectively, control the cursor left, down, up and right one lattice.
Press CTRL+B: The screen moves one page backward. [Usual]
Press CTRL+F: The screen moves one page forward. [Usual]
Press Ctrl+u: The screen moves half a page back.
Press Ctrl+d: The screen moves half a page forward.
Press W: the cursor jumps to the beginning of the next word. [Usual]
Press e: The cursor jumps to the end of the next word.
Press B: The cursor returns to the beginning of the previous word.
Press $: Moves to the end of the line where the cursor is located. [Usual]
Press ^: Moves to the first non-white-space character of the line.
Press 0: Move to the beginning of the line. Common
Press #: Move to the # position of the line,
[: This is a two-character instruction that moves the cursor forward to the first {.
] : Similar to the previous command, the difference is that it moves backwards, moving the cursor back to the first {.
(3) Delete text
x: Deletes one character from the position of the light every time it is pressed. [Paranormal Use]
#x: For example, the 6x table deletes the following 6 characters from the position of the cursor. [Usual]
x: Big Big X, each time you delete the previous character in the position of the cursor.
#X: For example, the 20X table deletes the previous 20 characters from the position of the cursor.
DD: Deletes the line where the cursor is located. [Paranormal Use]
#dd: For example, a 6DD table deletes text that is 6 lines down from the line where the cursor is located. [Usual]
(4) Copy
yw: Copies the characters at the end of the cursor to the buffer. (Want to be in and #x, #X的功能相反)
P: Pastes the characters in the buffer into the cursor location (instruction ' yw ' and ' p must be used together).
yy: Copy the row where the cursor is located. [Paranormal Use]
p: Copy single line to where you want to paste. (instruction ' yy ' and ' p ' must be used in combination with)
#yy: 6yy indicates that the copy is 6 lines down from the line where the cursor is located. Common
P: Copy multiple lines to where you want to paste. (instruction ' #yy ' and ' p ' must be used in combination)
"Ayy: the copy row into buffer A, vi provides buffer function, you can use the data exist buffer
AP: The data to be placed in buffer a is pasted.
"B3YY: Store three rows of data in buffer B."
"b3p: Paste the data that exists in buffer B
(5) Replace
R: Replace the character at the cursor: [Common]
R: Replaces the character until you press ESC.
(6) Restoration (undo) Previous Instruction
u: If you mistakenly operate an instruction, you can press u immediately to revert to the previous operation. Revoke. [Paranormal Use]
.:. You can repeat the previous instruction.
(7) Change
C: Deletes all content from the current line after the cursor, and then enters insert mode.
C{motion}: Deletes text from the current cursor based on the contents of motion, and then enters insert mode.
CW: Change the word to the end of word at the cursor and switch to insert mode.
C#w: For example, c3w represents a change of 3 word.
(8) skip to specified line
Ctrl+g: Lists the line number of the line where the cursor is located.
#G: 15G, for example, represents moving the cursor to the beginning of the 15th line of the article. Common next to line mode
Instructions: Please remember to press ESC to make sure you are already under command mode, and then press the colon ":" to enter last line mode.
1. List Line Numbers
Set Nu: After entering "set Nu", the line number is listed before each line in the article.
2. jump to a line in an article
#: The well number represents a number, enter a number before the last line mode prompt symbol ":", and then press ENTER to jump to the row, such as: 15[enter] will jump to the 15th line of the article. Common
3. Find a String
/keywords: first press/, and then enter the word you want to find, if the first time to find the keyword is not as far as possible, you can always press N will be down to find the keyword you want so far. Keywords: press first. , and then enter the words you want to find, if the first time you find the keyword is not what you want, you can press N will look forward to the keyword you want so far.
4. Replace string
1, $s/string/replace/g: in last line mode, enter "1, $s/string/replace/g" to replace the full text string with the Replace string, where 1,$ s means that the search interval is the beginning of the article, and G is a means of replacing it with no confirmation. %S/STRING/REPLACE/C: The full text string is also substituted for the replace string, unlike the instructions above,%s and 1, $s is the same function, and C means that the substitution must be confirmed again before it is replaced. 1,20s/string/replace/g: Replaces a string of between 1 and 20 rows with a relpace string.
: S/search/replacement/flags
5. Save File
W: In the last line mode prompt symbol ":" Press W to save the file. [Paranormal Use]
#,# w FileName: If you want to extract a section of the article and save it as another file, use this instruction # to represent the line number, such as 30,50 W Nice, to save the 30th to 50th line of the article you are editing as nice.
6. Leave
Q: Press Q to leave, sometimes if can not leave VI, can match. : Strong leave VI, such as "Q". ”
QW: Generally recommended to leave, with W to use together, so leave can also save files.
Insert Mode
ctrl+n/ctrl+p: fills the word that has already appeared in the document. CTRL + N key to find a matching word, ctrl+p combination of key to find the previous matching words.
ctrl+t/ctrl+d: Converts the current line to the left or right through shiftwidth settings.
Regular Type:
*: Automatically generate a search for word at the current cursor, which can be moved up and down through N.
To move the cursor over the word (variable name, function name, etc.) you are searching for, such as "test" and then press "*", Vim will automatically generate a search for "\<test\>" (see ": Help/\<" and "help/\>"), that is to say, Search for the complete word "test". Do not underestimate this technique, it often can greatly improve the speed of the search.