📄 cmdline.txt
字号:
*cmdline.txt* For Vim version 5.8. Last change: 2000 Nov 16 VIM REFERENCE MANUAL by Bram Moolenaar *Cmdline-mode* *Command-line-mode*Command-line mode *Cmdline* *Command-line* *mode-cmdline* *:*Command-line mode is used to enter Ex commands (":"), search patterns("/" and "?"), and filter commands ("!").1. Command-line editing |cmdline-editing|2. Command-line completion |cmdline-completion|3. Ex command-lines |cmdline-lines|4. Ex command-line ranges |cmdline-ranges|5. Ex special characters |cmdline-special|==============================================================================1. Command-line editing *cmdline-editing*Normally characters are inserted in front of the cursor position. You canmove around in the command-line with the left and right cursor keys. With the<Insert> key, you can toggle between inserting and overstriking characters.{Vi: can only alter the last character in the line}Note that if your keyboard does not have working cursor keys or any of theother special keys, you can use ":cnoremap" to define another key for them.For example, to define tcsh style editing keys: *tcsh-style*> :cnoremap <C-A> <Home>> :cnoremap <C-F> <Right>> :cnoremap <C-B> <Left>> :cnoremap <Esc>b <S-Left>> :cnoremap <Esc>f <S-Right>(<> notation |<>|; type all this literally) *cmdline-too-long*When the command line is getting longer than what fits on the screen, only thepart that fits will be shown. The cursor can only move in this visible part,thus you cannot edit beyond that. *cmdline-history*The command-lines that you enter are remembered in a history table. You canrecall them with the up and down cursor keys. There are actually fourhistory tables:- one for ':' commands- one for search strings- one for expressions- one for input lines, typed for the |input()| function.These are completely separate. Each history can only be accessed whenentering the same type of line.Use the 'history' option to set the number of lines that are remembered(default: 20).Notes:- When you enter a command-line that is exactly the same as an older one, the old one is removed (to avoid repeated commands moving older commands out of the history).- Only commands that are typed are remembered. Ones that completely come from mappings are not put in the history- All searches are put in the search history, including the ones that come from commands like "*" and "#". But for a mapping, only the last search is remembered (to avoid that long mappings trash the history).{Vi: no history}There is an automatic completion of names on the command-line; see|cmdline-completion|. *c_CTRL-V*CTRL-V Insert next non-digit literally. Up to three digits form the decimal value of a single byte. The non-digit and the three digits are not considered for mapping. This works the same way as in Insert mode (see above, |i_CTRL-V|). Note: Under Windows CTRL-V is often mapped to paste text. Use CTRL-Q instead then. *c_CTRL-Q*CTRL-Q Same as CTRL-V. *c_<Left>*<Left> cursor left *c_<Right>*<Right> cursor right *c_<S-Left>*<S-Left> or <C-Left> *c_<C-Left>* cursor one WORD left *c_<S-Right>*<S-Right> or <C-Right> *c_<C-Right>* cursor one WORD rightCTRL-B or <Home> *c_CTRL-B* *c_<Home>* cursor to beginning of command-lineCTRL-E or <End> *c_CTRL-E* *c_<End>* cursor to end of command-line *c_<LeftMouse>*<LeftMouse> cursor to position of mouse click.CTRL-H *c_<BS>* *c_CTRL-H*<BS> delete the character in front of the cursor (see |:fixdel| if your <BS> key does not do what you want). *c_<Del>*<Del> delete the character under the cursor (at end of line: character before the cursor) (see |:fixdel| if your <Del> key does not do what you want). *c_CTRL-W*CTRL-W delete the word before the cursor *c_CTRL-U*CTRL-U remove all characters Note: if the command-line becomes empty with one of the delete commands, Command-line mode is quit. *c_<Insert>*<Insert> Toggle between insert and overstrike. {not in Vi}{char1} <BS> {char2} or *c_digraph*CTRL-K {char1} {char2} *c_CTRL-K* enter digraph (see |digraphs|). When {char1} is a special key, the code for that key is inserted in <> form. {not in Vi}CTRL-R {0-9a-z"%#:-=.} *c_CTRL-R* *c_<C-R>* Insert the contents of a numbered or named register. Between typing CTRL-R and the second character '"' will be displayed to indicate that you are expected to enter the name of a register. The text is inserted as if you typed it, but mappings and abbreviations are not used. Characters that end the command line are inserted literally (<Esc>, <CR>, <NL>, <C-C>). A <BS> or CTRL-W could still end the command line though, and remaining characters will then be interpreted in another mode, which might not be what you intended. Special registers: '"' the unnamed register, containing the text of the last delete or yank '%' the current file name '#' the alternate file name '*' the clipboard contents '/' the last search pattern ':' the last command-line '-' the last small (less than a line) delete '.' the last inserted text '=' the expression register: you are prompted to enter an expression (see |expression|) See |registers| about registers. {not in Vi}CTRL-R CTRL-FCTRL-R CTRL-PCTRL-R CTRL-WCTRL-R CTRL-A Insert the object under the cursor: CTRL-F the Filename under the cursor CTRL-P the Filename under the cursor, expanded with 'path' as in |gf| CTRL-W the Word under the cursor CTRL-A the WORD under the cursor; see |WORD| {not in Vi} CTRL-F and CTRL-P: {only when +file_in_path feature is included} *c_CTRL-R_CTRL-R* *c_<C-R>_<C-R>*CTRL-R CTRL-R {0-9a-z"%#:-=. CTRL-F CTRL-P CTRL-W CTRL-A} Insert register or object under the cursor. Works like |c_CTRL-R| but inserts the text literally. For example, if register a contains "xy^Hz" (where ^H is a backspace), "CTRL-R a" will insert "xz" while "CTRL-R CTRL-R a" will insert "xy^Hz".CTRL-J *c_CTRL-J* *c_<NL>* *c_<CR>*<CR> or <NL> start entered command *c_<Esc>*<Esc> When typed and 'x' not present in 'cpoptions', quit Command-line mode without executing. In macros or when 'x' present in 'cpoptions', start entered command. *c_CTRL-C*CTRL-C quit command-line without executing *c_<Up>*<Up> recall older command-line from history, whose beginning matches the current command-line (see below). *c_<Down>*<Down> recall more recent command-line from history, whose beginning matches the current command-line (see below). *c_<S-Up>* *c_<PageUp>*<S-Up> or <PageUp> recall older command-line from history *c_<S-Down>* *c_<PageDown>*<S-Down> or <PageDown> recall more recent command-line from historyCTRL-D command-line completion (see |cmdline-completion|)'wildchar' option command-line completion (see |cmdline-completion|)CTRL-N command-line completion (see |cmdline-completion|)CTRL-P command-line completion (see |cmdline-completion|)CTRL-A command-line completion (see |cmdline-completion|)CTRL-L command-line completion (see |cmdline-completion|) *c_CTRL-_*CTRL-_ a - switch between Hebrew and English keyboard mode, which is private to the command-line and not related to hkmap. This is useful when Hebrew text entry is required in the command-line, searches, abbreviations, etc. Applies only if Vim is compiled with the |+rightleft| feature and the 'allowrevins' option is set. See |rightleft.txt|. b - switch between Farsi and English keyboard mode, which is private to the command-line and not related to fkmap. In Farsi keyboard mode the characters are inserted in reverse insert manner. This is useful when Farsi text entry is required in the command-line, searches, abbreviations, etc. Applies only if Vim is compiled with the |+farsi| feature. See |farsi.txt|.The <Up> and <Down> keys take the current command-line as a search string.The beginning of the next/previous command-lines are compared with thisstring. The first line that matches is the new command-line. When typingthese two keys repeatedly, the same string is used again. For example, thiscan be used to find the previous substitute command: Type ":s" and then <Up>.The same could be done by typing <S-Up> a number of times until the desiredcommand-line is shown. (Note: the shifted arrow keys do not work on allterminals) *his* *:history*:his[tory] Print the history of last entered commands. {not in Vi}:his[tory] [{name}] [{first}][, [{last}]] List the contents of history {name} which can be: c[md] or : command-line history s[earch] or / search string history e[xpr] or = expression register history i[nput] or @ input line history a[ll] all of the above {not in Vi} If the numbers {first} and/or {last} are given, the respective range of entries from a history is listed. These numbers can be specified in the following form: *:history-indexing* A positive number represents the absolute index of an entry as it is given in the first column of a :history listing. This number remains fixed even if other entries are deleted. A negative number means the relative position of an entry, counted from the newest entry (which has index -1) backwards. Examples: List entries 6 to 12 from the search history:> :history / 6,12 List the recent five entries from all histories:> :history all -5,==============================================================================2. Command-line completion *cmdline-completion*When editing the command-line, a few commands can be used to complete theword before the cursor. This is available for:- Command names: At the start of the command-line.- Tags: Only after the ":tag" command.- File names: Only after a command that accepts a file name or a setting for an option that can be set to a file name. This is called file name completion.- Options: Only after the ":set" command.- Mappings: Only after a ":map" or similar command.- Variable and function names: Only after a ":if", ":call" or similar command.When Vim was compiled with the |+cmdline_compl| feature disabled, only filenames, directories and help items can be completed.These are the commands that can be used: *c_CTRL-D*CTRL-D List names that match the pattern in front of the cursor. When showing file names, directories are highlighted (see 'highlight' option). Names where 'suffixes' matches are moved to the end. *c_CTRL-I* *c_wildchar* *c_<Tab>*'wildchar' option A match is done on the pattern in front of the cursor. The match (if there are several, the first match) is inserted in place of the pattern. (Note: does not work inside a macro, because <Tab> or <Esc> are mostly used as 'wildchar', and these have a special meaning in some macros.) When typed again and there were multiple matches, the next match is inserted. After the last match, the first is used again (wrap around). The behavior can be changed with the 'wildmode' option. *c_CTRL-N*CTRL-N After using 'wildchar' which got multiple matches, go to next match. Otherwise recall more recent command-line from history.<S-Tab> *c_CTRL-P* *c_<S-Tab>*CTRL-P After using 'wildchar' which got multiple matches, go to previous match. Otherwise recall older command-line from history. <S-Tab> only works with the GUI, on the Amiga and with MS-DOS. *c_CTRL-A*CTRL-A All names that match the pattern in front of the cursor are inserted. *c_CTRL-L*CTRL-L A match is done on the pattern in front of the cursor. If there is one match, it is inserted in place of the pattern. If there are multiple matches the longest common part is inserted in place of the pattern. If the result is shorter than the pattern, no completion is done.The 'wildchar' option defaults to <Tab> (CTRL-E when in Vi compatible mode; ina previous version <Esc> was used). In the pattern standard wildcards '*' and'?' are accepted. '*' matches any string, '?' matches exactly one character.If you like tcsh's autolist completion, you can use this mapping: :cnoremap X <C-L><C-D>(Where X is the command key to use, <C-L> is CTRL-L and <C-D> is CTRL-D)This will find the longest match and then list all matching files.If you like tcsh's autolist completion, you can use the 'wildmode' option toemulate it. For example, this mimics autolist=ambiguous: :set wildmode=longest,listThis will find the longest match with the first 'wildchar', then list allmatching files with the next. *suffixes*For file name completion you can use the 'suffixes' option to set a prioritybetween files with almost the same name. If there are multiple matches,those files with an extension that is in the 'suffixes' option are ignored.The default is ".bak,~,.o,.h,.info,.swp", which means that files ending in".bak", "~", ".o", ".h", ".info" and ".swp" are sometimes ignored. It isimpossible to ignore suffixes with two dots. Examples: pattern: files: match: ~ test* test.c test.h test.o test.c test* test.h test.o test.h and test.o test* test.i test.h test.c test.i and test.cIf there is more than one matching file (after ignoring the ones matchingthe 'suffixes' option) the first file name is inserted. You can see thatthere is only one match when you type 'wildchar' twice and the completedmatch stays the same. You can get to the other matches by entering'wildchar', CTRL-N or CTRL-P. All files are included, also the ones withextensions matching the 'suffixes' option.The old value of an option can be obtained by hitting 'wildchar' just afterthe '='. For example, typing 'wildchar' after ":set dir=" will insert thecurrent value of 'dir'. This overrules file name completion for the optionsthat take a file name.If you would like using <S-Tab> for CTRL-P in an xterm, put this command inyour .cshrc:> xmodmap -e "keysym Tab = Tab Find"And this in your .vimrc:> cmap <Esc>[1~ <C-P> (<C-P> is CTRL-P)==============================================================================3. Ex command-lines *cmdline-lines*The Ex commands have a few specialties: *:quote*'"' at the start of a line causes the whole line to be ignored. '"'after a command causes the rest of the line to be ignored. This can be usedto add comments. Example:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -