📄 change.txt
字号:
*change.txt* For Vim version 5.8. Last change: 2001 Jan 04 VIM REFERENCE MANUAL by Bram MoolenaarThis file describes commands that delete or change text. In this context,changing text means deleting the text and replacing it with other text usingone command. You can undo all of these commands. You can repeat the non-Excommands with the "." command.1. Deleting text |deleting|2. Delete and insert |delete-insert|3. Simple changes |simple-change| *changing*4. Complex changes |complex-change|5. Copying and moving text |copy-move|6. Formatting text |formatting|7. Indenting C programs |C-indenting|For inserting text see |insert.txt|.==============================================================================1. Deleting text *deleting*["x]<Del> or *<Del>* *x* *dl*["x]x Delete [count] characters under and after the cursor [into register x] (not linewise). Does the same as "dl". See |:fixdel| if the <Del> key does not do what you want. See |'whichwrap'| for deleting the <EOL> (join lines). {Vi does not support <Del>} *X* *dh*["x]X Delete [count] characters before the cursor [into register x] (not linewise). Does the same as "dh". Also see |'whichwrap'|. *d*["x]d{motion} Delete text that {motion} moves over [into register x]. See below for exceptions. *dd*["x]dd Delete [count] lines [into register x] (linewise). *D*["x]D Delete the characters under the cursor until the end of the line and [count]-1 more lines [into register x]; synonym for d$ (not linewise).{Visual}["x]x or *v_x* *v_d*{Visual}["x]d Delete the highlighted text [into register x] (for {Visual} see |Visual-mode|). {not in Vi}{Visual}["x]CTRL-H or *v_CTRL-H* *v_<BS>*{Visual}["x]<BS> When in Select mode: Delete the highlighted text [into register x].{Visual}["x]X or *v_X* *v_D* *v_b_D*{Visual}["x]D Delete the highlighted lines [into register x] (for {Visual} see |Visual-mode|). In Visual block mode, "D" deletes the highlighted text plus all text until the end of the line. {not in Vi} *:d* *:de* *:del* *:delete*:[range]d[elete] [x] Delete [range] lines (default: current line) [into register x].:[range]d[elete] [x] {count} Delete {count} lines, starting with [range] (default: current line |cmdline-ranges|) [into register x].These commands delete text. You can repeat them with the "." command(except ":d") and undo them. Use Visual mode to delete blocks of text. See|registers| for an explanation of registers.An exception for the d{motion} command: If the motion is not linewise, thestart and end of the motion are not in the same line, and there are onlyblanks before the start and after the end of the motion, the delete becomeslinewise. This means that the delete also removes the line of blanks that youmight expect to remain.Trying to delete an empty region of text (e.g., "d0" in the first column)is an error when 'cpoptions' includes the 'E' flag. *J*J Join [count] lines, with a minimum of two lines. Remove the indent and insert up to two spaces (see below). *v_J*{Visual}J Join the highlighted lines, with a minimum of two lines. Remove the indent and insert up to two spaces (see below). {not in Vi} *gJ*gJ Join [count] lines, with a minimum of two lines. Don't insert or remove any spaces. {not in Vi} *v_gJ*{Visual}gJ Join the highlighted lines, with a minimum of two lines. Don't insert or remove any spaces. {not in Vi} *:j* *:join*:[range]j[oin][!] Join [range] lines. Same as "J", except with [!] the join does not insert or delete any spaces. If a [range] has equal start and end values, this command does nothing. The default behavior is to join the current line with the line below it. {not in Vi: !}:[range]j[oin][!] {count} Join {count} lines, starting with [range] (default: current line |cmdline-ranges|). Same as "J", except with [!] the join does not insert or delete any spaces. {not in Vi: !}These commands delete the <EOL> between lines. This has the effect of joiningmultiple lines into one line. You can repeat these commands (except ":j") andundo them.These commands, except "gJ", insert one space in place of the <EOL> unlessthere is trailing white space or the next line starts with a ')'. Thesecommands, except "gJ", delete any leading white space on the next line. Ifthe 'joinspaces' option is on, these commands insert two spaces after a '.','!' or '?' (but if 'cpoptions' includes the 'j' flag, they insert two spacesonly after a '.').==============================================================================2. Delete and insert *delete-insert* *replacing* *R*R Enter Replace mode: Each character you type replaces an existing character, starting with the character under the cursor. Repeat the entered text [count]-1 times. See |Replace-mode| for more details. *gR*gR Enter Virtual replace mode: Each character you type replaces existing characters in screen space. So a <Tab> may replace several characters at once. Repeat the entered text [count]-1 times. See |Virtual-replace-mode| for more details. *c*["x]c{motion} Delete {motion} text [into register x] and start insert. When 'cpoptions' includes the 'E' flag and there is no text to delete (e.g., with "cTx" when the cursor is just after an 'x'), an error occurs and insert mode does not start (this is Vi compatible). When 'cpoptions' does not include the 'E' flag, the "c" command always starts insert mode, even if there is no text to delete. *cc*["x]cc Delete [count] lines [into register x] and start insert (linewise). If 'autoindent' is on, preserve the indent of the first line. *C*["x]C Delete from the cursor position to the end of the line and [count]-1 more lines [into register x], and start insert. Synonym for c$ (not linewise). *s*["x]s Delete [count] characters [into register x] and start insert (s stands for Substitute). Synonym for "cl" (not linewise). *S*["x]S Delete [count] lines [into register x] and start insert. Synonym for "cc" (linewise).{Visual}["x]c or *v_c* *v_s*{Visual}["x]s Delete the highlighted text [into register x] and start insert (for {Visual} see |Visual-mode|). {not in Vi} *v_r* {Visual}["x]r Doesn't work yet, it's supposed to replace all selected characters by the next typed character.{Visual}["x]C or{Visual}["x]S or *v_C* *v_R* *v_S*{Visual}["x]R Delete the highlighted lines [into register x] and start insert (for {Visual} see |Visual-mode|). {not in Vi}Notes:- You can end Insert and Replace mode with <Esc>.- See the section "Insert and Replace mode" |mode-ins-repl| for the other special characters in these modes.- The effect of [count] takes place after Vim exits Insert or Replace mode.- When the 'cpoptions' option contains '$' and the change is within one line, Vim continues to show the text to be deleted and puts a '$' at the last deleted character.See |registers| for an explanation of registers.Replace mode is just like Insert mode, except that every character you enterdeletes one character. If you reach the end of a line, Vim appends anyfurther characters (just like Insert mode). In Replace mode, the backspacekey restores the original text (if there was any). (See section "Insert andReplace mode" |mode-ins-repl|). *cw* *cW*Special case: "cw" and "cW" work the same as "ce" and "cE" if the cursor ison a non-blank. This is because Vim interprets "cw" as change-word, and aword does not include the following white space. {Vi: "cw" when on a blankfollowed by other blanks changes only the first blank; this is probably abug, because "dw" deletes all the blanks; use the 'w' flag in 'cpoptions' tomake it work like Vi anyway}If you prefer "cw" to include the space after a word, use this mapping:> :map cw dwi *:c* *:ch* *:change*:{range}c[hange] Replace lines of text with some different text. Type a line containing only "." to stop replacing. Without {range}, this command changes only the current line.==============================================================================3. Simple changes *simple-change* *r*r{char} Replace the character under the cursor with {char}. If {char} is a <CR> or <NL>, a line break replaces the character. To replace with a real <CR>, use CTRL-V <CR>. CTRL-V <NL> replaces with a <Nul>. {Vi: CTRL-V <CR> still replaces with a line break, cannot replace something with a <CR>} If you give a [count], Vim replaces [count] characters with [count] {char}s. When {char} is a <CR> or <NL>, however, Vim inserts only one <CR>: "5r<CR>" replaces five characters with a single line break. When {char} is a <CR> or <NL>, Vim performs autoindenting. This works just like deleting the characters that are replaced and then doing "i<CR><Esc>". *gr*gr{char} Replace the virtual characters under the cursor with {char}. This replaces in screen space, not file space. See |gR| and |Virtual-replace-mode| for more details. As with |r| a count may be given. *case* *locale* *$LANG*The following commands change the case of letters. The currently activelocale is used. This depends on your system On Unix, setting the $LANGenvironment variable can make a difference. For example, to enable changingthe case of letters with umlauts:> setenv LANG de *~*~ 'notildeop' option: Switch case of the character under the cursor and move the cursor to the right. If a [count] is given, do that many characters. {Vi: no count}~{motion} 'tildeop' option: switch case of {motion} text. {Vi: tilde cannot be used as an operator} *g~*g~{motion} Switch case of {motion} text. {not in Vi}g~g~ *g~g~* *g~~*g~~ Switch case of current line. {not in Vi}. *v_~*{Visual}~ Switch case of highlighted text (for {Visual} see |Visual-mode|). {not in Vi} *v_U*{Visual}U Make highlighted text uppercase (for {Visual} see |Visual-mode|). {not in Vi} *gU* *uppercase*gU{motion} Make {motion} text uppercase. {not in Vi} Example:> :map! <C-F> <Esc>gUiw`]a This works in Insert mode: press CTRL-F to make the before the cursor upper case. Handy to type words in lower case and then make them uppercase.gUgU *gUgU* *gUU*gUU Make current line uppercase. {not in Vi}. *v_u*{Visual}u Make highlighted text lowercase (for {Visual} see |Visual-mode|). {not in Vi} *gu* *lowercase*gu{motion} Make {motion} text lowercase. {not in Vi}gugu *gugu* *guu*guu Make current line lowercase. {not in Vi}. *g?* *rot13*g?{motion} Rot13 encode {motion} text. {not in Vi} *v_g?*{Visual}g? Rot13 encode the highlighted text (for {Visual} see |Visual-mode|). {not in Vi}g?g? *g?g?* *g??*g?? Rot13 encode current line. {not in Vi}.Adding and subtracting ~ *CTRL-A*CTRL-A Add [count] to the number at or after the cursor. {not in Vi} *CTRL-X*CTRL-X Subtract [count] from the number at or after the cursor. {not in Vi}The CTRL-A and CTRL-X commands work for (signed) decimal numbers andunsigned octal and hexadecimal numbers. This depends on the 'nrformats'option.- When 'nrformats' includes "hex", Vim assumes numbers starting with '0x' or '0X' are hexadecimal. The case of the rightmost letter in the number determines the case of the resulting hexadecimal number. If there is no letter in the current number, Vim uses the previously detected case.- When 'nrformats' includes "octal", Vim considers numbers starting with a '0' to be octal. Other numbers are decimal and may have a preceding minus sign. If the cursor is on a number, the commands apply to that number; otherwise Vim uses the number to the right of the cursor.For numbers with leading zeros (including all octal and hexadecimal numbers),Vim preserves the number of characters in the number when possible. CTRL-A on"0077" results in "0100", CTRL-X on "0x100" results in "0x0ff". Note thatwhen 'nrformats' includes "octal", decimal numbers with leading zeros areimpossible because they are indistinguishable from octal numbers.The CTRL-A command is very useful in a macro. Example: Use the followingsteps to make a numbered list.1. Create the first list entry, make sure it starts with a number.2. qa - start recording into buffer 'a'3. Y - yank the entry4. p - put a copy of the entry below the first one5. CTRL-A - increment the number6. q - stop recording7. <count>@a - repeat the yank, put and increment <count> timesSHIFTING LINES LEFT OR RIGHT *shift-left-right* *<*<{motion} Shift {motion} lines one 'shiftwidth' leftwards. *<<*<< Shift [count] lines one 'shiftwidth' leftwards. *v_<*{Visual}[count]< Shift the highlighted lines [count] 'shiftwidth' leftwards (for {Visual} see |Visual-mode|). {not in Vi} *>* >{motion} Shift {motion} lines one 'shiftwidth' rightwards. *>>* >> Shift [count] lines one 'shiftwidth' rightwards.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -