Bram Moolenaar | 10e8ff9 | 2023-06-10 21:40:39 +0100 | [diff] [blame] | 1 | *cmdline.txt* For Vim version 9.0. Last change: 2023 May 20 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2 | |
| 3 | |
| 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
| 5 | |
| 6 | |
| 7 | *Cmdline-mode* *Command-line-mode* |
| 8 | Command-line mode *Cmdline* *Command-line* *mode-cmdline* *:* |
| 9 | |
| 10 | Command-line mode is used to enter Ex commands (":"), search patterns |
| 11 | ("/" and "?"), and filter commands ("!"). |
| 12 | |
| 13 | Basic command line editing is explained in chapter 20 of the user manual |
| 14 | |usr_20.txt|. |
| 15 | |
| 16 | 1. Command-line editing |cmdline-editing| |
| 17 | 2. Command-line completion |cmdline-completion| |
| 18 | 3. Ex command-lines |cmdline-lines| |
| 19 | 4. Ex command-line ranges |cmdline-ranges| |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 20 | 5. Ex command-line flags |ex-flags| |
| 21 | 6. Ex special characters |cmdline-special| |
| 22 | 7. Command-line window |cmdline-window| |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 23 | |
| 24 | ============================================================================== |
| 25 | 1. Command-line editing *cmdline-editing* |
| 26 | |
| 27 | Normally characters are inserted in front of the cursor position. You can |
| 28 | move around in the command-line with the left and right cursor keys. With the |
| 29 | <Insert> key, you can toggle between inserting and overstriking characters. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 30 | |
| 31 | Note that if your keyboard does not have working cursor keys or any of the |
| 32 | other special keys, you can use ":cnoremap" to define another key for them. |
| 33 | For example, to define tcsh style editing keys: *tcsh-style* > |
| 34 | :cnoremap <C-A> <Home> |
| 35 | :cnoremap <C-F> <Right> |
| 36 | :cnoremap <C-B> <Left> |
| 37 | :cnoremap <Esc>b <S-Left> |
| 38 | :cnoremap <Esc>f <S-Right> |
| 39 | (<> notation |<>|; type all this literally) |
| 40 | |
| 41 | *cmdline-too-long* |
| 42 | When the command line is getting longer than what fits on the screen, only the |
| 43 | part that fits will be shown. The cursor can only move in this visible part, |
| 44 | thus you cannot edit beyond that. |
| 45 | |
| 46 | *cmdline-history* *history* |
| 47 | The command-lines that you enter are remembered in a history table. You can |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 48 | recall them with the up and down cursor keys. There are actually five |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 49 | history tables: |
| 50 | - one for ':' commands |
| 51 | - one for search strings |
| 52 | - one for expressions |
| 53 | - one for input lines, typed for the |input()| function. |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 54 | - one for debug mode commands |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 55 | These are completely separate. Each history can only be accessed when |
| 56 | entering the same type of line. |
| 57 | Use the 'history' option to set the number of lines that are remembered |
Bram Moolenaar | 6e93246 | 2014-09-09 18:48:09 +0200 | [diff] [blame] | 58 | (default: 50). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 59 | Notes: |
| 60 | - When you enter a command-line that is exactly the same as an older one, the |
| 61 | old one is removed (to avoid repeated commands moving older commands out of |
| 62 | the history). |
| 63 | - Only commands that are typed are remembered. Ones that completely come from |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 64 | mappings are not put in the history. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 65 | - All searches are put in the search history, including the ones that come |
| 66 | from commands like "*" and "#". But for a mapping, only the last search is |
| 67 | remembered (to avoid that long mappings trash the history). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 68 | {not available when compiled without the |+cmdline_hist| feature} |
| 69 | |
| 70 | There is an automatic completion of names on the command-line; see |
| 71 | |cmdline-completion|. |
| 72 | |
| 73 | *c_CTRL-V* |
| 74 | CTRL-V Insert next non-digit literally. Up to three digits form the |
| 75 | decimal value of a single byte. The non-digit and the three |
| 76 | digits are not considered for mapping. This works the same |
| 77 | way as in Insert mode (see above, |i_CTRL-V|). |
Bram Moolenaar | 6f345a1 | 2019-12-17 21:27:18 +0100 | [diff] [blame] | 78 | Note: Under MS-Windows CTRL-V is often mapped to paste text. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | Use CTRL-Q instead then. |
Bram Moolenaar | fc4ea2a | 2019-11-26 19:33:22 +0100 | [diff] [blame] | 80 | When |modifyOtherKeys| is enabled then special Escape sequence |
| 81 | is converted back to what it was without |modifyOtherKeys|, |
| 82 | unless the Shift key is also pressed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 83 | *c_CTRL-Q* |
| 84 | CTRL-Q Same as CTRL-V. But with some terminals it is used for |
| 85 | control flow, it doesn't work then. |
| 86 | |
Bram Moolenaar | fc4ea2a | 2019-11-26 19:33:22 +0100 | [diff] [blame] | 87 | CTRL-SHIFT-V *c_CTRL-SHIFT-V* *c_CTRL-SHIFT-Q* |
| 88 | CTRL-SHIFT-Q Works just like CTRL-V, unless |modifyOtherKeys| is active, |
| 89 | then it inserts the Escape sequence for a key with modifiers. |
zeertzjq | bad8a01 | 2022-04-29 16:44:00 +0100 | [diff] [blame] | 90 | In the GUI the |key-notation| is inserted without simplifying. |
Bram Moolenaar | fc4ea2a | 2019-11-26 19:33:22 +0100 | [diff] [blame] | 91 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 92 | *c_<Left>* *c_Left* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 93 | <Left> cursor left |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 94 | *c_<Right>* *c_Right* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | <Right> cursor right |
| 96 | *c_<S-Left>* |
| 97 | <S-Left> or <C-Left> *c_<C-Left>* |
| 98 | cursor one WORD left |
| 99 | *c_<S-Right>* |
| 100 | <S-Right> or <C-Right> *c_<C-Right>* |
| 101 | cursor one WORD right |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 102 | CTRL-B or <Home> *c_CTRL-B* *c_<Home>* *c_Home* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 103 | cursor to beginning of command-line |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 104 | CTRL-E or <End> *c_CTRL-E* *c_<End>* *c_End* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 105 | cursor to end of command-line |
| 106 | |
| 107 | *c_<LeftMouse>* |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 108 | <LeftMouse> Move the cursor to the position of the mouse click. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 109 | |
Bram Moolenaar | 256972a | 2015-12-29 19:10:25 +0100 | [diff] [blame] | 110 | *c_<MiddleMouse>* |
| 111 | <MiddleMouse> Paste the contents of the clipboard (for X11 the primary |
| 112 | selection). This is similar to using CTRL-R *, but no CR |
| 113 | characters are inserted between lines. |
| 114 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 115 | CTRL-H *c_<BS>* *c_CTRL-H* *c_BS* |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 116 | <BS> Delete the character in front of the cursor (see |:fixdel| if |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 117 | your <BS> key does not do what you want). |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 118 | *c_<Del>* *c_Del* |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 119 | <Del> Delete the character under the cursor (at end of line: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 120 | character before the cursor) (see |:fixdel| if your <Del> |
| 121 | key does not do what you want). |
| 122 | *c_CTRL-W* |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 123 | CTRL-W Delete the |word| before the cursor. This depends on the |
| 124 | 'iskeyword' option. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 125 | *c_CTRL-U* |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 126 | CTRL-U Remove all characters between the cursor position and |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 127 | the beginning of the line. Previous versions of vim |
| 128 | deleted all characters on the line. If that is the |
| 129 | preferred behavior, add the following to your .vimrc: > |
| 130 | :cnoremap <C-U> <C-E><C-U> |
| 131 | < |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 132 | *c_<Insert>* *c_Insert* |
Bram Moolenaar | 25c9c68 | 2019-05-05 18:13:34 +0200 | [diff] [blame] | 133 | <Insert> Toggle between insert and overstrike. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | |
| 135 | {char1} <BS> {char2} or *c_digraph* |
| 136 | CTRL-K {char1} {char2} *c_CTRL-K* |
| 137 | enter digraph (see |digraphs|). When {char1} is a special |
Bram Moolenaar | 25c9c68 | 2019-05-05 18:13:34 +0200 | [diff] [blame] | 138 | key, the code for that key is inserted in <> form. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 139 | |
Bram Moolenaar | 5be4cee | 2019-09-27 19:34:08 +0200 | [diff] [blame] | 140 | CTRL-R {register} *c_CTRL-R* *c_<C-R>* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 141 | Insert the contents of a numbered or named register. Between |
| 142 | typing CTRL-R and the second character '"' will be displayed |
| 143 | to indicate that you are expected to enter the name of a |
| 144 | register. |
| 145 | The text is inserted as if you typed it, but mappings and |
| 146 | abbreviations are not used. Command-line completion through |
| 147 | 'wildchar' is not triggered though. And characters that end |
| 148 | the command line are inserted literally (<Esc>, <CR>, <NL>, |
| 149 | <C-C>). A <BS> or CTRL-W could still end the command line |
| 150 | though, and remaining characters will then be interpreted in |
| 151 | another mode, which might not be what you intended. |
| 152 | Special registers: |
| 153 | '"' the unnamed register, containing the text of |
| 154 | the last delete or yank |
| 155 | '%' the current file name |
| 156 | '#' the alternate file name |
| 157 | '*' the clipboard contents (X11: primary selection) |
| 158 | '+' the clipboard contents |
| 159 | '/' the last search pattern |
| 160 | ':' the last command-line |
| 161 | '-' the last small (less than a line) delete |
| 162 | '.' the last inserted text |
| 163 | *c_CTRL-R_=* |
| 164 | '=' the expression register: you are prompted to |
| 165 | enter an expression (see |expression|) |
Bram Moolenaar | 05a7bb3 | 2006-01-19 22:09:32 +0000 | [diff] [blame] | 166 | (doesn't work at the expression prompt; some |
| 167 | things such as changing the buffer or current |
| 168 | window are not allowed to avoid side effects) |
Bram Moolenaar | d812df6 | 2008-11-09 12:46:09 +0000 | [diff] [blame] | 169 | When the result is a |List| the items are used |
| 170 | as lines. They can have line breaks inside |
| 171 | too. |
| 172 | When the result is a Float it's automatically |
| 173 | converted to a String. |
Bram Moolenaar | 6aa5729 | 2021-08-14 21:25:52 +0200 | [diff] [blame] | 174 | Note that when you only want to move the |
| 175 | cursor and not insert anything, you must make |
| 176 | sure the expression evaluates to an empty |
| 177 | string. E.g.: > |
| 178 | <C-R><C-R>=setcmdpos(2)[-1]<CR> |
| 179 | < See |registers| about registers. |
Bram Moolenaar | fd37168 | 2005-01-14 21:42:54 +0000 | [diff] [blame] | 180 | Implementation detail: When using the |expression| register |
| 181 | and invoking setcmdpos(), this sets the position before |
| 182 | inserting the resulting string. Use CTRL-R CTRL-R to set the |
| 183 | position afterwards. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 184 | |
| 185 | CTRL-R CTRL-F *c_CTRL-R_CTRL-F* *c_<C-R>_<C-F>* |
| 186 | CTRL-R CTRL-P *c_CTRL-R_CTRL-P* *c_<C-R>_<C-P>* |
| 187 | CTRL-R CTRL-W *c_CTRL-R_CTRL-W* *c_<C-R>_<C-W>* |
| 188 | CTRL-R CTRL-A *c_CTRL-R_CTRL-A* *c_<C-R>_<C-A>* |
Bram Moolenaar | e2c8d83 | 2018-05-01 19:24:03 +0200 | [diff] [blame] | 189 | CTRL-R CTRL-L *c_CTRL-R_CTRL-L* *c_<C-R>_<C-L>* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 190 | Insert the object under the cursor: |
| 191 | CTRL-F the Filename under the cursor |
| 192 | CTRL-P the Filename under the cursor, expanded with |
| 193 | 'path' as in |gf| |
| 194 | CTRL-W the Word under the cursor |
| 195 | CTRL-A the WORD under the cursor; see |WORD| |
Bram Moolenaar | e2c8d83 | 2018-05-01 19:24:03 +0200 | [diff] [blame] | 196 | CTRL-L the line under the cursor |
Bram Moolenaar | d3667a2 | 2006-03-16 21:35:52 +0000 | [diff] [blame] | 197 | |
| 198 | When 'incsearch' is set the cursor position at the end of the |
| 199 | currently displayed match is used. With CTRL-W the part of |
| 200 | the word that was already typed is not inserted again. |
| 201 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 202 | *c_CTRL-R_CTRL-R* *c_<C-R>_<C-R>* |
| 203 | *c_CTRL-R_CTRL-O* *c_<C-R>_<C-O>* |
Bram Moolenaar | 5be4cee | 2019-09-27 19:34:08 +0200 | [diff] [blame] | 204 | CTRL-R CTRL-R {register CTRL-F CTRL-P CTRL-W CTRL-A CTRL-L} |
| 205 | CTRL-R CTRL-O {register CTRL-F CTRL-P CTRL-W CTRL-A CTRL-L} |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 206 | Insert register or object under the cursor. Works like |
| 207 | |c_CTRL-R| but inserts the text literally. For example, if |
| 208 | register a contains "xy^Hz" (where ^H is a backspace), |
| 209 | "CTRL-R a" will insert "xz" while "CTRL-R CTRL-R a" will |
| 210 | insert "xy^Hz". |
| 211 | |
| 212 | CTRL-\ e {expr} *c_CTRL-\_e* |
| 213 | Evaluate {expr} and replace the whole command line with the |
| 214 | result. You will be prompted for the expression, type <Enter> |
| 215 | to finish it. It's most useful in mappings though. See |
| 216 | |expression|. |
| 217 | See |c_CTRL-R_=| for inserting the result of an expression. |
Bram Moolenaar | bfd8fc0 | 2005-09-20 23:22:24 +0000 | [diff] [blame] | 218 | Useful functions are |getcmdtype()|, |getcmdline()| and |
| 219 | |getcmdpos()|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 220 | The cursor position is unchanged, except when the cursor was |
| 221 | at the end of the line, then it stays at the end. |
| 222 | |setcmdpos()| can be used to set the cursor position. |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 223 | The |sandbox| is used for evaluating the expression to avoid |
| 224 | nasty side effects. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 225 | Example: > |
| 226 | :cmap <F7> <C-\>eAppendSome()<CR> |
| 227 | :func AppendSome() |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 228 | :let cmd = getcmdline() .. " Some()" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 229 | :" place the cursor on the ) |
| 230 | :call setcmdpos(strlen(cmd)) |
| 231 | :return cmd |
| 232 | :endfunc |
Bram Moolenaar | bfd8fc0 | 2005-09-20 23:22:24 +0000 | [diff] [blame] | 233 | < This doesn't work recursively, thus not when already editing |
Bram Moolenaar | 3a0d809 | 2012-10-21 03:02:54 +0200 | [diff] [blame] | 234 | an expression. But it is possible to use in a mapping. |
Bram Moolenaar | bfd8fc0 | 2005-09-20 23:22:24 +0000 | [diff] [blame] | 235 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 236 | *c_CTRL-Y* |
| 237 | CTRL-Y When there is a modeless selection, copy the selection into |
| 238 | the clipboard. |modeless-selection| |
| 239 | If there is no selection CTRL-Y is inserted as a character. |
| 240 | |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 241 | CTRL-M or CTRL-J *c_CTRL-M* *c_CTRL-J* *c_<NL>* *c_<CR>* *c_CR* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 242 | <CR> or <NL> start entered command |
Bram Moolenaar | 2ec618c | 2016-10-01 14:47:05 +0200 | [diff] [blame] | 243 | |
| 244 | CTRL-[ *c_CTRL-[* *c_<Esc>* *c_Esc* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 245 | <Esc> When typed and 'x' not present in 'cpoptions', quit |
| 246 | Command-line mode without executing. In macros or when 'x' |
| 247 | present in 'cpoptions', start entered command. |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 248 | Note: If your <Esc> key is hard to hit on your keyboard, train |
| 249 | yourself to use CTRL-[. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 250 | *c_CTRL-C* |
| 251 | CTRL-C quit command-line without executing |
| 252 | |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 253 | *c_<Up>* *c_Up* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 254 | <Up> recall older command-line from history, whose beginning |
| 255 | matches the current command-line (see below). |
| 256 | {not available when compiled without the |+cmdline_hist| |
| 257 | feature} |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 258 | *c_<Down>* *c_Down* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 259 | <Down> recall more recent command-line from history, whose beginning |
| 260 | matches the current command-line (see below). |
| 261 | {not available when compiled without the |+cmdline_hist| |
| 262 | feature} |
| 263 | |
| 264 | *c_<S-Up>* *c_<PageUp>* |
| 265 | <S-Up> or <PageUp> |
| 266 | recall older command-line from history |
| 267 | {not available when compiled without the |+cmdline_hist| |
| 268 | feature} |
| 269 | *c_<S-Down>* *c_<PageDown>* |
| 270 | <S-Down> or <PageDown> |
| 271 | recall more recent command-line from history |
| 272 | {not available when compiled without the |+cmdline_hist| |
| 273 | feature} |
| 274 | |
| 275 | CTRL-D command-line completion (see |cmdline-completion|) |
| 276 | 'wildchar' option |
| 277 | command-line completion (see |cmdline-completion|) |
| 278 | CTRL-N command-line completion (see |cmdline-completion|) |
| 279 | CTRL-P command-line completion (see |cmdline-completion|) |
| 280 | CTRL-A command-line completion (see |cmdline-completion|) |
| 281 | CTRL-L command-line completion (see |cmdline-completion|) |
| 282 | |
| 283 | *c_CTRL-_* |
| 284 | CTRL-_ a - switch between Hebrew and English keyboard mode, which is |
| 285 | private to the command-line and not related to hkmap. |
| 286 | This is useful when Hebrew text entry is required in the |
| 287 | command-line, searches, abbreviations, etc. Applies only if |
| 288 | Vim is compiled with the |+rightleft| feature and the |
| 289 | 'allowrevins' option is set. |
| 290 | See |rileft.txt|. |
| 291 | |
| 292 | b - switch between Farsi and English keyboard mode, which is |
| 293 | private to the command-line and not related to fkmap. In |
| 294 | Farsi keyboard mode the characters are inserted in reverse |
| 295 | insert manner. This is useful when Farsi text entry is |
| 296 | required in the command-line, searches, abbreviations, etc. |
| 297 | Applies only if Vim is compiled with the |+farsi| feature. |
| 298 | See |farsi.txt|. |
| 299 | |
| 300 | *c_CTRL-^* |
| 301 | CTRL-^ Toggle the use of language |:lmap| mappings and/or Input |
| 302 | Method. |
| 303 | When typing a pattern for a search command and 'imsearch' is |
| 304 | not -1, VAL is the value of 'imsearch', otherwise VAL is the |
| 305 | value of 'iminsert'. |
| 306 | When language mappings are defined: |
| 307 | - If VAL is 1 (langmap mappings used) it becomes 0 (no langmap |
| 308 | mappings used). |
| 309 | - If VAL was not 1 it becomes 1, thus langmap mappings are |
| 310 | enabled. |
| 311 | When no language mappings are defined: |
| 312 | - If VAL is 2 (Input Method is used) it becomes 0 (no input |
| 313 | method used) |
| 314 | - If VAL has another value it becomes 2, thus the Input Method |
| 315 | is enabled. |
| 316 | These language mappings are normally used to type characters |
| 317 | that are different from what the keyboard produces. The |
| 318 | 'keymap' option can be used to install a whole number of them. |
| 319 | When entering a command line, langmap mappings are switched |
| 320 | off, since you are expected to type a command. After |
| 321 | switching it on with CTRL-^, the new state is not used again |
| 322 | for the next command or Search pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 323 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 324 | *c_CTRL-]* |
Bram Moolenaar | 25c9c68 | 2019-05-05 18:13:34 +0200 | [diff] [blame] | 325 | CTRL-] Trigger abbreviation, without inserting a character. |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 326 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 327 | For Emacs-style editing on the command-line see |emacs-keys|. |
| 328 | |
| 329 | The <Up> and <Down> keys take the current command-line as a search string. |
| 330 | The beginning of the next/previous command-lines are compared with this |
| 331 | string. The first line that matches is the new command-line. When typing |
| 332 | these two keys repeatedly, the same string is used again. For example, this |
| 333 | can be used to find the previous substitute command: Type ":s" and then <Up>. |
| 334 | The same could be done by typing <S-Up> a number of times until the desired |
| 335 | command-line is shown. (Note: the shifted arrow keys do not work on all |
| 336 | terminals) |
| 337 | |
Bram Moolenaar | 066b622 | 2008-01-04 14:17:47 +0000 | [diff] [blame] | 338 | *:his* *:history* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 339 | :his[tory] Print the history of last entered commands. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 340 | {not available when compiled without the |+cmdline_hist| |
| 341 | feature} |
| 342 | |
| 343 | :his[tory] [{name}] [{first}][, [{last}]] |
| 344 | List the contents of history {name} which can be: |
Bram Moolenaar | 5ae636b | 2012-04-30 18:48:53 +0200 | [diff] [blame] | 345 | c[md] or : command-line history |
| 346 | s[earch] or / or ? search string history |
| 347 | e[xpr] or = expression register history |
| 348 | i[nput] or @ input line history |
| 349 | d[ebug] or > debug command history |
| 350 | a[ll] all of the above |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 351 | |
| 352 | If the numbers {first} and/or {last} are given, the respective |
| 353 | range of entries from a history is listed. These numbers can |
| 354 | be specified in the following form: |
| 355 | *:history-indexing* |
| 356 | A positive number represents the absolute index of an entry |
| 357 | as it is given in the first column of a :history listing. |
| 358 | This number remains fixed even if other entries are deleted. |
| 359 | |
| 360 | A negative number means the relative position of an entry, |
| 361 | counted from the newest entry (which has index -1) backwards. |
| 362 | |
| 363 | Examples: |
| 364 | List entries 6 to 12 from the search history: > |
| 365 | :history / 6,12 |
| 366 | < |
Bram Moolenaar | eebd84e | 2016-12-01 17:57:44 +0100 | [diff] [blame] | 367 | List the penultimate entry from all histories: > |
| 368 | :history all -2 |
| 369 | < |
| 370 | List the most recent two entries from all histories: > |
| 371 | :history all -2, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 372 | |
Bram Moolenaar | a939e43 | 2013-11-09 05:30:26 +0100 | [diff] [blame] | 373 | :keepp[atterns] {command} *:keepp* *:keeppatterns* |
| 374 | Execute {command}, without adding anything to the search |
| 375 | history |
| 376 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 377 | ============================================================================== |
| 378 | 2. Command-line completion *cmdline-completion* |
| 379 | |
| 380 | When editing the command-line, a few commands can be used to complete the |
| 381 | word before the cursor. This is available for: |
| 382 | |
| 383 | - Command names: At the start of the command-line. |
| 384 | - Tags: Only after the ":tag" command. |
| 385 | - File names: Only after a command that accepts a file name or a setting for |
| 386 | an option that can be set to a file name. This is called file name |
| 387 | completion. |
Bram Moolenaar | a203182 | 2006-03-07 22:29:51 +0000 | [diff] [blame] | 388 | - Shell command names: After ":!cmd", ":r !cmd" and ":w !cmd". $PATH is used. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 389 | - Options: Only after the ":set" command. |
| 390 | - Mappings: Only after a ":map" or similar command. |
| 391 | - Variable and function names: Only after a ":if", ":call" or similar command. |
| 392 | |
Bram Moolenaar | 0a52df5 | 2019-08-18 22:26:31 +0200 | [diff] [blame] | 393 | The number of help item matches is limited (currently to 300) to avoid a long |
| 394 | delay when there are very many matches. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 395 | |
| 396 | These are the commands that can be used: |
| 397 | |
| 398 | *c_CTRL-D* |
| 399 | CTRL-D List names that match the pattern in front of the cursor. |
| 400 | When showing file names, directories are highlighted (see |
| 401 | 'highlight' option). Names where 'suffixes' matches are moved |
| 402 | to the end. |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 403 | The 'wildoptions' option can be set to "tagfile" to list the |
| 404 | file of matching tags. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 405 | *c_CTRL-I* *c_wildchar* *c_<Tab>* |
| 406 | 'wildchar' option |
| 407 | A match is done on the pattern in front of the cursor. The |
| 408 | match (if there are several, the first match) is inserted |
| 409 | in place of the pattern. (Note: does not work inside a |
| 410 | macro, because <Tab> or <Esc> are mostly used as 'wildchar', |
| 411 | and these have a special meaning in some macros.) When typed |
| 412 | again and there were multiple matches, the next |
| 413 | match is inserted. After the last match, the first is used |
| 414 | again (wrap around). |
| 415 | The behavior can be changed with the 'wildmode' option. |
Bram Moolenaar | 7db25fe | 2018-05-13 00:02:36 +0200 | [diff] [blame] | 416 | *c_<S-Tab>* |
| 417 | <S-Tab> Like 'wildchar' or <Tab>, but begin with the last match and |
| 418 | then go to the previous match. |
| 419 | <S-Tab> does not work everywhere. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 420 | *c_CTRL-N* |
| 421 | CTRL-N After using 'wildchar' which got multiple matches, go to next |
| 422 | match. Otherwise recall more recent command-line from history. |
Bram Moolenaar | 7db25fe | 2018-05-13 00:02:36 +0200 | [diff] [blame] | 423 | *c_CTRL-P* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 424 | CTRL-P After using 'wildchar' which got multiple matches, go to |
| 425 | previous match. Otherwise recall older command-line from |
Bram Moolenaar | 7db25fe | 2018-05-13 00:02:36 +0200 | [diff] [blame] | 426 | history. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 427 | *c_CTRL-A* |
| 428 | CTRL-A All names that match the pattern in front of the cursor are |
| 429 | inserted. |
| 430 | *c_CTRL-L* |
| 431 | CTRL-L A match is done on the pattern in front of the cursor. If |
| 432 | there is one match, it is inserted in place of the pattern. |
| 433 | If there are multiple matches the longest common part is |
| 434 | inserted in place of the pattern. If the result is shorter |
| 435 | than the pattern, no completion is done. |
Bram Moolenaar | 4d6f32c | 2016-08-26 19:13:46 +0200 | [diff] [blame] | 436 | */_CTRL-L* |
Bram Moolenaar | d3667a2 | 2006-03-16 21:35:52 +0000 | [diff] [blame] | 437 | When 'incsearch' is set, entering a search pattern for "/" or |
| 438 | "?" and the current match is displayed then CTRL-L will add |
Bram Moolenaar | a9dc375 | 2010-07-11 20:46:53 +0200 | [diff] [blame] | 439 | one character from the end of the current match. If |
| 440 | 'ignorecase' and 'smartcase' are set and the command line has |
| 441 | no uppercase characters, the added character is converted to |
| 442 | lowercase. |
Bram Moolenaar | 1195669 | 2016-08-27 16:26:56 +0200 | [diff] [blame] | 443 | *c_CTRL-G* */_CTRL-G* |
| 444 | CTRL-G When 'incsearch' is set, entering a search pattern for "/" or |
| 445 | "?" and the current match is displayed then CTRL-G will move |
| 446 | to the next match (does not take |search-offset| into account) |
| 447 | Use CTRL-T to move to the previous match. Hint: on a regular |
| 448 | keyboard T is above G. |
| 449 | *c_CTRL-T* */_CTRL-T* |
| 450 | CTRL-T When 'incsearch' is set, entering a search pattern for "/" or |
| 451 | "?" and the current match is displayed then CTRL-T will move |
| 452 | to the previous match (does not take |search-offset| into |
| 453 | account). |
| 454 | Use CTRL-G to move to the next match. Hint: on a regular |
| 455 | keyboard T is above G. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 456 | |
| 457 | The 'wildchar' option defaults to <Tab> (CTRL-E when in Vi compatible mode; in |
| 458 | a previous version <Esc> was used). In the pattern standard wildcards '*' and |
Bram Moolenaar | 24ea3ba | 2010-09-19 19:01:21 +0200 | [diff] [blame] | 459 | '?' are accepted when matching file names. '*' matches any string, '?' |
| 460 | matches exactly one character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 461 | |
Bram Moolenaar | 259f26a | 2018-05-15 22:25:40 +0200 | [diff] [blame] | 462 | When repeating 'wildchar' or CTRL-N you cycle through the matches, eventually |
| 463 | ending up back to what was typed. If the first match is not what you wanted, |
| 464 | you can use <S-Tab> or CTRL-P to go straight back to what you typed. |
| 465 | |
Bram Moolenaar | 5dc6252 | 2012-02-13 00:05:22 +0100 | [diff] [blame] | 466 | The 'wildignorecase' option can be set to ignore case in filenames. |
| 467 | |
Bram Moolenaar | 74675a6 | 2017-07-15 13:53:23 +0200 | [diff] [blame] | 468 | The 'wildmenu' option can be set to show the matches just above the command |
| 469 | line. |
| 470 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 471 | If you like tcsh's autolist completion, you can use this mapping: |
| 472 | :cnoremap X <C-L><C-D> |
| 473 | (Where X is the command key to use, <C-L> is CTRL-L and <C-D> is CTRL-D) |
| 474 | This will find the longest match and then list all matching files. |
| 475 | |
| 476 | If you like tcsh's autolist completion, you can use the 'wildmode' option to |
| 477 | emulate it. For example, this mimics autolist=ambiguous: |
| 478 | :set wildmode=longest,list |
| 479 | This will find the longest match with the first 'wildchar', then list all |
| 480 | matching files with the next. |
| 481 | |
Bram Moolenaar | eab6dff | 2020-03-01 19:06:45 +0100 | [diff] [blame] | 482 | *complete-script-local-functions* |
| 483 | When completing user function names, prepend "s:" to find script-local |
| 484 | functions. |
| 485 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 486 | *suffixes* |
| 487 | For file name completion you can use the 'suffixes' option to set a priority |
| 488 | between files with almost the same name. If there are multiple matches, |
| 489 | those files with an extension that is in the 'suffixes' option are ignored. |
| 490 | The default is ".bak,~,.o,.h,.info,.swp,.obj", which means that files ending |
| 491 | in ".bak", "~", ".o", ".h", ".info", ".swp" and ".obj" are sometimes ignored. |
Bram Moolenaar | 055a2ba | 2009-07-14 19:40:21 +0000 | [diff] [blame] | 492 | |
| 493 | An empty entry, two consecutive commas, match a file name that does not |
| 494 | contain a ".", thus has no suffix. This is useful to ignore "prog" and prefer |
| 495 | "prog.c". |
| 496 | |
| 497 | Examples: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 498 | |
| 499 | pattern: files: match: ~ |
| 500 | test* test.c test.h test.o test.c |
| 501 | test* test.h test.o test.h and test.o |
| 502 | test* test.i test.h test.c test.i and test.c |
| 503 | |
Bram Moolenaar | 055a2ba | 2009-07-14 19:40:21 +0000 | [diff] [blame] | 504 | It is impossible to ignore suffixes with two dots. |
| 505 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 506 | If there is more than one matching file (after ignoring the ones matching |
| 507 | the 'suffixes' option) the first file name is inserted. You can see that |
| 508 | there is only one match when you type 'wildchar' twice and the completed |
| 509 | match stays the same. You can get to the other matches by entering |
| 510 | 'wildchar', CTRL-N or CTRL-P. All files are included, also the ones with |
| 511 | extensions matching the 'suffixes' option. |
| 512 | |
| 513 | To completely ignore files with some extension use 'wildignore'. |
| 514 | |
Bram Moolenaar | 066b622 | 2008-01-04 14:17:47 +0000 | [diff] [blame] | 515 | To match only files that end at the end of the typed text append a "$". For |
| 516 | example, to match only files that end in ".c": > |
| 517 | :e *.c$ |
| 518 | This will not match a file ending in ".cpp". Without the "$" it does match. |
| 519 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 520 | If you would like using <S-Tab> for CTRL-P in an xterm, put this command in |
| 521 | your .cshrc: > |
| 522 | xmodmap -e "keysym Tab = Tab Find" |
| 523 | And this in your .vimrc: > |
| 524 | :cmap <Esc>[1~ <C-P> |
Yee Cheng Chin | 900894b | 2023-09-29 20:42:32 +0200 | [diff] [blame] | 525 | < *complete-set-option* |
| 526 | When setting an option using |:set=|, the old value of an option can be |
| 527 | obtained by hitting 'wildchar' just after the '='. For example, typing |
| 528 | 'wildchar' after ":set dir=" will insert the current value of 'dir'. This |
| 529 | overrules file name completion for the options that take a file name. |
| 530 | |
| 531 | When using |:set=|, |:set+=|, or |:set^=|, string options that have |
| 532 | pre-defined names or syntax (e.g. 'diffopt', 'listchars') or are a list of |
| 533 | single-character flags (e.g. 'shortmess') will also present a list of possible |
| 534 | values for completion when using 'wildchar'. |
| 535 | |
| 536 | When using |:set-=|, comma-separated options like 'diffopt' or 'backupdir' |
| 537 | will show each item separately. Flag list options like 'shortmess' will show |
| 538 | both the entire old value and the individual flags. Otherwise completion will |
| 539 | just fill in with the entire old value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 540 | |
| 541 | ============================================================================== |
| 542 | 3. Ex command-lines *cmdline-lines* |
| 543 | |
| 544 | The Ex commands have a few specialties: |
| 545 | |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 546 | *:quote* *:comment* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 547 | '"' at the start of a line causes the whole line to be ignored. '"' |
| 548 | after a command causes the rest of the line to be ignored. This can be used |
| 549 | to add comments. Example: > |
| 550 | :set ai "set 'autoindent' option |
| 551 | It is not possible to add a comment to a shell command ":!cmd" or to the |
Bram Moolenaar | 2c64ca1 | 2018-10-19 16:22:31 +0200 | [diff] [blame] | 552 | ":map" command and a few others (mainly commands that expect expressions) |
| 553 | that see the '"' as part of their argument: |
| 554 | |
| 555 | :argdo |
| 556 | :autocmd |
| 557 | :bufdo |
| 558 | :cexpr (and the like) |
Bram Moolenaar | 2c64ca1 | 2018-10-19 16:22:31 +0200 | [diff] [blame] | 559 | :cdo (and the like) |
| 560 | :command |
| 561 | :cscope (and the like) |
| 562 | :debug |
| 563 | :display |
| 564 | :echo (and the like) |
| 565 | :elseif |
| 566 | :execute |
| 567 | :folddoopen |
| 568 | :folddoclosed |
| 569 | :for |
| 570 | :grep (and the like) |
| 571 | :help (and the like) |
| 572 | :if |
| 573 | :let |
| 574 | :make |
| 575 | :map (and the like including :abbrev commands) |
| 576 | :menu (and the like) |
| 577 | :mkspell |
| 578 | :normal |
| 579 | :ownsyntax |
| 580 | :popup |
| 581 | :promptfind (and the like) |
| 582 | :registers |
| 583 | :return |
| 584 | :sort |
| 585 | :syntax |
| 586 | :tabdo |
| 587 | :tearoff |
| 588 | :vimgrep (and the like) |
| 589 | :while |
| 590 | :windo |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 591 | |
| 592 | *:bar* *:\bar* |
| 593 | '|' can be used to separate commands, so you can give multiple commands in one |
| 594 | line. If you want to use '|' in an argument, precede it with '\'. |
| 595 | |
| 596 | These commands see the '|' as their argument, and can therefore not be |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 597 | followed by another Vim command: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 598 | :argdo |
| 599 | :autocmd |
| 600 | :bufdo |
Bram Moolenaar | aa23b37 | 2015-09-08 18:46:31 +0200 | [diff] [blame] | 601 | :cdo |
| 602 | :cfdo |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 603 | :command |
| 604 | :cscope |
| 605 | :debug |
Bram Moolenaar | bc93ceb | 2020-02-26 13:36:21 +0100 | [diff] [blame] | 606 | :eval |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 607 | :folddoopen |
| 608 | :folddoclosed |
| 609 | :function |
| 610 | :global |
| 611 | :help |
| 612 | :helpfind |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 613 | :helpgrep |
Bram Moolenaar | 110bc6b | 2006-02-10 23:13:40 +0000 | [diff] [blame] | 614 | :lcscope |
Bram Moolenaar | aa23b37 | 2015-09-08 18:46:31 +0200 | [diff] [blame] | 615 | :ldo |
| 616 | :lfdo |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 617 | :lhelpgrep |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 618 | :make |
| 619 | :normal |
| 620 | :perl |
| 621 | :perldo |
| 622 | :promptfind |
| 623 | :promptrepl |
| 624 | :pyfile |
| 625 | :python |
| 626 | :registers |
| 627 | :read ! |
| 628 | :scscope |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 629 | :sign |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 630 | :tabdo |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 631 | :tcl |
| 632 | :tcldo |
| 633 | :tclfile |
Bram Moolenaar | 7ceefb3 | 2020-05-01 16:07:38 +0200 | [diff] [blame] | 634 | :terminal |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 635 | :vglobal |
| 636 | :windo |
| 637 | :write ! |
| 638 | :[range]! |
| 639 | a user defined command without the "-bar" argument |:command| |
| 640 | |
| 641 | Note that this is confusing (inherited from Vi): With ":g" the '|' is included |
| 642 | in the command, with ":s" it is not. |
| 643 | |
| 644 | To be able to use another command anyway, use the ":execute" command. |
| 645 | Example (append the output of "ls" and jump to the first line): > |
| 646 | :execute 'r !ls' | '[ |
| 647 | |
| 648 | There is one exception: When the 'b' flag is present in 'cpoptions', with the |
| 649 | ":map" and ":abbr" commands and friends CTRL-V needs to be used instead of |
| 650 | '\'. You can also use "<Bar>" instead. See also |map_bar|. |
| 651 | |
| 652 | Examples: > |
| 653 | :!ls | wc view the output of two commands |
| 654 | :r !ls | wc insert the same output in the text |
| 655 | :%g/foo/p|> moves all matching lines one shiftwidth |
| 656 | :%s/foo/bar/|> moves one line one shiftwidth |
| 657 | :map q 10^V| map "q" to "10|" |
| 658 | :map q 10\| map \ l map "q" to "10\" and map "\" to "l" |
| 659 | (when 'b' is present in 'cpoptions') |
| 660 | |
| 661 | You can also use <NL> to separate commands in the same way as with '|'. To |
| 662 | insert a <NL> use CTRL-V CTRL-J. "^@" will be shown. Using '|' is the |
| 663 | preferred method. But for external commands a <NL> must be used, because a |
| 664 | '|' is included in the external command. To avoid the special meaning of <NL> |
| 665 | it must be preceded with a backslash. Example: > |
| 666 | :r !date<NL>-join |
| 667 | This reads the current date into the file and joins it with the previous line. |
| 668 | |
| 669 | Note that when the command before the '|' generates an error, the following |
| 670 | commands will not be executed. |
| 671 | |
| 672 | |
| 673 | Because of Vi compatibility the following strange commands are supported: > |
| 674 | :| print current line (like ":p") |
| 675 | :3| print line 3 (like ":3p") |
| 676 | :3 goto line 3 |
| 677 | |
| 678 | A colon is allowed between the range and the command name. It is ignored |
| 679 | (this is Vi compatible). For example: > |
| 680 | :1,$:s/pat/string |
| 681 | |
| 682 | When the character '%' or '#' is used where a file name is expected, they are |
| 683 | expanded to the current and alternate file name (see the chapter "editing |
| 684 | files" |:_%| |:_#|). |
| 685 | |
| 686 | Embedded spaces in file names are allowed on the Amiga if one file name is |
| 687 | expected as argument. Trailing spaces will be ignored, unless escaped with a |
| 688 | backslash or CTRL-V. Note that the ":next" command uses spaces to separate |
| 689 | file names. Escape the spaces to include them in a file name. Example: > |
| 690 | :next foo\ bar goes\ to school\ |
| 691 | starts editing the three files "foo bar", "goes to" and "school ". |
| 692 | |
| 693 | When you want to use the special characters '"' or '|' in a command, or want |
| 694 | to use '%' or '#' in a file name, precede them with a backslash. The |
| 695 | backslash is not required in a range and in the ":substitute" command. |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 696 | See also |`=|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 697 | |
| 698 | *:_!* |
| 699 | The '!' (bang) character after an Ex command makes the command behave in a |
| 700 | different way. The '!' should be placed immediately after the command, without |
| 701 | any blanks in between. If you insert blanks the '!' will be seen as an |
| 702 | argument for the command, which has a different meaning. For example: |
| 703 | :w! name write the current buffer to file "name", overwriting |
| 704 | any existing file |
| 705 | :w !name send the current buffer as standard input to command |
| 706 | "name" |
| 707 | |
| 708 | ============================================================================== |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 709 | 4. Ex command-line ranges *cmdline-ranges* *[range]* *E16* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 710 | |
| 711 | Some Ex commands accept a line range in front of them. This is noted as |
| 712 | [range]. It consists of one or more line specifiers, separated with ',' or |
| 713 | ';'. |
| 714 | |
| 715 | The basics are explained in section |10.3| of the user manual. |
| 716 | |
Bram Moolenaar | a4d131d | 2021-12-27 21:33:07 +0000 | [diff] [blame] | 717 | In |Vim9| script a range needs to be prefixed with a colon to avoid ambiguity |
| 718 | with continuation lines. For example, "+" can be used for a range but is also |
| 719 | a continuation of an expression: > |
| 720 | var result = start |
| 721 | + print |
| 722 | If the "+" is a range then it must be prefixed with a colon: > |
| 723 | var result = start |
| 724 | :+ print |
| 725 | < |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 726 | *:,* *:;* |
| 727 | When separated with ';' the cursor position will be set to that line |
| 728 | before interpreting the next line specifier. This doesn't happen for ','. |
| 729 | Examples: > |
| 730 | 4,/this line/ |
| 731 | < from line 4 till match with "this line" after the cursor line. > |
| 732 | 5;/that line/ |
| 733 | < from line 5 till match with "that line" after line 5. |
| 734 | |
| 735 | The default line specifier for most commands is the cursor position, but the |
| 736 | commands ":write" and ":global" have the whole file (1,$) as default. |
| 737 | |
| 738 | If more line specifiers are given than required for the command, the first |
| 739 | one(s) will be ignored. |
| 740 | |
Bram Moolenaar | 088e8e3 | 2019-08-08 22:15:18 +0200 | [diff] [blame] | 741 | Line numbers may be specified with: *:range* *{address}* |
Bram Moolenaar | a2baa73 | 2022-02-04 16:09:54 +0000 | [diff] [blame] | 742 | {number} an absolute line number *E1247* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 743 | . the current line *:.* |
| 744 | $ the last line in the file *:$* |
| 745 | % equal to 1,$ (the entire file) *:%* |
| 746 | 't position of mark t (lowercase) *:'* |
| 747 | 'T position of mark T (uppercase); when the mark is in |
| 748 | another file it cannot be used in a range |
| 749 | /{pattern}[/] the next line where {pattern} matches *:/* |
Bram Moolenaar | 9954dc3 | 2022-11-11 22:58:36 +0000 | [diff] [blame] | 750 | also see |:range-pattern| below |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 751 | ?{pattern}[?] the previous line where {pattern} matches *:?* |
Bram Moolenaar | 9954dc3 | 2022-11-11 22:58:36 +0000 | [diff] [blame] | 752 | also see |:range-pattern| below |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 753 | \/ the next line where the previously used search |
| 754 | pattern matches |
| 755 | \? the previous line where the previously used search |
| 756 | pattern matches |
| 757 | \& the next line where the previously used substitute |
| 758 | pattern matches |
| 759 | |
Bram Moolenaar | 9954dc3 | 2022-11-11 22:58:36 +0000 | [diff] [blame] | 760 | *:range-offset* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 761 | Each may be followed (several times) by '+' or '-' and an optional number. |
| 762 | This number is added or subtracted from the preceding line number. If the |
Bram Moolenaar | 2f0936c | 2022-01-08 21:51:59 +0000 | [diff] [blame] | 763 | number is omitted, 1 is used. If there is nothing before the '+' or '-' then |
| 764 | the current line is used. |
Bram Moolenaar | 9954dc3 | 2022-11-11 22:58:36 +0000 | [diff] [blame] | 765 | *:range-closed-fold* |
| 766 | When a line number after the comma is in a closed fold it is adjusted to the |
| 767 | last line of the fold, thus the whole fold is included. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 768 | |
Bram Moolenaar | 9954dc3 | 2022-11-11 22:58:36 +0000 | [diff] [blame] | 769 | When a number is added this is done after the adjustment to the last line of |
| 770 | the fold. This means these lines are additionally included in the range. For |
| 771 | example: > |
| 772 | :3,4+2print |
| 773 | On this text: |
| 774 | 1 one ~ |
| 775 | 2 two ~ |
| 776 | 3 three ~ |
| 777 | 4 four FOLDED ~ |
| 778 | 5 five FOLDED ~ |
| 779 | 6 six ~ |
| 780 | 7 seven ~ |
| 781 | 8 eight ~ |
| 782 | Where lines four and five are a closed fold, ends up printing lines 3 to 7. |
| 783 | The 7 comes from the "4" in the range, which is adjusted to the end of the |
| 784 | closed fold, which is 5, and then the offset 2 is added. |
| 785 | |
| 786 | An example for subtracting (which isn't very useful): > |
| 787 | :2,4-1print |
| 788 | On this text: |
| 789 | 1 one ~ |
| 790 | 2 two ~ |
h_east | ba77bbb | 2023-10-03 04:47:13 +0900 | [diff] [blame] | 791 | 3 three FOLDED ~ |
Bram Moolenaar | 9954dc3 | 2022-11-11 22:58:36 +0000 | [diff] [blame] | 792 | 4 four FOLDED ~ |
| 793 | 5 five FOLDED ~ |
| 794 | 6 six FOLDED ~ |
| 795 | 7 seven ~ |
| 796 | 8 eight ~ |
| 797 | Where lines three to six are a closed fold, ends up printing lines 2 to 6. |
| 798 | The 6 comes from the "4" in the range, which is adjusted to the end of the |
| 799 | closed fold, which is 6, and then 1 is subtracted, then this is still in the |
| 800 | closed fold and the last line of that fold is used, which is 6. |
| 801 | |
| 802 | *:range-pattern* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 803 | The "/" and "?" after {pattern} are required to separate the pattern from |
| 804 | anything that follows. |
| 805 | |
| 806 | The "/" and "?" may be preceded with another address. The search starts from |
| 807 | there. The difference from using ';' is that the cursor isn't moved. |
| 808 | Examples: > |
| 809 | /pat1//pat2/ Find line containing "pat2" after line containing |
| 810 | "pat1", without moving the cursor. |
| 811 | 7;/pat2/ Find line containing "pat2", after line 7, leaving |
| 812 | the cursor in line 7. |
| 813 | |
| 814 | The {number} must be between 0 and the number of lines in the file. When |
| 815 | using a 0 (zero) this is interpreted as a 1 by most commands. Commands that |
| 816 | use it as a count do use it as a zero (|:tag|, |:pop|, etc). Some commands |
| 817 | interpret the zero as "before the first line" (|:read|, search pattern, etc). |
| 818 | |
| 819 | Examples: > |
| 820 | .+3 three lines below the cursor |
| 821 | /that/+1 the line below the next line containing "that" |
| 822 | .,$ from current line until end of file |
| 823 | 0;/that the first line containing "that", also matches in the |
| 824 | first line. |
| 825 | 1;/that the first line after line 1 containing "that" |
| 826 | |
| 827 | Some commands allow for a count after the command. This count is used as the |
| 828 | number of lines to be used, starting with the line given in the last line |
| 829 | specifier (the default is the cursor line). The commands that accept a count |
| 830 | are the ones that use a range but do not have a file name argument (because |
Bram Moolenaar | 2f0936c | 2022-01-08 21:51:59 +0000 | [diff] [blame] | 831 | a file name can also be a number). The count cannot be negative. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 832 | |
| 833 | Examples: > |
| 834 | :s/x/X/g 5 substitute 'x' by 'X' in the current line and four |
| 835 | following lines |
| 836 | :23d 4 delete lines 23, 24, 25 and 26 |
| 837 | |
| 838 | |
| 839 | Folds and Range |
| 840 | |
| 841 | When folds are active the line numbers are rounded off to include the whole |
| 842 | closed fold. See |fold-behavior|. |
| 843 | |
| 844 | |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 845 | Reverse Range *E493* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 846 | |
| 847 | A range should have the lower line number first. If this is not the case, Vim |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 848 | will ask you if it should swap the line numbers. |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 849 | Backwards range given, OK to swap ~ |
| 850 | This is not done within the global command ":g". |
| 851 | |
| 852 | You can use ":silent" before a command to avoid the question, the range will |
| 853 | always be swapped then. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 854 | |
| 855 | |
| 856 | Count and Range *N:* |
| 857 | |
Bram Moolenaar | 76db9e0 | 2022-11-09 21:21:04 +0000 | [diff] [blame] | 858 | When giving a count before entering ":", this is translated into: > |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 859 | :.,.+(count - 1) |
Bram Moolenaar | 9fbdbb8 | 2022-09-27 17:30:34 +0100 | [diff] [blame] | 860 | In words: The "count" lines at and after the cursor. Example: To delete |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 861 | three lines: > |
| 862 | 3:d<CR> is translated into: .,.+2d<CR> |
| 863 | < |
| 864 | |
Bram Moolenaar | 2286304 | 2021-10-16 15:23:36 +0100 | [diff] [blame] | 865 | Visual Mode and Range |
Bram Moolenaar | 3ec3217 | 2021-05-16 12:39:47 +0200 | [diff] [blame] | 866 | *v_:* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 867 | {Visual}: Starts a command-line with the Visual selected lines as a |
Bram Moolenaar | a3e6bc9 | 2013-01-30 14:18:00 +0100 | [diff] [blame] | 868 | range. The code `:'<,'>` is used for this range, which makes |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 869 | it possible to select a similar line from the command-line |
| 870 | history for repeating a command on different Visually selected |
| 871 | lines. |
Bram Moolenaar | 3ec3217 | 2021-05-16 12:39:47 +0200 | [diff] [blame] | 872 | |
| 873 | :* *:star* *:star-visual-range* |
Bram Moolenaar | a3e6bc9 | 2013-01-30 14:18:00 +0100 | [diff] [blame] | 874 | When Visual mode was already ended, a short way to use the |
| 875 | Visual area for a range is `:*`. This requires that "*" does |
| 876 | not appear in 'cpo', see |cpo-star|. Otherwise you will have |
| 877 | to type `:'<,'>` |
Bram Moolenaar | 3ec3217 | 2021-05-16 12:39:47 +0200 | [diff] [blame] | 878 | For when "*" is in 'cpo' see |:star-compatible|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 879 | |
| 880 | ============================================================================== |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 881 | 5. Ex command-line flags *ex-flags* |
| 882 | |
| 883 | These flags are supported by a selection of Ex commands. They print the line |
| 884 | that the cursor ends up after executing the command: |
| 885 | |
| 886 | l output like for |:list| |
| 887 | # add line number |
| 888 | p output like for |:print| |
| 889 | |
| 890 | The flags can be combined, thus "l#" uses both a line number and |:list| style |
| 891 | output. |
| 892 | |
| 893 | ============================================================================== |
| 894 | 6. Ex special characters *cmdline-special* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 895 | |
Bram Moolenaar | 8fa0445 | 2005-12-23 22:13:51 +0000 | [diff] [blame] | 896 | Note: These are special characters in the executed command line. If you want |
| 897 | to insert special things while typing you can use the CTRL-R command. For |
| 898 | example, "%" stands for the current file name, while CTRL-R % inserts the |
| 899 | current file name right away. See |c_CTRL-R|. |
| 900 | |
Bram Moolenaar | fc39ecf | 2015-08-11 20:34:49 +0200 | [diff] [blame] | 901 | Note: If you want to avoid the effects of special characters in a Vim script |
| 902 | you may want to use |fnameescape()|. Also see |`=|. |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 903 | |
Bram Moolenaar | 8fa0445 | 2005-12-23 22:13:51 +0000 | [diff] [blame] | 904 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 905 | In Ex commands, at places where a file name can be used, the following |
| 906 | characters have a special meaning. These can also be used in the expression |
Bram Moolenaar | fc39ecf | 2015-08-11 20:34:49 +0200 | [diff] [blame] | 907 | function |expand()|. |
Bram Moolenaar | d812df6 | 2008-11-09 12:46:09 +0000 | [diff] [blame] | 908 | % Is replaced with the current file name. *:_%* *c_%* |
| 909 | # Is replaced with the alternate file name. *:_#* *c_#* |
Bram Moolenaar | 3678208 | 2013-11-28 13:53:34 +0100 | [diff] [blame] | 910 | This is remembered for every window. |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 911 | #n (where n is a number) is replaced with *:_#0* *:_#n* |
| 912 | the file name of buffer n. "#0" is the same as "#". *c_#n* |
Bram Moolenaar | d812df6 | 2008-11-09 12:46:09 +0000 | [diff] [blame] | 913 | ## Is replaced with all names in the argument list *:_##* *c_##* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 914 | concatenated, separated by spaces. Each space in a name |
| 915 | is preceded with a backslash. |
Bram Moolenaar | d812df6 | 2008-11-09 12:46:09 +0000 | [diff] [blame] | 916 | #<n (where n is a number > 0) is replaced with old *:_#<* *c_#<* |
| 917 | file name n. See |:oldfiles| or |v:oldfiles| to get the |
| 918 | number. *E809* |
Bram Moolenaar | db84e45 | 2010-08-15 13:50:43 +0200 | [diff] [blame] | 919 | {only when compiled with the |+eval| and |+viminfo| features} |
Bram Moolenaar | 7e6a515 | 2021-01-02 16:39:53 +0100 | [diff] [blame] | 920 | In |Vim9-script| # is used to start a comment, use %% for the alternate file |
| 921 | name: |
| 922 | % Is replaced with the current file name. |
| 923 | %% Is replaced with the alternate file name. *:_%%* *c_%%* |
| 924 | %%n (where n is a number) is replaced with *:_%%0* *:_%%n* |
| 925 | the file name of buffer n. "%%0" is the same as "%%". *c_%%n* |
| 926 | %%% Is replaced with all names in the argument *:_%%%* *c_%%%#* |
| 927 | list concatenated, separated by spaces. |
| 928 | %%<n (where n is a number > 0) is replaced with old *:_%%<* *c_%%<* |
| 929 | file name n. |
Bram Moolenaar | d812df6 | 2008-11-09 12:46:09 +0000 | [diff] [blame] | 930 | |
| 931 | Note that these, except "#<n", give the file name as it was typed. If an |
| 932 | absolute path is needed (when using the file name from a different directory), |
| 933 | you need to add ":p". See |filename-modifiers|. |
| 934 | |
| 935 | The "#<n" item returns an absolute path, but it will start with "~/" for files |
| 936 | below your home directory. |
| 937 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 938 | Note that backslashes are inserted before spaces, so that the command will |
| 939 | correctly interpret the file name. But this doesn't happen for shell |
Bram Moolenaar | d812df6 | 2008-11-09 12:46:09 +0000 | [diff] [blame] | 940 | commands. For those you probably have to use quotes (this fails for files |
| 941 | that contain a quote and wildcards): > |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 942 | :!ls "%" |
| 943 | :r !spell "%" |
| 944 | |
| 945 | To avoid the special meaning of '%' and '#' insert a backslash before it. |
| 946 | Detail: The special meaning is always escaped when there is a backslash before |
| 947 | it, no matter how many backslashes. |
| 948 | you type: result ~ |
| 949 | # alternate.file |
| 950 | \# # |
| 951 | \\# \# |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 952 | Also see |`=|. |
Bram Moolenaar | fc39ecf | 2015-08-11 20:34:49 +0200 | [diff] [blame] | 953 | |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 954 | *E499* *E500* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 955 | Note: these are typed literally, they are not special keys! |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 956 | *:<cword>* *<cword>* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 957 | <cword> is replaced with the word under the cursor (like |star|) |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 958 | *:<cWORD>* *<cWORD>* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 959 | <cWORD> is replaced with the WORD under the cursor (see |WORD|) |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 960 | *:<cexpr>* *<cexpr>* |
Bram Moolenaar | 65f0847 | 2017-09-10 18:16:20 +0200 | [diff] [blame] | 961 | <cexpr> is replaced with the word under the cursor, including more |
| 962 | to form a C expression. E.g., when the cursor is on "arg" |
| 963 | of "ptr->arg" then the result is "ptr->arg"; when the |
| 964 | cursor is on "]" of "list[idx]" then the result is |
| 965 | "list[idx]". This is used for |v:beval_text|. |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 966 | *:<cfile>* *<cfile>* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 967 | <cfile> is replaced with the path name under the cursor (like what |
| 968 | |gf| uses) |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 969 | *:<afile>* *<afile>* |
Bram Moolenaar | 81af925 | 2010-12-10 20:35:50 +0100 | [diff] [blame] | 970 | <afile> When executing autocommands, is replaced with the file name |
Bram Moolenaar | 01164a6 | 2017-11-02 22:58:42 +0100 | [diff] [blame] | 971 | of the buffer being manipulated, or the file for a read or |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 972 | write. *E495* |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 973 | *:<abuf>* *<abuf>* |
Bram Moolenaar | 81af925 | 2010-12-10 20:35:50 +0100 | [diff] [blame] | 974 | <abuf> When executing autocommands, is replaced with the currently |
Bram Moolenaar | 10e8ff9 | 2023-06-10 21:40:39 +0100 | [diff] [blame] | 975 | effective buffer number. It is not set for all events, |
| 976 | also see |bufnr()|. For ":r file" and ":so file" it is the |
| 977 | current buffer, the file being read/sourced is not in a |
| 978 | buffer. *E496* |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 979 | *:<amatch>* *<amatch>* |
Bram Moolenaar | 81af925 | 2010-12-10 20:35:50 +0100 | [diff] [blame] | 980 | <amatch> When executing autocommands, is replaced with the match for |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 981 | which this autocommand was executed. *E497* |
Bram Moolenaar | 4700398 | 2021-12-05 21:54:04 +0000 | [diff] [blame] | 982 | It differs from <afile> when the file name isn't used to |
| 983 | match with (for FileType, Syntax and SpellFileMissing |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 984 | events). |
Bram Moolenaar | 4700398 | 2021-12-05 21:54:04 +0000 | [diff] [blame] | 985 | When the match is with a file name, it is expanded to the |
| 986 | full path. |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 987 | *:<sfile>* *<sfile>* |
Bram Moolenaar | 8a3b805 | 2022-06-26 12:21:15 +0100 | [diff] [blame] | 988 | <sfile> When executing a `:source` command, is replaced with the |
Bram Moolenaar | fc39ecf | 2015-08-11 20:34:49 +0200 | [diff] [blame] | 989 | file name of the sourced file. *E498* |
Bram Moolenaar | 6304be6 | 2021-11-27 10:57:26 +0000 | [diff] [blame] | 990 | When executing a legacy function, is replaced with the call |
| 991 | stack, as with <stack> (this is for backwards |
LemonBoy | 6013d00 | 2022-04-09 21:42:10 +0100 | [diff] [blame] | 992 | compatibility, using <stack> or <script> is preferred). |
Bram Moolenaar | 6304be6 | 2021-11-27 10:57:26 +0000 | [diff] [blame] | 993 | In Vim9 script using <sfile> in a function gives error |
| 994 | *E1245* . |
Bram Moolenaar | ca63501 | 2015-09-25 20:34:21 +0200 | [diff] [blame] | 995 | Note that filename-modifiers are useless when <sfile> is |
Bram Moolenaar | a5d0423 | 2020-07-26 15:37:02 +0200 | [diff] [blame] | 996 | not used inside a script. |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 997 | *:<stack>* *<stack>* |
Bram Moolenaar | a5d0423 | 2020-07-26 15:37:02 +0200 | [diff] [blame] | 998 | <stack> is replaced with the call stack, using |
| 999 | "function {function-name}[{lnum}]" for a function line |
| 1000 | and "script {file-name}[{lnum}]" for a script line, and |
| 1001 | ".." in between items. E.g.: |
| 1002 | "function {function-name1}[{lnum}]..{function-name2}[{lnum}]" |
Bram Moolenaar | 2f0936c | 2022-01-08 21:51:59 +0000 | [diff] [blame] | 1003 | If there is no call stack you get error *E489* . |
LemonBoy | 6013d00 | 2022-04-09 21:42:10 +0100 | [diff] [blame] | 1004 | *:<script>* *<script>* |
| 1005 | <script> When executing a `:source` command, is replaced with the file |
| 1006 | name of the sourced file. When executing a function, is |
| 1007 | replaced with the file name of the script where it is |
| 1008 | defined. |
| 1009 | If the file name cannot be determined you get error *E1274* . |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 1010 | *:<slnum>* *<slnum>* |
Bram Moolenaar | 8a3b805 | 2022-06-26 12:21:15 +0100 | [diff] [blame] | 1011 | <slnum> When executing a `:source` command, is replaced with the |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 1012 | line number. *E842* |
Bram Moolenaar | 81af925 | 2010-12-10 20:35:50 +0100 | [diff] [blame] | 1013 | When executing a function it's the line number relative to |
| 1014 | the start of the function. |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 1015 | *:<sflnum>* *<sflnum>* |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 1016 | <sflnum> When executing a script, is replaced with the line number. |
| 1017 | It differs from <slnum> in that <sflnum> is replaced with |
| 1018 | the script line number in any situation. *E961* |
Bram Moolenaar | 1d59aa1 | 2020-09-19 18:50:13 +0200 | [diff] [blame] | 1019 | *:<client>* *<client>* |
| 1020 | <client> is replaced with the {clinetid} of the last received |
| 1021 | message in |server2client()| |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1022 | |
| 1023 | *filename-modifiers* |
Bram Moolenaar | 251835e | 2014-02-24 02:51:51 +0100 | [diff] [blame] | 1024 | *:_%:* *::8* *::p* *::.* *::~* *::h* *::t* *::r* *::e* *::s* *::gs* *::S* |
| 1025 | *%:8* *%:p* *%:.* *%:~* *%:h* *%:t* *%:r* *%:e* *%:s* *%:gs* *%:S* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1026 | The file name modifiers can be used after "%", "#", "#n", "<cfile>", "<sfile>", |
| 1027 | "<afile>" or "<abuf>". They are also used with the |fnamemodify()| function. |
Bram Moolenaar | 30e9b3c | 2019-09-07 16:24:12 +0200 | [diff] [blame] | 1028 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1029 | These modifiers can be given, in this order: |
| 1030 | :p Make file name a full path. Must be the first modifier. Also |
| 1031 | changes "~/" (and "~user/" for Unix and VMS) to the path for |
| 1032 | the home directory. If the name is a directory a path |
| 1033 | separator is added at the end. For a file name that does not |
| 1034 | exist and does not have an absolute path the result is |
Bram Moolenaar | 30b6581 | 2012-07-12 22:01:11 +0200 | [diff] [blame] | 1035 | unpredictable. On MS-Windows an 8.3 filename is expanded to |
| 1036 | the long name. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1037 | :8 Converts the path to 8.3 short format (currently only on |
Bram Moolenaar | 30b6581 | 2012-07-12 22:01:11 +0200 | [diff] [blame] | 1038 | MS-Windows). Will act on as much of a path that is an |
| 1039 | existing path. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1040 | :~ Reduce file name to be relative to the home directory, if |
| 1041 | possible. File name is unmodified if it is not below the home |
| 1042 | directory. |
| 1043 | :. Reduce file name to be relative to current directory, if |
| 1044 | possible. File name is unmodified if it is not below the |
Bram Moolenaar | d816cd9 | 2020-02-04 22:23:09 +0100 | [diff] [blame] | 1045 | current directory. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1046 | For maximum shortness, use ":~:.". |
| 1047 | :h Head of the file name (the last component and any separators |
| 1048 | removed). Cannot be used with :e, :r or :t. |
| 1049 | Can be repeated to remove several components at the end. |
| 1050 | When the file name ends in a path separator, only the path |
| 1051 | separator is removed. Thus ":p:h" on a directory name results |
| 1052 | on the directory name itself (without trailing slash). |
| 1053 | When the file name is an absolute path (starts with "/" for |
Bram Moolenaar | 5666fcd | 2019-12-26 14:35:26 +0100 | [diff] [blame] | 1054 | Unix; "x:\" for Win32; "drive:" for Amiga), that part is not |
Bram Moolenaar | 6f345a1 | 2019-12-17 21:27:18 +0100 | [diff] [blame] | 1055 | removed. When there is no head (path is relative to current |
| 1056 | directory) the result is empty. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1057 | :t Tail of the file name (last component of the name). Must |
| 1058 | precede any :r or :e. |
| 1059 | :r Root of the file name (the last extension removed). When |
| 1060 | there is only an extension (file name that starts with '.', |
| 1061 | e.g., ".vimrc"), it is not removed. Can be repeated to remove |
| 1062 | several extensions (last one first). |
| 1063 | :e Extension of the file name. Only makes sense when used alone. |
| 1064 | When there is no extension the result is empty. |
| 1065 | When there is only an extension (file name that starts with |
| 1066 | '.'), the result is empty. Can be repeated to include more |
| 1067 | extensions. If there are not enough extensions (but at least |
| 1068 | one) as much as possible are included. |
| 1069 | :s?pat?sub? |
| 1070 | Substitute the first occurrence of "pat" with "sub". This |
| 1071 | works like the |:s| command. "pat" is a regular expression. |
| 1072 | Any character can be used for '?', but it must not occur in |
| 1073 | "pat" or "sub". |
| 1074 | After this, the previous modifiers can be used again. For |
| 1075 | example ":p", to make a full path after the substitution. |
| 1076 | :gs?pat?sub? |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 1077 | Substitute all occurrences of "pat" with "sub". Otherwise |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1078 | this works like ":s". |
Bram Moolenaar | fc39ecf | 2015-08-11 20:34:49 +0200 | [diff] [blame] | 1079 | :S Escape special characters for use with a shell command (see |
Bram Moolenaar | 251835e | 2014-02-24 02:51:51 +0100 | [diff] [blame] | 1080 | |shellescape()|). Must be the last one. Examples: > |
| 1081 | :!dir <cfile>:S |
| 1082 | :call system('chmod +w -- ' . expand('%:S')) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1083 | |
| 1084 | Examples, when the file name is "src/version.c", current dir |
| 1085 | "/home/mool/vim": > |
| 1086 | :p /home/mool/vim/src/version.c |
| 1087 | :p:. src/version.c |
| 1088 | :p:~ ~/vim/src/version.c |
| 1089 | :h src |
| 1090 | :p:h /home/mool/vim/src |
| 1091 | :p:h:h /home/mool/vim |
| 1092 | :t version.c |
| 1093 | :p:t version.c |
| 1094 | :r src/version |
| 1095 | :p:r /home/mool/vim/src/version |
| 1096 | :t:r version |
| 1097 | :e c |
| 1098 | :s?version?main? src/main.c |
| 1099 | :s?version?main?:p /home/mool/vim/src/main.c |
| 1100 | :p:gs?/?\\? \home\mool\vim\src\version.c |
| 1101 | |
| 1102 | Examples, when the file name is "src/version.c.gz": > |
| 1103 | :p /home/mool/vim/src/version.c.gz |
| 1104 | :e gz |
| 1105 | :e:e c.gz |
| 1106 | :e:e:e c.gz |
| 1107 | :e:e:r c |
| 1108 | :r src/version.c |
| 1109 | :r:e c |
| 1110 | :r:r src/version |
| 1111 | :r:r:r src/version |
| 1112 | < |
| 1113 | *extension-removal* *:_%<* |
| 1114 | If a "<" is appended to "%", "#", "#n" or "CTRL-V p" the extension of the file |
| 1115 | name is removed (everything after and including the last '.' in the file |
| 1116 | name). This is included for backwards compatibility with version 3.0, the |
| 1117 | ":r" form is preferred. Examples: > |
| 1118 | |
| 1119 | % current file name |
| 1120 | %< current file name without extension |
| 1121 | # alternate file name for current window |
| 1122 | #< idem, without extension |
| 1123 | #31 alternate file number 31 |
| 1124 | #31< idem, without extension |
| 1125 | <cword> word under the cursor |
| 1126 | <cWORD> WORD under the cursor (see |WORD|) |
| 1127 | <cfile> path name under the cursor |
| 1128 | <cfile>< idem, without extension |
| 1129 | |
| 1130 | Note: Where a file name is expected wildcards expansion is done. On Unix the |
| 1131 | shell is used for this, unless it can be done internally (for speed). |
Bram Moolenaar | fc39ecf | 2015-08-11 20:34:49 +0200 | [diff] [blame] | 1132 | Unless in |restricted-mode|, backticks work also, like in > |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1133 | :n `echo *.c` |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1134 | But expansion is only done if there are any wildcards before expanding the |
| 1135 | '%', '#', etc.. This avoids expanding wildcards inside a file name. If you |
| 1136 | want to expand the result of <cfile>, add a wildcard character to it. |
| 1137 | Examples: (alternate file name is "?readme?") |
| 1138 | command expands to ~ |
| 1139 | :e # :e ?readme? |
| 1140 | :e `ls #` :e {files matching "?readme?"} |
| 1141 | :e #.* :e {files matching "?readme?.*"} |
| 1142 | :cd <cfile> :cd {file name under cursor} |
| 1143 | :cd <cfile>* :cd {file name under cursor plus "*" and then expanded} |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 1144 | Also see |`=|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1145 | |
| 1146 | When the expanded argument contains a "!" and it is used for a shell command |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 1147 | (":!cmd", ":r !cmd" or ":w !cmd"), the "!" is escaped with a backslash to |
| 1148 | avoid it being expanded into a previously used command. When the 'shell' |
| 1149 | option contains "sh", this is done twice, to avoid the shell trying to expand |
| 1150 | the "!". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1151 | |
| 1152 | *filename-backslash* |
Bram Moolenaar | 6f345a1 | 2019-12-17 21:27:18 +0100 | [diff] [blame] | 1153 | For filesystems that use a backslash as directory separator (MS-Windows), it's |
| 1154 | a bit difficult to recognize a backslash that is used to escape the special |
| 1155 | meaning of the next character. The general rule is: If the backslash is |
| 1156 | followed by a normal file name character, it does not have a special meaning. |
| 1157 | Therefore "\file\foo" is a valid file name, you don't have to type the |
| 1158 | backslash twice. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1159 | |
| 1160 | An exception is the '$' sign. It is a valid character in a file name. But |
| 1161 | to avoid a file name like "$home" to be interpreted as an environment variable, |
| 1162 | it needs to be preceded by a backslash. Therefore you need to use "/\$home" |
| 1163 | for the file "$home" in the root directory. A few examples: |
| 1164 | |
| 1165 | FILE NAME INTERPRETED AS ~ |
| 1166 | $home expanded to value of environment var $home |
| 1167 | \$home file "$home" in current directory |
| 1168 | /\$home file "$home" in root directory |
| 1169 | \\$home file "\\", followed by expanded $home |
Bram Moolenaar | fc39ecf | 2015-08-11 20:34:49 +0200 | [diff] [blame] | 1170 | |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 1171 | Also see |`=|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1172 | |
| 1173 | ============================================================================== |
Bram Moolenaar | ac7bd63 | 2013-03-19 11:35:58 +0100 | [diff] [blame] | 1174 | 7. Command-line window *cmdline-window* *cmdwin* |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 1175 | *command-line-window* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1176 | In the command-line window the command line can be edited just like editing |
| 1177 | text in any window. It is a special kind of window, because you cannot leave |
| 1178 | it in a normal way. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1179 | |
| 1180 | |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 1181 | OPEN *c_CTRL-F* *q:* *q/* *q?* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1182 | |
| 1183 | There are two ways to open the command-line window: |
| 1184 | 1. From Command-line mode, use the key specified with the 'cedit' option. |
| 1185 | The default is CTRL-F when 'compatible' is not set. |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 1186 | 2. From Normal mode, use the "q:", "q/" or "q?" command. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1187 | This starts editing an Ex command-line ("q:") or search string ("q/" or |
| 1188 | "q?"). Note that this is not possible while recording is in progress (the |
| 1189 | "q" stops recording then). |
| 1190 | |
| 1191 | When the window opens it is filled with the command-line history. The last |
| 1192 | line contains the command as typed so far. The left column will show a |
| 1193 | character that indicates the type of command-line being edited, see |
| 1194 | |cmdwin-char|. |
| 1195 | |
| 1196 | Vim will be in Normal mode when the editor is opened, except when 'insertmode' |
| 1197 | is set. |
Bram Moolenaar | 2ecbe53 | 2022-07-29 21:36:21 +0100 | [diff] [blame] | 1198 | *E1292* |
| 1199 | Once a command-line window is open it is not possible to open another one. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1200 | |
| 1201 | The height of the window is specified with 'cmdwinheight' (or smaller if there |
| 1202 | is no room). The window is always full width and is positioned just above the |
| 1203 | command-line. |
| 1204 | |
| 1205 | |
| 1206 | EDIT |
| 1207 | |
| 1208 | You can now use commands to move around and edit the text in the window. Both |
| 1209 | in Normal mode and Insert mode. |
| 1210 | |
| 1211 | It is possible to use ":", "/" and other commands that use the command-line, |
| 1212 | but it's not possible to open another command-line window then. There is no |
| 1213 | nesting. |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 1214 | *E11* *E1188* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1215 | The command-line window is not a normal window. It is not possible to move to |
| 1216 | another window or edit another buffer. All commands that would do this are |
| 1217 | disabled in the command-line window. Of course it _is_ possible to execute |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 1218 | any command that you entered in the command-line window. Other text edits are |
| 1219 | discarded when closing the window. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1220 | |
| 1221 | |
| 1222 | CLOSE *E199* |
| 1223 | |
| 1224 | There are several ways to leave the command-line window: |
| 1225 | |
| 1226 | <CR> Execute the command-line under the cursor. Works both in |
| 1227 | Insert and in Normal mode. |
| 1228 | CTRL-C Continue in Command-line mode. The command-line under the |
| 1229 | cursor is used as the command-line. Works both in Insert and |
Bram Moolenaar | bc2eada | 2017-01-02 21:27:47 +0100 | [diff] [blame] | 1230 | in Normal mode. There is no redraw, thus the window will |
| 1231 | remain visible. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1232 | :quit Discard the command line and go back to Normal mode. |
Bram Moolenaar | 3d1cde8 | 2020-08-15 18:55:18 +0200 | [diff] [blame] | 1233 | ":close", CTRL-W c, ":exit", ":xit" and CTRL-\ CTRL-N also |
| 1234 | work. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1235 | :qall Quit Vim, unless there are changes in some buffer. |
| 1236 | :qall! Quit Vim, discarding changes to any buffer. |
| 1237 | |
| 1238 | Once the command-line window is closed the old window sizes are restored. The |
| 1239 | executed command applies to the window and buffer where the command-line was |
| 1240 | started from. This works as if the command-line window was not there, except |
| 1241 | that there will be an extra screen redraw. |
| 1242 | The buffer used for the command-line window is deleted. Any changes to lines |
| 1243 | other than the one that is executed with <CR> are lost. |
| 1244 | |
Bram Moolenaar | 36fc535 | 2006-03-04 21:49:37 +0000 | [diff] [blame] | 1245 | If you would like to execute the command under the cursor and then have the |
| 1246 | command-line window open again, you may find this mapping useful: > |
| 1247 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 1248 | :autocmd CmdwinEnter * map <buffer> <F5> <CR>q: |
Bram Moolenaar | 36fc535 | 2006-03-04 21:49:37 +0000 | [diff] [blame] | 1249 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1250 | |
| 1251 | VARIOUS |
| 1252 | |
| 1253 | The command-line window cannot be used: |
| 1254 | - when there already is a command-line window (no nesting) |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 1255 | - for entering an encryption key or when using inputsecret() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1256 | |
| 1257 | Some options are set when the command-line window is opened: |
| 1258 | 'filetype' "vim", when editing an Ex command-line; this starts Vim syntax |
| 1259 | highlighting if it was enabled |
| 1260 | 'rightleft' off |
| 1261 | 'modifiable' on |
| 1262 | 'buftype' "nofile" |
| 1263 | 'swapfile' off |
| 1264 | |
| 1265 | It is allowed to write the buffer contents to a file. This is an easy way to |
| 1266 | save the command-line history and read it back later. |
| 1267 | |
| 1268 | If the 'wildchar' option is set to <Tab>, and the command-line window is used |
| 1269 | for an Ex command, then two mappings will be added to use <Tab> for completion |
| 1270 | in the command-line window, like this: > |
Bram Moolenaar | d592deb | 2022-06-17 15:42:40 +0100 | [diff] [blame] | 1271 | :inoremap <buffer> <Tab> <C-X><C-V> |
| 1272 | :nnoremap <buffer> <Tab> a<C-X><C-V> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1273 | Note that hitting <Tab> in Normal mode will do completion on the next |
| 1274 | character. That way it works at the end of the line. |
| 1275 | If you don't want these mappings, disable them with: > |
| 1276 | au CmdwinEnter [:>] iunmap <Tab> |
| 1277 | au CmdwinEnter [:>] nunmap <Tab> |
| 1278 | You could put these lines in your vimrc file. |
| 1279 | |
| 1280 | While in the command-line window you cannot use the mouse to put the cursor in |
| 1281 | another window, or drag statuslines of other windows. You can drag the |
| 1282 | statusline of the command-line window itself and the statusline above it. |
| 1283 | Thus you can resize the command-line window, but not others. |
| 1284 | |
Bram Moolenaar | fb53927 | 2014-08-22 19:21:47 +0200 | [diff] [blame] | 1285 | The |getcmdwintype()| function returns the type of the command-line being |
| 1286 | edited as described in |cmdwin-char|. |
| 1287 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1288 | |
| 1289 | AUTOCOMMANDS |
| 1290 | |
Bram Moolenaar | 96e38a8 | 2019-09-09 18:35:33 +0200 | [diff] [blame] | 1291 | Two autocommand events are used: |CmdwinEnter| and |CmdwinLeave|. You can use |
| 1292 | the Cmdwin events to do settings specifically for the command-line window. |
| 1293 | Be careful not to cause side effects! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1294 | Example: > |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 1295 | :au CmdwinEnter : let b:cpt_save = &cpt | set cpt=. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1296 | :au CmdwinLeave : let &cpt = b:cpt_save |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 1297 | This sets 'complete' to use completion in the current window for |i_CTRL-N|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1298 | Another example: > |
| 1299 | :au CmdwinEnter [/?] startinsert |
| 1300 | This will make Vim start in Insert mode in the command-line window. |
| 1301 | |
| 1302 | *cmdwin-char* |
| 1303 | The character used for the pattern indicates the type of command-line: |
| 1304 | : normal Ex command |
| 1305 | > debug mode command |debug-mode| |
| 1306 | / forward search string |
| 1307 | ? backward search string |
| 1308 | = expression for "= |expr-register| |
| 1309 | @ string for |input()| |
| 1310 | - text for |:insert| or |:append| |
| 1311 | |
Bram Moolenaar | 91f84f6 | 2018-07-29 15:07:52 +0200 | [diff] [blame] | 1312 | vim:tw=78:ts=8:noet:ft=help:norl: |