📄 change.txt
字号:
*gp*["x]gp Just like "p", but leave the cursor just after the new text. {not in Vi} *gP*["x]gP Just like "P", but leave the cursor just after the new text. {not in Vi} *:pu* *:put*:[line]pu[t] [x] Put the text [from register x] after [line] (default current line). The register can also be '=' followed by an optional expression. The expression continues until the end of the command. You need to escape the '|' and '"' characters to prevent them from terminating the command. Example:> :put ='path' . \",/test\" If there is no expression after '=', Vim uses the previous expression. You can see it with ":dis =".:[line]pu[t]! [x] Put the text [from register x] before [line] (default current line).["x]]p or *]p* *]<MiddleMouse>*["x]]<MiddleMouse> Like "p", but adjust the indent to the current line. Using the mouse only works when 'mouse' contains 'n' or 'a'. {not in Vi}["x][P or *[P*["x]]P or *]P*["x][p or *[p* *[<MiddleMouse>*["x][<MiddleMouse> Like "P", but adjust the indent to the current line. Using the mouse only works when 'mouse' contains 'n' or 'a'. {not in Vi}You can use these commands to copy text from one place to another. Do thisby first getting the text into a register with a yank, delete or changecommand, then inserting the register contents with a put command. You canalso use these commands to move text from one file to another, because Vimpreserves all registers when changing buffers (the CTRL-^ command is a quickway to toggle between two files). *linewise-register* *characterwise-register*You can repeat the put commands with "." (except for :put) and undo them. Ifthe command that was used to get the text into the register was linewise, Viminserts the text below ("p") or above ("P") the line where the cursor is.Otherwise Vim inserts the text after ("p") or before ("P") the cursor. Withthe ":put" command, Vim always inserts the text in the next line. You canexchange two characters with the command sequence "xp". You can exchange twolines with the command sequence "ddp". You can exchange two words with thecommand sequence "deep" (start with the cursor in the blank space before thefirst word). You can use the "']" or "`]" command after the put command tomove the cursor to the end of the inserted text, or use "'[" or "`[" to movethe cursor to the start. *blockwise-register*If you use a blockwise Visual mode command to get the text into the register,the block of text will be inserted before ("P") or after ("p") the cursorcolumn in the current and next lines. Vim makes the whole block of text startin the same column. Thus the inserted text looks the same as when it wasyanked or deleted. Vim may replace some <Tab> characters with spaces to makethis happen. However, if the width of the block is not a multiple of a <Tab>width and the text after the inserted block contains <Tab>s, that text may bemisaligned.Note that after a yank command, Vim leaves the cursor on the first yankedcharacter that is closest to the start of the buffer. This means that "yl"doesn't move the cursor, but "yh" moves the cursor one character left.Rationale: In Vi the "y" command followed by a backwards motion would sometimes not move the cursor to the first yanked character, because redisplaying was skipped. In Vim it always moves to the first character, as specified by Posix.There are nine types of registers: *registers*1. The unnamed register ""2. 10 numbered registers "0 to "93. The small delete register "-4. 26 named registers "a to "z or "A to "Z5. four read-only registers ":, "., "% and "#6. the expression register "=7. The selection register "*8. The black hole register "_9. Last search pattern register "/1. Unnamed register "" *quote_quote* *quotequote*Vim fills this register with text deleted with the "d", "c", "s", "x" commandsor copied with the yank "y" command, regardless of whether or not a specificregister was used (e.g. "xdd). An exception is the '_' register: "_dd doesnot store the deleted text in any register. Vim uses the contents of thisregister for any put command (p or P) which does not specify a register.Additionally you can access it with the name '"'. This means you have to typetwo double quotes. {Vi: register contents are lost when changing files, no'"'}2. Numbered registers "0 to "9 *quote_number* *quote0* *quote1* *quote2* *quote3* *quote4* *quote9*Vim fills these registers with text from yank and delete commands. Numberedregister 0 contains the text from the most recent yank command, unless thecommand specified another register with ["x]. Numbered register 1 containsthe text deleted by the most recent delete or change command, unless thecommand specified another register or the text is less than one line (Vim putstext deleted with "x" or "dw" in the small delete register). With eachsuccessive deletion or change, Vim shifts the previous contents of register 1into register 2, 2 into 3, and so forth, losing the previous contents ofregister 9. {Vi: numbered register contents are lost when changing files;register 0 does not exist}3. Small delete register "- *quote_-* *quote-*This register contains text from commands that delete less than one line,except when the command specifies a register with ["x].{not in Vi}4. Named registers "a to "z or "A to "Z *quote_alpha* *quotea*Vim fills these registers only when you say so. Specify them as lowercaseletters to replace their previous contents or as uppercase letters to appendto their previous contents.5. Read-only registers ":, "., "% and "#These are '%', '#', ':' and '.'. You can use them only with the "p", "P",and ":put" commands and with CTRL-R. {not in Vi} *quote_.* *quote.* ". Contains the last inserted text (the same as what is inserted with the insert mode commands CTRL-A and CTRL-@). Note: this doesn't work with CTRL-R on the command-line. It works a bit differently, like inserting the text instead of putting it ('textwidth' and other options affect what is inserted). *quote_%* *quote%* "% Contains the name of the current file. *quote_#* *quote#* "# Contains the name of the alternate file. *quote_:* *quote:* ": Contains the most recent executed command-line. Example: Use "@:" to repeat the previous command-line command. The command-line is only stored in this register when at least one character of it was typed. Thus it remains unchanged if the command was completely from a mapping.6. Expression register "= *quote_=* *quote=*This is not really a register that stores text, but is a way to use anexpression in commands which use a register. The expression register isread-only; you cannot put text into it. After the '=', the cursor moves tothe command-line, where you can enter any expression (see |expression|). Allnormal command-line editing commands are available, including a specialhistory for expressions. When you end the command-line by typing <CR>, Vimcomputes the result of the expression. If you end it with <Esc>, Vim abandonsthe expression. If you do not enter an expression, Vim uses the previousexpression (like with the "/" command). If the "= register is used for the"p" command, the string is split up at <NL> characters. If the string ends ina <NL>, it is regarded as a linewise register. {not in Vi}7. Selection register "*Use this register for storing and retrieving the selected text for the GUI.See |quotestar|. When the clipboard is not available or not working, theunnamed register is used instead. {not in Vi}8. Black hole register "_ *quote_*When writing to this register, nothing happens. This can be used to deletetext without affecting the normal registers. When reading from this register,nothing is returned. {not in Vi}9. Last search pattern register "/ *quote_/* *quote/*Contains the most recent search-pattern. This is used for "n" and 'hlsearch'.It is read-only. {not in Vi} *@/*You can write to a register with a ":let" command |:let-@|. Example:> :let @/ = "the"If you use a put command without specifying a register, Vim uses the registerthat was last filled (this is also the contents of the unnamed register). Ifyou are confused, use the ":dis" command to find out what Vim will put (thiscommand displays all named and numbered registers; the unnamed register islabelled '"').The next three commands always work on whole lines.:[range]co[py] {address} *:co* *:copy* Copy the lines given by [range] to below the line given by {address}. *:t*:t Synonym for copy.:[range]m[ove] {address} *:m* *:mo* *:move* Move the lines given by [range] to below the line given by {address}.==============================================================================6. Formatting text *formatting*:[range]ce[nter] [width] *:ce* *:center* Center lines in [range] between [width] columns (default 'textwidth' or 80 when 'textwidth' is 0). {not in Vi} Not available when |+ex_extra| feature was disabled at compile time.:[range]ri[ght] [width] *:ri* *:right* Right-align lines in [range] at [width] columns (default 'textwidth' or 80 when 'textwidth' is 0). {not in Vi} Not available when |+ex_extra| feature was disabled at compile time. *:le* *:left*:[range]le[ft] [indent] Left-align lines in [range]. Sets the indent in the lines to [indent] (default 0). {not in Vi} Not available when |+ex_extra| feature was disabled at compile time. *gq*gq{motion} Format the lines that {motion} moves over. The 'textwidth' option controls the length of each formatted line (see below). If the 'textwidth' option is 0, the formatted line length is the screen width (with a maximum width of 79). {not in Vi} The 'formatoptions' option controls the type of formatting |fo-table|. NOTE: The "Q" command formerly performed this function. If you still want to use "Q" for formatting, use this mapping:> :nnoremap Q gqgqgq *gqgq* *gqq*gqq Format the current line. {not in Vi} *v_gq*{Visual}gq Format the highlighted text. (for {Visual} see |Visual-mode|). {not in Vi}Example: To format the current paragraph use> gqapThe "gq" command leaves the cursor in the line where the motion command takesthe cursor. This allows you to repeat formatting repeated with ".". Thisworks well with "gqj" (format current and next line) and "gq}" (format untilend of paragraph). Note: When 'formatprg' is set, "gq" leaves the cursor onthe first formatted line (as with using a filter command).If the 'autoindent' option is on, Vim uses the indent of the first line forthe following lines.Formatting does not change empty lines (but it does change lines with onlywhite space!).The 'joinspaces' option is used when lines are joined together.You can set the 'formatprg' option to the name of an external program for Vimto use for text formatting. The 'textwidth' and other options have no effecton formatting by an external program. *right-justify*There is no command in Vim to right justify text. You can do it withan external command, like "par" (e.g.: "!}par" to format until the end of theparagraph) or set 'formatprg' to "par". *format-comments*Vim can format comments in a special way. Vim recognizes a comment by aspecific string at the start of the line (ignoring white space). Three typesof comments can be used:- A comment string that repeats at the start of each line. An example is the type of comment used in shell scripts, starting with "#".- A comment string that occurs only in the first line, not in the following lines. An example is this list with dashes.- Three-piece comments that have a start string, an end string, and optional lines in between. The strings for the start, middle and end are different. An example is the C-style comment: /* * this is a C comment */The 'comments' option is a comma-separated list of parts. Each part defines atype of comment string. A part consists of: {flags}:{string}{string} is the literal text that must appear.{flags}: n Nested comment. Nesting with mixed parts is allowed. If 'comments' is "n:),n:>" a line starting with "> ) >" is a comment. b Blank (<Space>, <Tab> or <EOL>) required after {string}. f Only the first line has the comment string. Do not repeat comment on the next line, but preserve indentation (e.g., a bullet-list). s Start of three-piece comment m Middle of a three-piece comment e End of a three-piece comment l Left adjust middle with start or end (default). Only recognized when used together with 's' or 'e'. r Right adjust middle with start or end. Only recognized when used together with 's' or 'e'. x Allows three-piece comments to be ended by just typing the last character of the end-comment string as the first character on a new line, when the middle-comment string has already been inserted automatically. See below for more details. {digits} When together with 's' or 'e': add extra indent for the middle part. This can be used to left-align the middle part with the start or end and then add an offset. -{digits} Like {digits} but reduce the indent. This only works when there is some indent for the start or end part that can be removed.When a string has none of the 'f', 's', 'm' or 'e' flags, Vim assumes thecomment string repeats at the start of each line. The flags field may beempty.Any blank space in the text before and after the {string} is part of the{string}, so do not include leading or trailing blanks unless the blanks are arequired part of the comment string.When one comment leader is part of another, specify the part after the whole.For example, to include both "-" and "->", use> :set comments=f:->,f:-A three-piece comment must always be given as start,middle,end, with no otherparts in between. An example of a three-piece comment is> sr:/*,mb:*,ex:*/for C-comments. To avoid recognizing "*ptr" as a comment, the middle stringincludes the 'b' flag. For three-piece comments, Vim checks the text afterthe start and middle strings for the end string. If Vim finds the end string,the comment does not continue on the next line. Three-piece comments musthave a middle string because otherwise Vim can't recognize the middle lines.Notice the use of the "x" flag in the above three-piece comment definition.When you hit Return in a C-comment, Vim will insert the middle comment leaderfor the new line, eg " * ". To close this comment you just have to type "/"before typing anything else on the new line. This will replace themiddle-comment leader with the end-comment leader, leaving just " */". Thereis no need to hit BackSpace first.Examples:> "b:*" Includes lines starting with "*", but not if the "*" is> followed by a non-blank. This avoids a pointer dereference> like "*str" to be recognized as a comment.> "n:>" Includes a line starting with ">", ">>", ">>>", etc.> "fb:-" Format a list that starts with "- ".By default, "b:#" is included. This means that a line that starts with"#include" is not recognized as a comment line. But a line that starts with"# define" is recognized. This is a compromise.Often the alignment can be changed from right alignment to a left alignmentwith an additional space. For example, for Javadoc comments, this can beused (insert a backslash before the space when using ":set"):> s1:/*,mb:*,ex:*/Note that an offset is included with start, so that the middle part is leftaligned with the start and then an offset of one character added. This makesit possible to left align the start and middle for this construction:> /**> * comment> */{not available when compiled without the |+comments| feature} *fo-table*You can use the 'formatoptions' option to influence how Vim formats text.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -