robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1*various.txt* Nvim 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7Various commands *various* 8 9 Type |gO| to see the table of contents. 10 11============================================================================== 121. Various commands *various-cmds* 13 14 *CTRL-C* 15CTRL-C Interrupt the current command, script, mapping, 16 prompt, or search. 17 18 In Normal mode, any pending command is aborted. During 19 a search, interrupts the search. 20 21 Lua code cannot be interrupted unless it "yields" via 22 |vim.wait()|. 23 24 *CTRL-L* 25CTRL-L Clears and redraws the screen. The redraw may happen 26 later, after processing typeahead. 27 See also |nvim__redraw()|. 28 *CTRL-L-default* 29 By default, also clears search highlighting 30 |:nohlsearch|, removes |multicursor|s, and updates 31 diffs |:diffupdate|. |default-mappings| 32 33 *:mod* *:mode* *E359* 34:mod[e] Clears and redraws the screen. 35 See also |nvim__redraw()|. 36 37 *:redr* *:redraw* 38:redr[aw][!] Redraws pending screen updates now, or the entire 39 screen if "!" is included. To CLEAR the screen use 40 |:mode| or |CTRL-L|. 41 It can be used to redraw the screen in a script 42 or function (or a mapping if 'lazyredraw' is set). 43 See also |nvim__redraw()|. 44 45 *:redraws* *:redrawstatus* 46:redraws[tatus][!] Redraws the status line and window bar of the current 47 window, or all status lines and window bars if "!" is 48 included. Redraws the commandline instead if it contains 49 the 'ruler'. Useful if 'statusline' or 'winbar' includes 50 an item that doesn't cause automatic updating. 51 See also |nvim__redraw()|. 52 53 *:redrawt* *:redrawtabline* 54:redrawt[abline] Redraw the tabline. Useful to update the tabline when 55 'tabline' includes an item that doesn't trigger 56 automatic updating. See also |nvim__redraw()|. 57 58 *N<Del>* 59<Del> When entering a number: Remove the last digit. 60 Note: if you like to use <BS> for this, add this 61 mapping to your vimrc: > 62 :map CTRL-V <BS> CTRL-V <Del> 63< 64:as[cii] or *ga* *:as* *:ascii* 65ga Print the ascii value of the character under the 66 cursor in decimal, hexadecimal and octal. 67 Mnemonic: Get Ascii value. 68 69 For example, when the cursor is on a 'R': 70 <R> 82, Hex 52, Octal 122 ~ 71 When the character is a non-standard ASCII character, 72 the non-printable version is also given. 73 74 When the character is larger than 127: 75 <<81>> 129, Hex 0081, Octal 201 ~ 76 <p> 254, Hex 00fe, Octal 376 ~ 77 (where <p> is a special character) 78 79 The <Nul> character in a file is stored internally as 80 <NL>, but it will be shown as: 81 <^@> 0, Hex 00, Octal 000 ~ 82 83 If the character has composing characters these are 84 also shown. The value of 'maxcombine' doesn't matter. 85 86 If the character can be inserted as a digraph, also 87 output the two characters that can be used to create 88 the character: 89 <ö> 246, Hex 00f6, Oct 366, Digr o: ~ 90 This shows you can type CTRL-K o : to insert ö. 91 92 *g8* 93g8 Print the hex values of the bytes used in the 94 character under the cursor, assuming it is in |UTF-8| 95 encoding. This also shows composing characters. The 96 value of 'maxcombine' doesn't matter. 97 Example of a character with two composing characters: 98 e0 b8 81 + e0 b8 b9 + e0 b9 89 ~ 99 100 *8g8* 1018g8 Find an illegal UTF-8 byte sequence at or after the 102 cursor. 103 Can be used when editing a file that was supposed to 104 be UTF-8 but was read as if it is an 8-bit encoding 105 because it contains illegal bytes. 106 Does not wrap around the end of the file. 107 Note that when the cursor is on an illegal byte or the 108 cursor is halfway through a multibyte character the 109 command won't move the cursor. 110 111 *gx* 112gx Opens the current filepath, URL (decided by 113 |<cfile>|, 'isfname'), or |LSP| "documentLink" at 114 cursor using the system default handler. 115 116 In |help| files, gx treats help tags as 117 https://neovim.io/doc/user/ URLs. 118 119 Mapped to |vim.ui.open()|. 120 121 *v_gx* 122{Visual}gx Opens the selected text using the system default 123 handler. Mapped to |vim.ui.open()|. 124 125 *:p* *:pr* *:print* *E749* 126:[range]p[rint] [flags] 127 Print [range] lines (default current line). Can also 128 be spelled `:[range]|` due to Vi compatibility (see 129 |:bar|). Gives an error in an empty buffer. 130 In the GUI you can use the File.Print menu entry. 131 See |ex-flags| for [flags]. 132 The |:filter| command can be used to only show lines 133 matching a pattern. 134 135:[range]p[rint] {count} [flags] 136 Print {count} lines, starting with [range] (default 137 current line |cmdline-ranges|). 138 See |ex-flags| for [flags]. 139 140 *:l* *:list* 141:[range]l[ist] [count] [flags] 142 Same as :print, but show tabs as ">", trailing spaces 143 as "-", and non-breakable space characters as "+" by 144 default. Further changed by the 'listchars' option. 145 See |ex-flags| for [flags]. 146 147 *:nu* *:number* 148:[range]nu[mber] [count] [flags] 149 Same as :print, but precede each line with its line 150 number. (See also |hl-LineNr| and 'numberwidth'). 151 See |ex-flags| for [flags]. 152 153 *:#* 154:[range]# [count] [flags] 155 synonym for :number. 156 157 *:#!* *vim-shebang* 158:#!{anything} Ignored, so that you can start a Vim script with: > 159 #!vim -S 160 let mylogbook='$HOME/logbook.md' 161 exe $':e {mylogbook}' 162 $ 163 put ='## ' .. strftime('%d. %b %Y') 164 norm! o 165< 166 Make that script executable and run it to create a 167 new diary entry. 168 169 *:z* *E144* 170:[range]z[+-^.=][count] Display several lines of text surrounding the line 171 specified with [range], or around the current line 172 if there is no [range]. 173 174 If there is a [count], that's how many lines you'll 175 see; if there is no [count] and only one window then 176 twice the value of the 'scroll' option is used, 177 otherwise the current window height minus 3 is used. 178 This is the value of "scr" in the table below. 179 180 If there is a [count] the 'window' option is set to 181 its value. 182 183 :z can be used either alone or followed by any of 184 several marks. These have the following effect: 185 186 mark first line last line new cursor line ~ 187 ---- ---------- --------- ------------ 188 + current line 1 scr forward 1 scr forward 189 - 1 scr back current line current line 190 ^ 2 scr back 1 scr back 1 scr back 191 . 1/2 scr back 1/2 scr fwd 1/2 scr fwd 192 = 1/2 scr back 1/2 scr fwd current line 193 194 Specifying no mark at all is the same as "+". 195 If the mark is "=", a line of dashes is printed 196 around the current line. 197 198 If the 'number' option is set, absolute line numbers 199 will be included in the output. 200 201 *:z!* 202:[range]z![+-^.=][count] 203 Like ":z", but when [count] is not specified, it 204 defaults to the Vim window height minus one. 205 206:[range]z[!]#[+-^.=][count] *:z#* 207 Like ":z" or ":z!", but number the lines. 208 209 *:=* 210:= [args] Without [args]: prints the last line number. 211 With [args]: equivalent to `:lua ={expr}`. see |:lua| 212 213:{range}= Prints the last line number in {range}. For example, 214 this prints the current line number: > 215 :.= 216 217:norm[al][!] {commands} *:norm* *:normal* 218 Execute Normal mode commands {commands}. This makes 219 it possible to execute Normal mode commands typed on 220 the command-line. {commands} are executed like they 221 are typed. For undo all commands are undone together. 222 Execution stops when an error is encountered. 223 224 If the [!] is given, mappings will not be used. 225 Without it, when this command is called from a 226 non-remappable mapping (|:noremap|), the argument can 227 be mapped anyway. 228 229 {commands} should be a complete command. If 230 {commands} does not finish a command, the last one 231 will be aborted as if <Esc> or <C-C> was typed. 232 This implies that an insert command must be completed 233 (to start Insert mode, see |:startinsert|). A ":" 234 command must be completed as well. And you can't 235 start |Ex-mode|. 236 237 The display is not updated while ":normal" is busy. 238 239 {commands} cannot start with a space. Put a count of 240 1 (one) before it, "1 " is one space. 241 242 This command cannot be followed by another command, 243 since any '|' is considered part of the command. 244 245 This command can be used recursively, but the depth is 246 limited by 'maxmapdepth'. 247 248 An alternative is to use |:execute|, which uses an 249 expression as argument. This allows the use of 250 printable characters to represent special characters. 251 252 Example: > 253 :exe "normal \<c-w>\<c-w>" 254< 255 256:{range}norm[al][!] {commands} *:normal-range* 257 Execute Normal mode commands {commands} for each line 258 in the {range}. Before executing the {commands}, the 259 cursor is positioned in the first column of the range, 260 for each line. Otherwise it's the same as the 261 ":normal" command without a range. 262 263 *:sh* *:shell* *E371* *E360* 264:sh[ell] Removed. |vim-differences| 265 266 *:terminal* *:te* 267:te[rminal][!] [cmd] Run [cmd] in a non-interactive 'shell' in a new 268 |terminal-emulator| buffer. Without [cmd], start an 269 interactive 'shell'. 270 271 By default the current window is used. To open in 272 a split window, use |:horizontal| or |:vertical|: > 273 :hor te 274 :vert te 275< 276 Type |i| to enter |Terminal-mode|, then keys are sent to 277 the job running in the terminal. Type <C-\><C-N> to 278 leave Terminal-mode. |CTRL-\_CTRL-N|. Type <C-\><C-O> 279 to execute a single normal mode command |t_CTRL-\_CTRL-O| 280 281 Fails if changes have been made to the current buffer, 282 unless 'hidden' is set. 283 284 If [cmd] is omitted, and the 'shell' job exits with no 285 error, the buffer is closed automatically 286 |default-autocmds|. 287 288 To enter |Terminal-mode| automatically: > 289 autocmd TermOpen * startinsert 290< 291 *:!cmd* *:!* 292:!{cmd} Execute {cmd} with 'shell'. See also |:terminal|. 293 For the filter command, see |:range!|. 294 295 The command runs in a non-interactive shell connected 296 to a pipe (not a terminal). Use |:terminal| to run an 297 interactive shell connected to a terminal. 298 299 Backgrounded ("&") commands must not write to stdout 300 or stderr, the streams are closed immediately. |E5677| 301 Use |jobstart()| instead. > 302 :call jobstart('foo', {'detach':1}) 303< 304 For powershell, chaining a stringed executable path 305 requires using the call operator (&). > 306 :!Write-Output "1`n2" | & "C:\Windows\System32\sort.exe" /r 307< 308 Vim builds command line using options 'shell', 'shcf', 309 'sxq' and 'shq' in the following order: 310 `&sh &shcf &sxq &shq {cmd} &shq &sxq` 311 So setting both 'sxq' and 'shq' is possible but rarely 312 useful. Additional escaping inside `{cmd}` may also 313 be due to 'sxe' option. 314 315 Also, all |cmdline-special| characters in {cmd} are 316 replaced by Vim before passing them to shell. 317 318 *E34* 319 Any "!" in {cmd} is replaced with the previous 320 external command (see also 'cpoptions'), unless 321 escaped by a backslash. Example: ":!ls" followed by 322 ":!echo ! \! \\!" executes "echo ls ! \!". 323 324 Any "|" in {cmd} is passed to the shell, you cannot 325 use it to append a Vim command. See |:bar|. 326 327 Any "%" in {cmd} is expanded to the current file name. 328 Any "#" in {cmd} is expanded to the alternate file name. 329 Special characters are not escaped, use quotes or 330 |shellescape()|: > 331 :!ls "%" 332 :exe "!ls " .. shellescape(expand("%"),1) 333< 334 Newline character ends {cmd} unless a backslash 335 precedes the newline. What follows is interpreted as 336 another |:| command. 337 338 After the command has been executed, the timestamp and 339 size of the current file is checked |timestamp|. 340 341 If the command produces too much output some lines may 342 be skipped so the command can execute quickly. No 343 data is lost, this only affects the display. The last 344 few lines are always displayed (never skipped). 345 346 To avoid the hit-enter prompt use: > 347 :silent !{cmd} 348< 349 *:!!* 350:!! Repeat last ":!{cmd}". 351 352 *:ve* *:ver* *:version* 353:ve[rsion] Print editor version and build information. 354 See also |feature-compile|. 355 356 *:redi* *:redir* 357:redi[r][!] > {file} Redirect messages to file {file}. The messages which 358 are the output of commands are written to that file, 359 until redirection ends. The messages are also still 360 shown on the screen. When [!] is included, an 361 existing file is overwritten. When [!] is omitted, 362 and {file} exists, this command fails. 363 364 Only one ":redir" can be active at a time. Calls to 365 ":redir" will close any active redirection before 366 starting redirection to the new target. For recursive 367 use check out |execute()|. 368 369 To stop the messages and commands from being echoed to 370 the screen, put the commands in a function and call it 371 with ":silent call Function()". 372 Alternatives are the 'verbosefile' option or 373 |execute()| function, these can be used in combination 374 with ":redir". 375 376:redi[r] >> {file} Redirect messages to file {file}. Append if {file} 377 already exists. 378 379:redi[r] @{a-zA-Z} 380:redi[r] @{a-zA-Z}> Redirect messages to register {a-z}. Append to the 381 contents of the register if its name is given 382 uppercase {A-Z}. The ">" after the register name is 383 optional. 384:redi[r] @{a-z}>> Append messages to register {a-z}. 385 386:redi[r] @*> 387:redi[r] @+> Redirect messages to the selection or clipboard. For 388 backward compatibility, the ">" after the register 389 name can be omitted. See |quotestar| and |quoteplus|. 390:redi[r] @*>> 391:redi[r] @+>> Append messages to the selection or clipboard. 392 393:redi[r] @"> Redirect messages to the unnamed register. For 394 backward compatibility, the ">" after the register 395 name can be omitted. 396:redi[r] @">> Append messages to the unnamed register. 397 398:redi[r] => {var} Redirect messages to a variable. If the variable 399 doesn't exist, then it is created. If the variable 400 exists, then it is initialized to an empty string. 401 The variable will remain empty until redirection ends. 402 Only string variables can be used. After the 403 redirection starts, if the variable is removed or 404 locked or the variable type is changed, then further 405 command output messages will cause errors. When using 406 a local variable (l:var in a function or s:var in a 407 script) and another `:redir` causes the current one to 408 end, the scope might be different and the assignment 409 fails. 410 To get the output of one command the |execute()| 411 function can be used instead of redirection. 412 413:redi[r] =>> {var} Append messages to an existing variable. Only string 414 variables can be used. 415 416:redi[r] END End redirecting messages. 417 418 *:filt* *:filter* 419:filt[er][!] {pattern} {command} 420:filt[er][!] /{pattern}/ {command} 421 Restrict the output of {command} to lines matching 422 with {pattern}. For example, to list only xml files: > 423 :filter /\.xml$/ oldfiles 424< If the [!] is given, restrict the output of {command} 425 to lines that do NOT match {pattern}. 426 427 {pattern} is a Vim search pattern. Instead of 428 enclosing it in / any non-ID character (see 'isident') 429 can be used, so long as it does not appear in 430 {pattern}. 431 Without the enclosing character the pattern cannot 432 include the bar character. 'ignorecase' is not used. 433 434 The pattern is matched against the relevant part of 435 the output, not necessarily the whole line. Only some 436 commands support filtering, try it out to check if it 437 works. Some of the commands that support filtering: 438 |:#| - filter whole line 439 |:clist| - filter by file name or module name 440 |:command| - filter by command name 441 |:files| - filter by file name 442 |:highlight| - filter by highlight group 443 |:history| - filter by history commands 444 |:jumps| - filter by file name 445 |:let| - filter by variable name 446 |:list| - filter whole line 447 |:llist| - filter by file name or module name 448 |:marks| - filter by text in the current file, 449 or file name for other files 450 |:oldfiles| - filter by file name 451 |:registers| - filter by register contents 452 (does not work multi-line) 453 |:set| - filter by option name 454 455 Only normal messages are filtered, error messages are 456 not. 457 458 *:sil* *:silent* *:silent!* 459:sil[ent][!] {command} Execute {command} silently. Normal messages will not 460 be given or added to the message history. 461 When [!] is added, error messages will also be 462 skipped, and commands and mappings will not be aborted 463 when an error is detected. |v:errmsg| is still set. 464 When [!] is not used, an error message will cause 465 further messages to be displayed normally. 466 Redirection, started with |:redir|, will continue as 467 usual, although there might be small differences. 468 This will allow redirecting the output of a command 469 without seeing it on the screen. Example: > 470 :redir >/tmp/foobar 471 :silent g/Aap/p 472 :redir END 473< To execute a Normal mode command silently, use the 474 |:normal| command. For example, to search for a 475 string without messages: > 476 :silent exe "normal /path\<CR>" 477< ":silent!" is useful to execute a command that may 478 fail, but the failure is to be ignored. Example: > 479 :let v:errmsg = "" 480 :silent! /^begin 481 :if v:errmsg != "" 482 : ... pattern was not found 483< ":silent" also skips the hit-enter prompt. 484 Dialogs that prompt for user input (|confirm()|, 485 'swapfile', …) are never silent. 486 487 *:uns* *:unsilent* 488:uns[ilent] {command} Execute {command} not silently. Only makes a 489 difference when |:silent| was used to get to this 490 command. 491 Use this for giving a message even when |:silent| was 492 used. In this example |:silent| is used to avoid the 493 message about reading the file and |:unsilent| to be 494 able to list the first line of each file. > 495 :silent argdo unsilent echo expand('%') .. ": " .. getline(1) 496< 497 498 *:verb* *:verbose* 499:[count]verb[ose] {command} 500 Execute {command} with 'verbose' set to [count]. If 501 [count] is omitted one is used. ":0verbose" can be 502 used to set 'verbose' to zero. 503 The additional use of ":silent" makes messages 504 generated but not displayed. 505 The combination of ":silent" and ":verbose" can be 506 used to generate messages and check them with 507 |v:statusmsg| and friends. For example: > 508 :let v:statusmsg = "" 509 :silent verbose runtime foobar.vim 510 :if v:statusmsg != "" 511 : " foobar.vim could not be found 512 :endif 513< When concatenating another command, the ":verbose" 514 only applies to the first one: > 515 :4verbose set verbose | set verbose 516< verbose=4 ~ 517 verbose=0 ~ 518 For logging verbose messages in a file use the 519 'verbosefile' option. 520 521 *:verbose-cmd* 522When 'verbose' is non-zero, listing the value of a Vim option or a key map or 523an abbreviation or a user-defined function or a command or a highlight group 524or an autocommand will also display where it was last defined. If they were 525defined in Lua they will only be located if 'verbose' is set. So Start 526nvim with -V1 arg to see them. If it was defined manually then there 527will be no "Last set" message. When it was defined while executing a function, 528user command or autocommand, the script in which it was defined is reported. 529 530 *K* 531[count]K Runs the program given by 'keywordprg' to lookup the 532 |word| (defined by 'iskeyword') under or right of the 533 cursor. Default is "man". Works like this: > 534 :tabnew | terminal {program} {keyword} 535< Special cases: 536 - If 'keywordprg' begins with ":" it is invoked as 537 a Vim command and [count] is passed as the first 538 argument, if present. 539 - If 'keywordprg' is empty, |:help| is used. 540 - When 'keywordprg' is equal to "man", a [count] 541 before "K" is inserted after the "man" command and 542 before the keyword. For example, using "2K" while 543 the cursor is on "mkdir", results in: > 544 !man 2 mkdir 545< - When 'keywordprg' is equal to "man -s", a [count] 546 before "K" is inserted after the "-s". If there is 547 no count, the "-s" is removed. 548 *K-lsp-default* 549 - The Nvim |LSP| client sets K to show LSP "hover" 550 feature. |lsp-defaults| 551 552 *v_K* 553{Visual}K Like "K", but use the visually highlighted text for 554 the keyword. Only works when the highlighted text is 555 not more than one line. 556 557 *gO* 558gO Show a filetype-specific, navigable "outline" of the 559 current buffer. For example, in a |help| buffer this 560 shows the table of contents. 561 562 Works in |help| and |:Man| buffers, or any buffer with 563 an active |LSP| client (|lsp-defaults|). 564 565[N]gs *gs* *:sl* *:sleep* 566:[N]sl[eep] [N][m] Do nothing for [N] seconds, or [N] milliseconds if [m] 567 was given. "gs" always uses seconds. 568 Default is one second. > 569 :sleep "sleep for one second 570 :5sleep "sleep for five seconds 571 :sleep 100m "sleep for 100 milliseconds 572 10gs "sleep for ten seconds 573< Can be interrupted with CTRL-C. 574 "gs" stands for "goto sleep". 575 While sleeping the cursor is positioned in the text, 576 if at a visible position. 577 Queued messages are processed during the sleep. 578 579 *:sl!* *:sleep!* 580:[N]sl[eep]! [N][m] Same as above, but hide the cursor. 581 582 *g==* 583g== Executes the current code block. 584 585 Works in |help| buffers. 586 587 *:upt* *:uptime* 588:upt[ime] Shows Nvim's uptime. 589 See also |v:starttime|. 590 591============================================================================== 5922. Using Vim like less or more *less* 593 594If you use the less or more program to view a file, you don't get syntax 595highlighting. Thus you would like to use Vim instead. You can do this by 596using the shell script "$VIMRUNTIME/scripts/less.sh". 597 598This shell script uses the Vim script "$VIMRUNTIME/scripts/less.vim". It sets 599up mappings to simulate the commands that less supports. Otherwise, you can 600still use the Vim commands. 601 602This isn't perfect. For example, when viewing a short file Vim will still use 603the whole screen. But it works well enough for most uses, and you get syntax 604highlighting. 605 606The "h" key will give you a short overview of the available commands. 607 608If you want to set options differently when using less, define the 609LessInitFunc in your vimrc, for example: > 610 611 func LessInitFunc() 612 set nocursorcolumn nocursorline 613 endfunc 614< 615============================================================================== 6163. Commenting *commenting* 617 618Nvim supports commenting and uncommenting of lines based on 'commentstring'. 619 620Acting on a single line behaves as follows: 621- If the line matches 'commentstring', the comment markers are removed (e.g. 622 `/*foo*/` is transformed to `foo`). 623- Otherwise the comment markers are added to the current line (e.g. `foo` is 624 transformed to `/*foo*/`). Blank lines are ignored. 625 626Acting on multiple lines behaves as follows: 627- If each affected non-blank line matches 'commentstring', then all comment 628 markers are removed. 629- Otherwise all affected lines are converted to comments; blank lines are 630 transformed to empty comments (e.g. `/**/`). Comment markers are aligned to 631 the least indented line. 632 633Matching 'commentstring' does not account for whitespace in comment markers. 634Removing comment markers is first attempted exactly, with fallback to using 635markers trimmed from whitespace. 636 637If the filetype of the buffer is associated with a language for which a 638|treesitter| parser is installed, then |vim.filetype.get_option()| is called 639to look up the value of 'commentstring' corresponding to the cursor position. 640(This can be different from the buffer's 'commentstring' in case of 641|treesitter-language-injections|.) 642 643The following |default-mappings| are defined: 644 645 *gc* *gc-default* 646gc{motion} Comment or uncomment lines covered by {motion}. 647 648 *gcc* *gcc-default* 649gcc Comment or uncomment [count] lines starting at cursor. 650 651 *v_gc* *v_gc-default* 652{Visual}gc Comment or uncomment the selected line(s). 653 654 *o_gc* *o_gc-default* 655gc Text object for the largest contiguous block of 656 non-blank commented lines around the cursor (e.g. 657 `gcgc` uncomments a comment block; `dgc` deletes it). 658 Works only in Operator-pending mode. 659 660 vim:noet:tw=78:ts=8:ft=help:norl: