Common Vim commands and usage

Source: Internet
Author: User

Common Vim commands and usage 1 switch insert mode: In command mode, insert the (lower case) cursor and then insert the (upper case) cursor at the end of the line to insert the I (lower case) insert I (uppercase) before the cursor start insert I (uppercase) insert o (lowercase) at the beginning of the row where the cursor is located Insert a new empty line insert O (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 # <ESC> when you press ctrl + p shortcut keys, add a # sign at the beginning of the line where the cursor is located, and return to command mode Tip 3 in continuous line comment editing mode: n1, n2/^/#/g (# Is the annotation symbol, in shell, the annotation symbol is #, C ++ is/): n1, n2/^/\/g C ++ source file multiple-line Continuous annotation technique 4 replace: after AB string1 string2 is entered in vim and string1 is pressed by 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.