Common Vim commands and usage

Source: Internet
Author: User
Common Vim commands and usage 1 switch insert mode: insert a (uppercase) after A (lowercase) cursor in command mode) insert I at the end of the row where the cursor is located (common commands and usage of lowercase Vim 1 switch insert mode: insert a (uppercase) after the cursor in command mode) insert I (lower case) at the end of the row where the cursor is located. Insert I (upper case) at the beginning of the row where the cursor is located. insert o (lower case) insert an empty row after the row where the cursor is located (uppercase) insert an empty row before the row where the cursor is located. in insert mode, press ESC to return to command mode 2 switch to edit mode. in command mode, Press [:] to enter edit mode, press enter to return to command mode or press ESC to return to command mode. 3. Save the file in editing mode: w (lower case) save the file: wq (lower case) save and exit vim: w file name 1 save the file as file name 1: ZZ (upper case) save the file and exit, equivalent to: wq! (Lower case) the file owner forces to save the read-only file. if this operation is not performed by the file owner, the operation cannot be successful: q! Exit do not save file 4 Copy (yank) command mode yy or Y copy the entire line of the cursor y ^ copy to the beginning of the line of the cursor, the cursor position Character y $ is not included. copy a word to the end of the row where the cursor is located, including the cursor position character yw, the cursor must copy the yG at the beginning of the word to the end of the file y1G to copy the nyy at the beginning of the file copy n lines 5 at the beginning of the cursor paste command mode p (lower case) paste to the cursor after P (upper case) paste to the top 6 of the cursor delete command mode x (lower case) delete the character before the cursor X (upper case) delete the character after the cursor dd (lower case) delete the entire row of the cursor dw (lower case) delete the word dG where the cursor is located delete the entire row of the cursor to the end of the file dgg delete the entire row of the cursor to the beginning of the file D (uppercase) delete to the end of the row, the character "d $" at the cursor position has the same effect as the character "D $" at the cursor position. "d0" is deleted to the beginning of the line, excluding the character "d ^" at the cursor position. The effect is the same as that in d0: n1, n2d editing mode, delete n1-n2 line 7 Undo command mode u (lower case) undo without limit before saving (about 500 times) ctrl + r redo8 character replacement command In this mode, replace the r (lower case) character at the place where the cursor is located, and replace it with the R (upper case) character until you press ESC to exit the replacement, which is equivalent to pressing the keyboard to the insert key cc (lower case) replace S (uppercase) in the entire row where the cursor is located with ss (lowercase). C (uppercase) is replaced with the end of the line, including c0 (lowercase, number 0) in the cursor) replace with the beginning of the line, excluding the characters c ^ (lower case) and c0 (lower case, number 0) at the cursor) 9. search for strings with the same effect. in command mode, search for strings starting from the cursor. in string mode, search for strings. in search mode, Press n (lower case) to find the next string. Press N (upper case) search for the last? String starts from the cursor and starts to look up the characters starting from string? In search mode, Click n (lower case) to find the previous one, and then click N (upper case) search for the next * completely match the word under the cursor # completely match the word under the cursor g * partially match the word under the cursor g # partially match the word under the cursor down to the word Editing mode: case-insensitive when searching for set ic: case-insensitive when canceling search for set noic: f string (lowercase f and string have spaces) searches for matching strings in a row: % s/old/new/g replace old with new in full text. if not, % s/old/new/c replace old with new in full text, prompting whether to replace n1, n2s/old/new/g n1-n2 line, replace old with new, do not prompt: n1, n2s/old/new/c n1-n2 line, replace old with new, if you are prompted whether to replace the old or new text with/characters, you need to use \ for escape 10 to display the line number Editing mode: set nu (mber) to display the line number: set nonu to cancel displaying the line number: set nu! Cancel line number 11 in simple typographical Editing mode: ce (nter) center show row of cursor: ri (ght) right show row of cursor: le (ft) show the cursor on the left. in command mode, J combines the next line of the cursor into the row where the cursor is located.> The line where the cursor is located adds indentation (a tab) <reduce indentation of the row where the cursor is located (one tab) n> n rows at the beginning of the row where the cursor is located increase indent n <n rows at the beginning of the row where the cursor is located decrease indent 12 bookmarks command mode mx sets bookmarks, x is any letter, generally, when lowercase letters (a-z) and x are lowercase letters, they are limited to switching between files. when uppercase letters are used, they can be switched between files. 'X ('next to number key 1) jump to bookmarks x edit mode: marks view tags 13 cursor move mode command mode H (uppercase, Head) move the first non-white space character M (uppercase, Mid) to the top of the screen and move it to the first non-white space character L (uppercase, Last) in the middle of the screen) move the first non-blank character (left parentheses) at the bottom of the screen to the beginning of the previous sentence) (right parentheses) to the next sentence Sub-heads {(left braces) move to the beginning of the previous paragraph} (right braces) move to the beginning of the next paragraph % cursor jump to match to the brackets, support {}() [The cursor jumps to the beginning of the code block, that is, the {Place, requires that the {Exclusive line gD cursor jump to the local variable definition ''(two single quotes) the cursor jumps to the last dock h (lower case) move the cursor one character to the left, equivalent to the left arrow key l (lower case) move the cursor one character to the right, equivalent to the right arrow key k (lower case) move the cursor up a line vertically, equivalent to the upper arrow key j (lower case) move the cursor down a line vertically, equivalent to ctrl + f (forword) down the entire page flip ctrl + B (backward) up the entire page flip ctrl + u (up) up half page ctrl + d (down) down half page zz (lower case) place the cursor row in the center of the screen zt (lower case) place the cursor row in the top of the screen zb (lower case) place the row where the cursor is located in the editing mode at the bottom of the screen: n specifies to move to the number prefix of Line 14 on line n and add the number before the command in repeated command mode, marking the number of times the command is processed, for example, 5dd indicates 5 executions Dd (delete the entire row where the cursor is located) operation .. (English period) refers to the command repetition command, and the command that was last executed once is pressed. 15 browsing directory Editing mode: e directory listing files and directories under a specified directory 16 vim Tips 1 import files or shell command execution result Editing mode: r file name 1 introduces file 1 to this file :! Run the shell command in vim. after the command is executed, press enter to go to the vim interface: r! Shell commands (r and! There is a space between them) import the result of shell command execution to this file. Tip 2: Customize the shortcut key operation in edit mode: map ^ x command (there is a space between map and ^, and between x and the command. here to ^ is not the ^ on the keyboard, but press ctrl + v to display the shortcut key, which indicates the ctrl key, press ctrl + x to execute the command example: map ^ p I # When you press ctrl + p, add a # sign at the beginning of the line where the cursor is located, and return to command mode tip 3 continuous line comment Editing mode: n1, n2/^/#/g (# indicates the annotation symbol. in shell, the annotation symbol is #, and in C ++, it is //): n1, n2/^/\/g C ++ source file multi-row continuous annotation technique 4 Replace: AB string1 string2 input string1 in vim and press space or press enter, string1 will be automatically replaced with string2: unab string1 to cancel replacing the vim configuration file of string1 ~ /. Vimrc can write the commands in editing mode, and each command is a single line, so that the commands will be automatically executed at each startup.
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.