various.txt (34484B)
1 *various.txt* For Vim version 9.2. Last change: 2026 Sep 30 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7 Various commands *various* 8 9 1. Various commands |various-cmds| 10 2. Using Vim like less or more |less| 11 12 ============================================================================== 13 1. Various commands *various-cmds* 14 15 *CTRL-L* 16 CTRL-L Clear and redraw the screen. The redraw may happen 17 later, after processing typeahead. 18 19 *:redr* *:redraw* 20 :redr[aw][!] Redraw the screen right now. When ! is included it is 21 cleared first. 22 It can be used to redraw the screen in a script 23 or function (or a mapping if 'lazyredraw' is set). 24 25 *:redraws* *:redrawstatus* 26 :redraws[tatus][!] Redraw the status line of the current window. When ! 27 is included all status lines are redrawn. 28 Useful to update the status line(s) when 'statusline' 29 includes an item that doesn't cause automatic 30 updating. 31 When the last window has no status line the ruler is 32 redrawn instead, this is useful when 'rulerformat' 33 includes such an item. 34 If the command line is being edited the redraw is 35 postponed until later. 36 37 *:redrawt* *:redrawtabline* 38 :redrawt[abline] Redraw the tabline. Useful to update the tabline when 39 'tabline' includes an item that doesn't trigger 40 automatic updating. 41 42 *E1547* *:redrawtabp* *:redrawtabpanel* 43 :redrawtabp[anel] Redraw the tabpanel Useful to update the tabpanel 44 when 'tabpanel' includes an item that doesn't trigger 45 automatic updating. 46 47 *N<Del>* 48 <Del> When entering a number: Remove the last digit. 49 Note: if you like to use <BS> for this, add this 50 mapping to your .vimrc: > 51 :map CTRL-V <BS> CTRL-V <Del> 52 < See |:fixdel| if your <Del> key does not do what you 53 want. 54 55 :as[cii] or *ga* *:as* *:ascii* 56 ga Print the ascii value of the character under the 57 cursor in decimal, hexadecimal and octal. 58 Mnemonic: Get Ascii value. 59 60 For example, when the cursor is on a 'R': 61 <R> 82, Hex 52, Octal 122 ~ 62 When the character is a non-standard ASCII character, 63 but printable according to the 'isprint' option, the 64 non-printable version is also given. 65 66 When the character is larger than 127: 67 <<81>> 129, Hex 0081, Octal 201 ~ 68 <p> 254, Hex 00fe, Octal 376 ~ 69 (where <p> is a special character) 70 71 The <Nul> character in a file is stored internally as 72 <NL>, but it will be shown as: 73 <^@> 0, Hex 00, Octal 000 ~ 74 75 If the character has composing characters these are 76 also shown. The value of 'maxcombine' doesn't matter. 77 78 If the character can be inserted as a digraph, also 79 output the two characters that can be used to create 80 the character: 81 <ö> 246, Hex 00f6, Oct 366, Digr o: ~ 82 This shows you can type CTRL-K o : to insert ö. 83 84 *g8* 85 g8 Print the hex values of the bytes used in the 86 character under the cursor, assuming it is in |UTF-8| 87 encoding. This also shows composing characters. The 88 value of 'maxcombine' doesn't matter. 89 Example of a character with two composing characters: 90 e0 b8 81 + e0 b8 b9 + e0 b9 89 ~ 91 92 *8g8* 93 8g8 Find an illegal UTF-8 byte sequence at or after the 94 cursor. This works in two situations: 95 1. when 'encoding' is any 8-bit encoding 96 2. when 'encoding' is "utf-8" and 'fileencoding' is 97 any 8-bit encoding 98 Thus it can be used when editing a file that was 99 supposed to be UTF-8 but was read as if it is an 8-bit 100 encoding because it contains illegal bytes. 101 Does not wrap around the end of the file. 102 Note that when the cursor is on an illegal byte or the 103 cursor is halfway a multibyte character the command 104 won't move the cursor. 105 106 *:p* *:pr* *:print* *E749* 107 :[range]p[rint] [flags] 108 Print [range] lines (default current line). Can also 109 be spelled `:[range]|` due to Vi compatibility (see 110 |:bar|). Gives an error in an empty buffer. 111 Note: If you are looking for a way to print your text 112 on paper see |:hardcopy|. In the GUI you can use the 113 File.Print menu entry. 114 See |ex-flags| for [flags]. 115 The |:filter| command can be used to only show lines 116 matching a pattern. 117 118 :[range]p[rint] {count} [flags] 119 Print {count} lines, starting with [range] (default 120 current line |cmdline-ranges|). 121 See |ex-flags| for [flags]. 122 123 *:P* *:Print* 124 :[range]P[rint] [count] [flags] 125 Just as ":print". Was apparently added to Vi for 126 people that keep the shift key pressed too long... 127 This command is not supported in |Vim9| script. 128 Note: A user command can overrule this command. 129 See |ex-flags| for [flags]. 130 131 *:l* *:list* 132 :[range]l[ist] [count] [flags] 133 Same as :print, but display unprintable characters 134 with '^' and put $ after the line. This can be 135 further changed with the 'listchars' option. 136 See |ex-flags| for [flags]. 137 138 *:nu* *:number* 139 :[range]nu[mber] [count] [flags] 140 Same as :print, but precede each line with its line 141 number. (See also 'highlight' and 'numberwidth' 142 option). 143 See |ex-flags| for [flags]. 144 145 *:#* 146 :[range]# [count] [flags] 147 synonym for :number. 148 149 *:#!* *vim-shebang* 150 :#!{anything} Ignored, so that you can start a Vim script with: > 151 #!vim -S 152 let mylogbook='$HOME/logbook.md' 153 exe $':e {mylogbook}' 154 $ 155 put ='## ' .. strftime('%d. %b %Y') 156 norm! o 157 < 158 Make that script executable and run it to create a 159 new diary entry. 160 161 *:z* *E144* 162 :[range]z[+-^.=][count] Display several lines of text surrounding the line 163 specified with [range], or around the current line 164 if there is no [range]. 165 166 If there is a [count], that's how many lines you'll 167 see; if there is no [count] and only one window then 168 twice the value of the 'scroll' option is used, 169 otherwise the current window height minus 3 is used. 170 This is the value of "scr" in the table below. 171 172 If there is a [count] the 'window' option is set to 173 its value. 174 175 :z can be used either alone or followed by any of 176 several marks. These have the following effect: 177 178 mark first line last line new cursor line ~ 179 ---- ---------- --------- ------------ 180 + current line 1 scr forward 1 scr forward 181 - 1 scr back current line current line 182 ^ 2 scr back 1 scr back 1 scr back 183 . 1/2 scr back 1/2 scr fwd 1/2 scr fwd 184 = 1/2 scr back 1/2 scr fwd current line 185 186 Specifying no mark at all is the same as "+". 187 If the mark is "=", a line of dashes is printed 188 around the current line. 189 190 If the 'number' option is set, absolute line numbers 191 will be included in the output. 192 193 *:z!* 194 :[range]z![+-^.=][count] 195 Like ":z", but when [count] is not specified, it 196 defaults to the Vim window height minus one. 197 198 :[range]z[!]#[+-^.=][count] *:z#* 199 Like ":z" or ":z!", but number the lines. 200 201 *:=* 202 := [flags] Print the last line number. 203 See |ex-flags| for [flags]. 204 205 :{range}= [flags] Prints the last line number in {range}. For example, 206 this prints the current line number: > 207 :.= 208 < See |ex-flags| for [flags]. 209 210 :norm[al][!] {commands} *:norm* *:normal* 211 Execute Normal mode commands {commands}. This makes 212 it possible to execute Normal mode commands typed on 213 the command-line. {commands} are executed like they 214 are typed. For undo all commands are undone together. 215 Execution stops when an error is encountered. 216 217 If the [!] is given, mappings will not be used. 218 Without it, when this command is called from a 219 non-remappable mapping (|:noremap|), the argument can 220 be mapped anyway. 221 222 {commands} should be a complete command. If 223 {commands} does not finish a command, the last one 224 will be aborted as if <Esc> or <C-C> was typed. 225 This implies that an insert command must be completed 226 (to start Insert mode, see |:startinsert|). A ":" 227 command must be completed as well. And you can't use 228 "Q" or "gQ" to start Ex mode. 229 230 The display is not updated while ":normal" is busy. 231 232 {commands} cannot start with a space. Put a count of 233 1 (one) before it, "1 " is one space. 234 235 The 'insertmode' option is ignored for {commands}. 236 237 This command cannot be followed by another command, 238 since any '|' is considered part of the command. 239 240 This command can be used recursively, but the depth is 241 limited by 'maxmapdepth'. 242 243 An alternative is to use |:execute|, which uses an 244 expression as argument. This allows the use of 245 printable characters to represent special characters. 246 247 Example: > 248 :exe "normal \<c-w>\<c-w>" 249 250 :{range}norm[al][!] {commands} *:normal-range* 251 Execute Normal mode commands {commands} for each line 252 in the {range}. Before executing the {commands}, the 253 cursor is positioned in the first column of the range, 254 for each line. Otherwise it's the same as the 255 ":normal" command without a range. 256 257 *:sh* *:shell* *E371* 258 :sh[ell] This command starts a shell. When the shell exits 259 (after the "exit" command) you return to Vim. The 260 name for the shell command comes from 'shell' option. 261 *E360* 262 Note: This doesn't work when Vim on the Amiga was 263 started in QuickFix mode from a compiler, because the 264 compiler will have set stdin to a non-interactive 265 mode. 266 267 *:!cmd* *:!* 268 :!{cmd} Execute {cmd} with the shell. See also the 'shell' 269 and 'shelltype' option. For the filter command, see 270 |:range!|. 271 272 Vim builds command line using options 'shell', 'shcf', 273 'sxq' and 'shq' in the following order: 274 `&sh &shcf &sxq &shq {cmd} &shq &sxq` 275 So setting both 'sxq' and 'shq' is possible but rarely 276 useful. Additional escaping inside `{cmd}` may also 277 be due to 'sxe' option. 278 279 Also, all |cmdline-special| characters in {cmd} are 280 replaced by Vim before passing them to shell. 281 282 *E34* 283 Any '!' in {cmd} is replaced with the previous 284 external command (see also 'cpoptions'). But not when 285 there is a backslash before the '!', then that 286 backslash is removed. Example: ":!ls" followed by 287 ":!echo ! \! \\!" executes "echo ls ! \!". 288 289 A '|' in {cmd} is passed to the shell, you cannot use 290 it to append a Vim command. See |:bar|. 291 292 If {cmd} contains "%" it is expanded to the current 293 file name, "#" is expanded to the alternate file name. 294 Special characters in the file name are not escaped, 295 use quotes to avoid their special meaning: > 296 :!ls "%" 297 < If the file name contains a "$" then single quotes 298 might work better, but this only works if the file 299 name does not contain a single quote: > 300 :!ls '%' 301 < This should always work, but it's more typing: > 302 :exe "!ls " .. shellescape(expand("%"),1) 303 < To get a literal "%" or "#" prepend it with a 304 backslash. For example, to list all files starting 305 with "%": > 306 :!ls \%* 307 < 308 A newline character ends {cmd}, what follows is 309 interpreted as a following ":" command. However, if 310 there is a backslash before the newline it is removed 311 and {cmd} continues. It doesn't matter how many 312 backslashes are before the newline, only one is 313 removed. 314 315 On Unix the command normally runs in a non-interactive 316 shell. If you want an interactive shell to be used 317 (to use aliases) set 'shellcmdflag' to "-ic". 318 For Win32 also see |:!start|. 319 320 After the command has been executed, the timestamp and 321 size of the current file is checked |timestamp|. 322 323 Vim redraws the screen after the command is finished, 324 because it may have printed any text. This requires a 325 hit-enter prompt, so that you can read any messages. 326 To avoid this use: > 327 :silent !{cmd} 328 < The screen is not redrawn then, thus you have to use 329 CTRL-L or ":redraw!" if the command did display 330 something. However, this depends on what the |t_ti| 331 and |t_te| termcap entries are set to. 332 333 Hint: use |:terminal| command if you want to run {cmd} 334 in Vim window. `:term ++shell ++close {cmd}` could 335 serve as close approximation to what `:!{cmd}` does. 336 337 *:!!* 338 :!! Repeat last ":!{cmd}". 339 340 *:ve* *:ver* *:version* 341 :ve[rsion] Print the version number of the editor. If the 342 compiler used understands "__DATE__" the compilation 343 date is mentioned. Otherwise a fixed release-date is 344 shown. 345 The following lines contain information about which 346 features were enabled when Vim was compiled. When 347 there is a preceding '+', the feature is included, 348 when there is a '-' it is excluded. To change this, 349 you have to edit feature.h and recompile Vim. 350 To check for this in an expression, see |has()|. 351 Here is an overview of the features. 352 The first column shows the smallest version in which 353 they are included: 354 T tiny (always) 355 N normal 356 H huge 357 m manually enabled or depends on other features 358 - never, feature was removed 359 (none) system dependent 360 Thus if a feature is marked with "N", it is included 361 in the normal and huge versions of Vim. 362 363 *+feature-list* 364 *+acl* |ACL| support included 365 *+ARP* Amiga only: ARP support included 366 H *+arabic* |Arabic| language support 367 N *+autochdir* support 'autochdir' option 368 T *+autocmd* |:autocmd|, automatic commands. Always enabled since 369 8.0.1564 370 H *+autoservername* Automatically enable |clientserver| 371 m *+balloon_eval* |balloon-eval| support in the GUI. Included when 372 compiling with supported GUI (Motif, GTK, GUI) and 373 either Netbeans/Sun Workshop integration or |+eval| 374 feature. 375 H *+balloon_eval_term* |balloon-eval| support in the terminal, 376 'balloonevalterm' 377 N *+browse* |:browse| command 378 T *++builtin_terms* maximal terminals builtin |builtin-terms| Always 379 enabled since 9.0.0280 380 N *+byte_offset* support for 'o' flag in 'statusline' option, "go" 381 and ":goto" commands. 382 m *+channel* inter process communication |channel| 383 T *+cindent* 'cindent', C indenting; Always enabled 384 N *+clientserver* Unix and Win32: Remote invocation |clientserver| 385 *+clipboard* |clipboard| support compiled-in 386 *+clipboard_working* |clipboard| support compiled-in and working 387 *+clipboard_provider* |clipboard-providers| support compiled-in 388 T *+cmdline_compl* command line completion |cmdline-completion| 389 T *+cmdline_hist* command line history |cmdline-history| 390 T *+cmdline_info* 'showcmd' and 'ruler'; Always enabled since 391 9.0.0747 392 T *+cmdwin* |cmdline-window| support; Always enabled since 9.0.0657 393 T *+comments* 'comments' support 394 N *+conceal* "conceal" support, see |conceal| |:syn-conceal| etc. 395 N *+cryptv* encryption support |encryption| 396 H *+cscope* |cscope| support 397 T *+cursorbind* 'cursorbind' support 398 m *+cursorshape* |termcap-cursor-shape| support 399 m *+debug* Compiled for debugging. 400 N *+dialog_gui* Support for |:confirm| with GUI dialog. 401 N *+dialog_con* Support for |:confirm| with console dialog. 402 N *+dialog_con_gui* Support for |:confirm| with GUI and console dialog. 403 N *+diff* |vimdiff| and 'diff' 404 N *+digraphs* |digraphs| *E196* 405 *+directx* Win32 GUI only: DirectX and 'renderoptions' 406 *+dnd* Support for DnD into the "~ register |quote_~|. 407 H *+emacs_tags* |emacs-tags| files 408 N *+eval* expression evaluation |eval.txt| 409 T *+ex_extra* always on now, used to be for Vim's extra Ex commands 410 N *+extra_search* 'hlsearch' and 'incsearch' options. 411 - *+farsi* Removed: |farsi| language 412 T *+file_in_path* |gf|, |CTRL-W_f| and |<cfile>| Always enabled since 413 9.0.265 414 N *+find_in_path* include file searches: |[I|, |:isearch|, 415 |CTRL-W_CTRL-I|, |:checkpath|, etc. 416 N *+folding* |folding| 417 *+footer* |gui-footer| 418 *+fork* Unix only: |fork| shell commands 419 T *+float* Floating point support Always enabled since 9.0.0491 420 N *+gettext* message translations |multi-lang| 421 - *+GUI_Athena* Unix only: Athena |GUI| 422 *+GUI_neXtaw* Unix only: neXtaw |GUI| 423 *+GUI_GTK* Unix only: GTK+ |GUI| 424 *+GUI_Motif* Unix only: Motif |GUI| 425 *+GUI_Photon* QNX only: Photon |GUI| 426 m *+hangul_input* Hangul input support |hangul| 427 *+iconv* Compiled with the |iconv()| function 428 *+iconv/dyn* Likewise |iconv-dynamic| |/dyn| 429 H *+image* image rendering, |image| 430 H *+image_popup* popup window image rendering, |popup-image| 431 T *+insert_expand* |insert_expand| Insert mode completion 432 m *+ipv6* Support for IPv6 networking |channel| 433 m *+job* starting and stopping jobs |job| 434 T *+jumplist* |jumplist|; Always enabled since 8.2.3795 435 H *+keymap* 'keymap' 436 N *+lambda* |lambda| and |closure| 437 H *+langmap* 'langmap' 438 N *+libcall* |libcall()| 439 N *+linebreak* 'linebreak', 'breakat' and 'showbreak' 440 T *+lispindent* 'lisp' 441 T *+listcmds* Vim commands for the list of buffers |buffer-hidden| 442 and argument list |:argdelete| 443 T *+localmap* Support for mappings local to a buffer |:map-local| 444 m *+lua* |Lua| interface 445 m *+lua/dyn* |Lua| interface |/dyn| 446 N *+menu* |:menu| 447 N *+mksession* |:mksession| 448 T *+modify_fname* |filename-modifiers| 449 T *+mouse* Mouse handling |mouse-using| 450 N *+mouseshape* 'mouseshape' 451 N *+mouse_dec* Unix only: Dec terminal mouse handling |dec-mouse| 452 N *+mouse_gpm* Unix only: Linux console mouse handling |gpm-mouse| 453 m *+mouse_gpm/dyn* Same as |+mouse_gpm| with optional library dependency 454 |/dyn| 455 N *+mouse_jsbterm* JSB mouse handling |jsbterm-mouse| 456 N *+mouse_netterm* Unix only: netterm mouse handling |netterm-mouse| 457 N *+mouse_pterm* QNX only: pterm mouse handling |qnx-terminal| 458 N *+mouse_sysmouse* Unix only: *BSD console mouse handling |sysmouse| 459 N *+mouse_sgr* Unix only: sgr mouse handling |sgr-mouse| 460 N *+mouse_urxvt* Unix only: urxvt mouse handling |urxvt-mouse| 461 N *+mouse_xterm* Unix only: xterm mouse handling |xterm-mouse| 462 T *+multi_byte* Unicode support, 16 and 32 bit characters |multibyte|. 463 Always enabled since 8.1.0811 464 *+multi_byte_ime* Win32 input method for multibyte chars |multibyte-ime| 465 N *+multi_lang* non-English language support |multi-lang| 466 m *+mzscheme* Mzscheme interface |mzscheme| 467 m *+mzscheme/dyn* Mzscheme interface |mzscheme-dynamic| |/dyn| 468 m *+netbeans_intg* |netbeans| 469 T *+num64* 64-bit Number support |Number| 470 Always enabled since 8.2.0271, use v:numbersize to 471 check the actual size of a Number. 472 m *+ole* Win32 GUI only: |ole-interface| 473 N *+packages* Loading |packages| 474 T *+path_extra* Up/downwards search in 'path' and 'tags' Always 475 enabled since 9.0.0270 476 m *+perl* Perl interface |perl| 477 m *+perl/dyn* Perl interface |perl-dynamic| |/dyn| 478 N *+persistent_undo* Persistent undo |undo-persistence| 479 N *+popupwin* Popup windows |popup-window| 480 *+postscript* |:hardcopy| writes a PostScript file 481 *+pango* |:hardcopy| uses Pango and Cairo to render pages 482 N *+printer* |:hardcopy| command 483 H *+profile* |:profile| command 484 m *+python* Python 2 interface |python| 485 m *+python/dyn* Python 2 interface |python-dynamic| |/dyn| 486 m *+python3* Python 3 interface |python| 487 m *+python3/dyn* Python 3 interface |python-dynamic| |/dyn| 488 m *+python3/dyn-stable* 489 Python 3 interface |python-dynamic| |python-stable| 490 |/dyn| 491 N *+quickfix* |:make| and |quickfix| commands 492 N *+reltime* |reltime()| function, 'hlsearch'/'incsearch' timeout, 493 'redrawtime' option 494 H *+rightleft* Right to left typing 'rightleft' 495 m *+ruby* Ruby interface |ruby| 496 m *+ruby/dyn* Ruby interface |ruby-dynamic| |/dyn| 497 T *+scrollbind* 'scrollbind' 498 N *+signs* |:sign| 499 T *+smartindent* 'smartindent' 500 N *+socketserver* Unix only: socket server backend for clientserver 501 functionality 502 H *+sodium* compiled with libsodium for better encryption support 503 H *+sound* |sound_playevent()|, |sound_playfile()| functions, etc. 504 N *+spell* spell checking support, see |spell| 505 N *+startuptime* |--startuptime| argument 506 N *+statusline* Options 'statusline', 'rulerformat' and special 507 formats of 'titlestring' and 'iconstring' 508 - *+sun_workshop* Removed: |workshop| 509 N *+syntax* Syntax highlighting |syntax| 510 *+system()* Unix only: opposite of |+fork| 511 H *+tabpanel* Support for |tabpanel| 512 T *+tag_binary* binary searching in tags file |tag-binary-search| 513 - *+tag_old_static* Removed; method for static tags |tag-old-static| 514 - *+tag_any_white* Removed; was to allow any white space in tags files 515 m *+tcl* Tcl interface |tcl| 516 m *+tcl/dyn* Tcl interface |tcl-dynamic| |/dyn| 517 m *+terminal* Support for terminal window |terminal| 518 *+terminfo* uses |terminfo| instead of termcap 519 N *+termresponse* support for |t_RV| and |v:termresponse| 520 N *+termguicolors* 24-bit color in xterm-compatible terminals support 521 T *+textobjects* |text-objects| selection. Always enabled since 9.0.0222. 522 N *+textprop* |text-properties| 523 *+tgetent* non-Unix only: able to use external termcap 524 N *+timers* the |timer_start()| function 525 T *+title* Setting the window 'title' and 'icon'; Always enabled 526 N *+toolbar* |gui-toolbar| 527 T *+user_commands* User-defined commands. |user-commands| 528 Always enabled since 8.1.1210. 529 H *+vartabs* Variable-width tab stops. 'vartabstop' 530 T *+vertsplit* Vertically split windows |:vsplit|; Always enabled 531 since 8.0.1118. 532 T *+vim9script* |Vim9| script 533 N *+viminfo* 'viminfo' 534 T *+virtualedit* 'virtualedit' Always enabled since 8.1.826. 535 T *+visual* Visual mode |Visual-mode| Always enabled since 7.4.200. 536 T *+visualextra* extra Visual mode commands |blockwise-operators| 537 T *+vreplace* |gR| and |gr| 538 *+vtp* on MS-Windows console: support for 'termguicolors' 539 N *+wayland* Unix only: support for the Wayland protocol. 540 N *+wayland_clipboard* Unix only: support for Wayland selections/clipboard. 541 T *+wildignore* 'wildignore' Always enabled since 9.0.0278 542 T *+wildmenu* 'wildmenu' Always enabled since 9.0.0279 543 T *+windows* more than one window; Always enabled since 8.0.1118. 544 m *+writebackup* 'writebackup' is default on 545 m *+xim* X input method |xim| 546 *+xfontset* X fontset support |xfontset| 547 N *+xattr* compiled with extended attribute support (Linux only) 548 *+xpm* pixmap support 549 m *+xpm_w32* Win32 GUI only: pixmap support |w32-xpm-support| 550 *+xsmp* XSMP (X session management) support 551 *+xsmp_interact* interactive XSMP (X session management) support 552 N *+xterm_clipboard* Unix only: xterm clipboard handling 553 m *+xterm_save* save and restore xterm screen |xterm-screens| 554 N *+X11* Unix only: can restore window title |X11| 555 556 */dyn* *E370* *E448* 557 To some of the features "/dyn" is added when the 558 feature is only available when the related library can 559 be dynamically loaded. 560 561 :ve[rsion] {nr} Is now ignored. This was previously used to check the 562 version number of a .vimrc file. It was removed, 563 because you can now use the ":if" command for 564 version-dependent behavior. 565 566 *:redi* *:redir* 567 :redi[r][!] > {file} Redirect messages to file {file}. The messages which 568 are the output of commands are written to that file, 569 until redirection ends. The messages are also still 570 shown on the screen. When [!] is included, an 571 existing file is overwritten. When [!] is omitted, 572 and {file} exists, this command fails. 573 574 Only one ":redir" can be active at a time. Calls to 575 ":redir" will close any active redirection before 576 starting redirection to the new target. For recursive 577 use check out |execute()|. 578 579 To stop the messages and commands from being echoed to 580 the screen, put the commands in a function and call it 581 with ":silent call Function()". 582 An alternative is to use the 'verbosefile' option, 583 this can be used in combination with ":redir". 584 585 :redi[r] >> {file} Redirect messages to file {file}. Append if {file} 586 already exists. 587 588 :redi[r] @{a-zA-Z} 589 :redi[r] @{a-zA-Z}> Redirect messages to register {a-z}. Append to the 590 contents of the register if its name is given 591 uppercase {A-Z}. The ">" after the register name is 592 optional. 593 :redi[r] @{a-z}>> Append messages to register {a-z}. 594 595 :redi[r] @*> 596 :redi[r] @+> Redirect messages to the selection or clipboard. For 597 backward compatibility, the ">" after the register 598 name can be omitted. See |quotestar| and |quoteplus|. 599 :redi[r] @*>> 600 :redi[r] @+>> Append messages to the selection or clipboard. 601 602 :redi[r] @"> Redirect messages to the unnamed register. For 603 backward compatibility, the ">" after the register 604 name can be omitted. 605 :redi[r] @">> Append messages to the unnamed register. 606 *E1092* 607 :redi[r] => {var} Redirect messages to a variable. 608 In legacy script: If the variable doesn't exist, then 609 it is created. If the variable exists, then it is 610 initialized to an empty string. After the redirection 611 starts, if the variable is removed or locked or the 612 variable type is changed, then further command output 613 messages will cause errors. When using a local 614 variable (l:var in a function or s:var in a script) 615 and another `:redir` causes the current one to end, 616 the scope might be different and the assignment fails. 617 In Vim9 script: the variable must have been declared 618 as a string. 619 The variable will remain empty until redirection ends. 620 Only string variables can be used. 621 To get the output of one command the |execute()| 622 function can be used instead of redirection. 623 624 :redi[r] =>> {var} Append messages to an existing variable. Only string 625 variables can be used. 626 *E1185* 627 :redi[r] END End redirecting messages. 628 629 *:filt* *:filter* 630 :filt[er][!] {pattern} {command} 631 :filt[er][!] /{pattern}/ {command} 632 Restrict the output of {command} to lines matching 633 with {pattern}. For example, to list only xml files: > 634 :filter /\.xml$/ oldfiles 635 < If the [!] is given, restrict the output of {command} 636 to lines that do NOT match {pattern}. 637 638 {pattern} is a Vim search pattern. Instead of 639 enclosing it in / any non-ID character (see 'isident') 640 can be used, so long as it does not appear in 641 {pattern}. 642 Without the enclosing character the pattern cannot 643 include the bar character. 'ignorecase' is not used. 644 645 The pattern is matched against the relevant part of 646 the output, not necessarily the whole line. Only some 647 commands support filtering, try it out to check if it 648 works. Some of the commands that support filtering: 649 |:#| - filter whole line 650 |:clist| - filter by file name or module name 651 |:command| - filter by command name 652 |:files| - filter by file name 653 |:highlight| - filter by highlight group 654 |:history| - filter by history commands 655 |:jumps| - filter by file name 656 |:let| - filter by variable name 657 |:list| - filter whole line 658 |:llist| - filter by file name or module name 659 |:marks| - filter by text in the current file, 660 or file name for other files 661 |:oldfiles| - filter by file name 662 |:registers| - filter by register contents 663 (does not work multi-line) 664 |:set| - filter by option name 665 666 Only normal messages are filtered, error messages are 667 not. 668 669 *:sil* *:silent* *:silent!* 670 :sil[ent][!] {command} Execute {command} silently. Normal messages will not 671 be given or added to the message history. 672 When [!] is added, error messages will also be 673 skipped, and commands and mappings will not be aborted 674 when an error is detected. |v:errmsg| is still set. 675 When [!] is not used, an error message will cause 676 further messages to be displayed normally. 677 Redirection, started with |:redir|, will continue as 678 usual, although there might be small differences. 679 This will allow redirecting the output of a command 680 without seeing it on the screen. Example: > 681 :redir >/tmp/foobar 682 :silent g/Aap/p 683 :redir END 684 < To execute a Normal mode command silently, use the 685 |:normal| command. For example, to search for a 686 string without messages: > 687 :silent exe "normal /path\<CR>" 688 < ":silent!" is useful to execute a command that may 689 fail, but the failure is to be ignored. Example: > 690 :let v:errmsg = "" 691 :silent! /^begin 692 :if v:errmsg != "" 693 : ... pattern was not found 694 < ":silent" will also avoid the hit-enter prompt. When 695 using this for an external command, this may cause the 696 screen to be messed up. Use |CTRL-L| to clean it up 697 then. 698 ":silent menu ..." defines a menu that will not echo a 699 Command-line command. The command will still produce 700 messages though. Use ":silent" in the command itself 701 to avoid that: ":silent menu .... :silent command". 702 703 *:uns* *:unsilent* 704 :uns[ilent] {command} Execute {command} not silently. Only makes a 705 difference when |:silent| was used to get to this 706 command. 707 Use this for giving a message even when |:silent| was 708 used. In this example |:silent| is used to avoid the 709 message about reading the file and |:unsilent| to be 710 able to list the first line of each file. > 711 :silent argdo unsilent echo expand('%') .. ": " .. getline(1) 712 < 713 714 *:verb* *:verbose* 715 :[count]verb[ose] {command} 716 Execute {command} with 'verbose' set to [count]. If 717 [count] is omitted one is used. ":0verbose" can be 718 used to set 'verbose' to zero. 719 The additional use of ":silent" makes messages 720 generated but not displayed. 721 The combination of ":silent" and ":verbose" can be 722 used to generate messages and check them with 723 |v:statusmsg| and friends. For example: > 724 :let v:statusmsg = "" 725 :silent verbose runtime foobar.vim 726 :if v:statusmsg != "" 727 : " foobar.vim could not be found 728 :endif 729 < When concatenating another command, the ":verbose" 730 only applies to the first one: > 731 :4verbose set verbose | set verbose 732 < verbose=4 ~ 733 verbose=0 ~ 734 For logging verbose messages in a file use the 735 'verbosefile' option. 736 737 *:verbose-cmd* 738 When 'verbose' is non-zero, listing the value of a Vim option or a key map or 739 an abbreviation or a user-defined function or a command or a highlight group 740 or an autocommand will also display where it was last defined. If it was 741 defined manually then there will be no "Last set" message. When it was 742 defined while executing a function, user command or autocommand, the script in 743 which it was defined is reported. 744 {not available when compiled without the |+eval| feature} 745 746 *K* 747 K Run a program to lookup the keyword under the 748 cursor. The name of the program is given with the 749 'keywordprg' (kp) option (default is "man"). The 750 keyword is formed of letters, numbers and the 751 characters in 'iskeyword'. The keyword under or 752 right of the cursor is used. The same can be done 753 with the command > 754 :!{program} {keyword} 755 < There is an example of a program to use in the tools 756 directory of Vim. It is called "ref" and does a 757 simple spelling check. 758 Special cases: 759 - If 'keywordprg' begins with ":" it is invoked as 760 a Vim Ex command with [count]. 761 - If 'keywordprg' is empty, the ":help" command is 762 used. It's a good idea to include more characters 763 in 'iskeyword' then, to be able to find more help. 764 - When 'keywordprg' is equal to "man" or starts with 765 ":", a [count] before "K" is inserted after 766 keywordprg and before the keyword. For example, 767 using "2K" while the cursor is on "mkdir", results 768 in: > 769 !man 2 mkdir 770 < - When 'keywordprg' is equal to "man -s", a count 771 before "K" is inserted after the "-s". If there is 772 no count, the "-s" is removed. 773 774 *v_K* 775 {Visual}K Like "K", but use the visually highlighted text for 776 the keyword. Only works when the highlighted text is 777 not more than one line. 778 779 [N]gs *gs* *:sl* *:sleep* 780 :[N]sl[eep] [N][m] Do nothing for [N] seconds. When [m] is included, 781 sleep for [N] milliseconds. The count for "gs" always 782 uses seconds. The default is one second. > 783 :sleep "sleep for one second 784 :5sleep "sleep for five seconds 785 :sleep 100m "sleep for 100 milliseconds 786 10gs "sleep for ten seconds 787 < Can be interrupted with CTRL-C (CTRL-Break on 788 MS-Windows). "gs" stands for "goto sleep". 789 While sleeping the cursor is positioned in the text, 790 if at a visible position. 791 Queued messages and timers (|+timers|) are processed 792 during the sleep as well. 793 794 *:sl!* *:sleep!* 795 :[N]sl[eep]! [N][m] Same as above, but hide the cursor. 796 797 *:xrestore* *:xr* 798 :xr[estore] [display] Reinitializes the connection to the X11 server. 799 Useful after the X server restarts, e.g. when running 800 Vim for long time inside screen/tmux and connecting 801 from different machines. 802 [display] should be in the format of the $DISPLAY 803 environment variable (e.g. "localhost:10.0") 804 If [display] is omitted, then it reinitializes the 805 connection to the X11 server using the same value as 806 was used for the previous execution of this command. 807 If the value was never specified, then it uses the 808 value of $DISPLAY environment variable as it was when 809 Vim was started. This will also update |v:clipmethod|. 810 {only available when compiled with the 811 |+xterm_clipboard| feature} 812 813 *:clipreset* *:clip* 814 :clip[reset] Attempts to choose a new method for accessing the 815 clipboard, using the 'clipmethod' option. This is 816 useful when the current method has become unavailable, 817 and you want to try using another method. 818 {only available when compiled with the |+clipboard| 819 feature} 820 821 *g_CTRL-A* 822 g CTRL-A Only when Vim was compiled with MEM_PROFILING defined 823 (which is very rare): print memory usage statistics. 824 Only useful for debugging Vim. 825 For incrementing in Visual mode see |v_g_CTRL-A|. 826 827 ============================================================================== 828 2. Using Vim like less or more *less* 829 830 If you use the less or more program to view a file, you don't get syntax 831 highlighting. Thus you would like to use Vim instead. You can do this by 832 using the shell script "$VIMRUNTIME/macros/less.sh". 833 834 This shell script uses the Vim script "$VIMRUNTIME/macros/less.vim". It sets 835 up mappings to simulate the commands that less supports. Otherwise, you can 836 still use the Vim commands. 837 838 This isn't perfect. For example, when viewing a short file Vim will still use 839 the whole screen. But it works well enough for most uses, and you get syntax 840 highlighting. 841 842 The "h" key will give you a short overview of the available commands. 843 844 If you want to set options differently when using less, define the 845 LessInitFunc in your vimrc, for example: > 846 847 func LessInitFunc() 848 set nocursorcolumn nocursorline 849 endfunc 850 < 851 852 vim:tw=78:ts=8:noet:ft=help:norl: