various.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. *various.txt* Nvim
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. Various commands *various*
  4. Type |gO| to see the table of contents.
  5. ==============================================================================
  6. 1. Various commands *various-cmds*
  7. *CTRL-L*
  8. CTRL-L Clears and redraws the screen. The redraw may happen
  9. later, after processing typeahead.
  10. *CTRL-L-default*
  11. By default, also clears search highlighting
  12. |:nohlsearch| and updates diffs |:diffupdate|.
  13. |default-mappings|
  14. *:mod* *:mode*
  15. :mod[e] Clears and redraws the screen.
  16. *:redr* *:redraw*
  17. :redr[aw][!] Redraws pending screen updates now, or the entire
  18. screen if "!" is included. To CLEAR the screen use
  19. |:mode| or |CTRL-L|.
  20. Useful to update the screen during a script or
  21. function (or a mapping if 'lazyredraw' set).
  22. *:redraws* *:redrawstatus*
  23. :redraws[tatus][!] Redraws the status line and window bar of the current
  24. window, or all status lines and window bars if "!" is
  25. included. Useful if 'statusline' or 'winbar' includes
  26. an item that doesn't cause automatic updating.
  27. *:redrawt* *:redrawtabline*
  28. :redrawt[abline] Redraw the tabline. Useful to update the tabline when
  29. 'tabline' includes an item that doesn't trigger
  30. automatic updating.
  31. *N<Del>*
  32. <Del> When entering a number: Remove the last digit.
  33. Note: if you like to use <BS> for this, add this
  34. mapping to your vimrc: >
  35. :map CTRL-V <BS> CTRL-V <Del>
  36. <
  37. :as[cii] or *ga* *:as* *:ascii*
  38. ga Print the ascii value of the character under the
  39. cursor in decimal, hexadecimal and octal.
  40. Mnemonic: Get Ascii value.
  41. For example, when the cursor is on a 'R':
  42. <R> 82, Hex 52, Octal 122 ~
  43. When the character is a non-standard ASCII character,
  44. but printable according to the 'isprint' option, the
  45. non-printable version is also given.
  46. When the character is larger than 127, the <M-x> form
  47. is also printed. For example:
  48. <~A> <M-^A> 129, Hex 81, Octal 201 ~
  49. <p> <|~> <M-~> 254, Hex fe, Octal 376 ~
  50. (where <p> is a special character)
  51. The <Nul> character in a file is stored internally as
  52. <NL>, but it will be shown as:
  53. <^@> 0, Hex 00, Octal 000 ~
  54. If the character has composing characters these are
  55. also shown. The value of 'maxcombine' doesn't matter.
  56. If the character can be inserted as a digraph, also
  57. output the two characters that can be used to create
  58. the character:
  59. <ö> 246, Hex 00f6, Oct 366, Digr o: ~
  60. This shows you can type CTRL-K o : to insert ö.
  61. *g8*
  62. g8 Print the hex values of the bytes used in the
  63. character under the cursor, assuming it is in |UTF-8|
  64. encoding. This also shows composing characters. The
  65. value of 'maxcombine' doesn't matter.
  66. Example of a character with two composing characters:
  67. e0 b8 81 + e0 b8 b9 + e0 b9 89 ~
  68. *8g8*
  69. 8g8 Find an illegal UTF-8 byte sequence at or after the
  70. cursor. This works in two situations:
  71. 1. when 'encoding' is any 8-bit encoding
  72. 2. when 'encoding' is "utf-8" and 'fileencoding' is
  73. any 8-bit encoding
  74. Thus it can be used when editing a file that was
  75. supposed to be UTF-8 but was read as if it is an 8-bit
  76. encoding because it contains illegal bytes.
  77. Does not wrap around the end of the file.
  78. Note that when the cursor is on an illegal byte or the
  79. cursor is halfway through a multibyte character the
  80. command won't move the cursor.
  81. *:p* *:pr* *:print* *E749*
  82. :[range]p[rint] [flags]
  83. Print [range] lines (default current line).
  84. Note: If you are looking for a way to print your text
  85. on paper see |:hardcopy|. In the GUI you can use the
  86. File.Print menu entry.
  87. See |ex-flags| for [flags].
  88. The |:filter| command can be used to only show lines
  89. matching a pattern.
  90. :[range]p[rint] {count} [flags]
  91. Print {count} lines, starting with [range] (default
  92. current line |cmdline-ranges|).
  93. See |ex-flags| for [flags].
  94. *:l* *:list*
  95. :[range]l[ist] [count] [flags]
  96. Same as :print, but show tabs as ">", trailing spaces
  97. as "-", and non-breakable space characters as "+" by
  98. default. Further changed by the 'listchars' option.
  99. See |ex-flags| for [flags].
  100. *:nu* *:number*
  101. :[range]nu[mber] [count] [flags]
  102. Same as :print, but precede each line with its line
  103. number. (See also |hl-LineNr| and 'numberwidth').
  104. See |ex-flags| for [flags].
  105. *:#*
  106. :[range]# [count] [flags]
  107. synonym for :number.
  108. *:#!*
  109. :#!{anything} Ignored, so that you can start a Vim script with: >
  110. #!vim -S
  111. echo "this is a Vim script"
  112. quit
  113. <
  114. *:z* *E144*
  115. :[range]z[+-^.=][count] Display several lines of text surrounding the line
  116. specified with [range], or around the current line
  117. if there is no [range].
  118. If there is a [count], that's how many lines you'll
  119. see; if there is no [count] and only one window then
  120. twice the value of the 'scroll' option is used,
  121. otherwise the current window height minus 3 is used.
  122. This is the value of "scr" in the table below.
  123. If there is a [count] the 'window' option is set to
  124. its value.
  125. :z can be used either alone or followed by any of
  126. several marks. These have the following effect:
  127. mark first line last line new cursor line ~
  128. ---- ---------- --------- ------------
  129. + current line 1 scr forward 1 scr forward
  130. - 1 scr back current line current line
  131. ^ 2 scr back 1 scr back 1 scr back
  132. . 1/2 scr back 1/2 scr fwd 1/2 scr fwd
  133. = 1/2 scr back 1/2 scr fwd current line
  134. Specifying no mark at all is the same as "+".
  135. If the mark is "=", a line of dashes is printed
  136. around the current line.
  137. *:z!*
  138. :[range]z![+-^.=][count]
  139. Like ":z", but when [count] is not specified, it
  140. defaults to the Vim window height minus one.
  141. :[range]z[!]#[+-^.=][count] *:z#*
  142. Like ":z" or ":z!", but number the lines.
  143. *:=*
  144. := [flags] Print the last line number.
  145. See |ex-flags| for [flags].
  146. :{range}= [flags] Prints the last line number in {range}. For example,
  147. this prints the current line number: >
  148. :.=
  149. < See |ex-flags| for [flags].
  150. :norm[al][!] {commands} *:norm* *:normal*
  151. Execute Normal mode commands {commands}. This makes
  152. it possible to execute Normal mode commands typed on
  153. the command-line. {commands} are executed like they
  154. are typed. For undo all commands are undone together.
  155. Execution stops when an error is encountered.
  156. If the [!] is given, mappings will not be used.
  157. Without it, when this command is called from a
  158. non-remappable mapping (|:noremap|), the argument can
  159. be mapped anyway.
  160. {commands} should be a complete command. If
  161. {commands} does not finish a command, the last one
  162. will be aborted as if <Esc> or <C-C> was typed.
  163. This implies that an insert command must be completed
  164. (to start Insert mode, see |:startinsert|). A ":"
  165. command must be completed as well. And you can't use
  166. "Q" or "gQ" to start Ex mode.
  167. The display is not updated while ":normal" is busy.
  168. {commands} cannot start with a space. Put a count of
  169. 1 (one) before it, "1 " is one space.
  170. This command cannot be followed by another command,
  171. since any '|' is considered part of the command.
  172. This command can be used recursively, but the depth is
  173. limited by 'maxmapdepth'.
  174. An alternative is to use |:execute|, which uses an
  175. expression as argument. This allows the use of
  176. printable characters to represent special characters.
  177. Example: >
  178. :exe "normal \<c-w>\<c-w>"
  179. <
  180. :{range}norm[al][!] {commands} *:normal-range*
  181. Execute Normal mode commands {commands} for each line
  182. in the {range}. Before executing the {commands}, the
  183. cursor is positioned in the first column of the range,
  184. for each line. Otherwise it's the same as the
  185. ":normal" command without a range.
  186. *:sh* *:shell* *E371* *E360*
  187. :sh[ell] Removed. |vim-differences|
  188. *:terminal* *:te*
  189. :te[rminal][!] [{cmd}] Run {cmd} in a non-interactive 'shell' in a new
  190. |terminal-emulator| buffer. Without {cmd}, start an
  191. interactive 'shell'.
  192. Type |i| to enter |Terminal-mode|, then keys are sent to
  193. the job running in the terminal. Type <C-\><C-N> to
  194. leave Terminal-mode. |CTRL-\_CTRL-N|. Type <C-\><C-O>
  195. to execute a single normal mode command |t_CTRL-\_CTRL-O|
  196. Fails if changes have been made to the current buffer,
  197. unless 'hidden' is set.
  198. To enter |Terminal-mode| automatically: >
  199. autocmd TermOpen * startinsert
  200. <
  201. *:!cmd* *:!*
  202. :!{cmd} Execute {cmd} with 'shell'. See also |:terminal|.
  203. The command runs in a non-interactive shell connected
  204. to a pipe (not a terminal). Use |:terminal| to run an
  205. interactive shell connected to a terminal.
  206. Backgrounded ("&") commands must not write to stdout
  207. or stderr, the streams are closed immediately. |E5677|
  208. Use |jobstart()| instead. >
  209. :call jobstart('foo', {'detach':1})
  210. <
  211. *E34*
  212. Any "!" in {cmd} is replaced with the previous
  213. external command (see also 'cpoptions'), unless
  214. escaped by a backslash. Example: ":!ls" followed by
  215. ":!echo ! \! \\!" executes "echo ls ! \!".
  216. Any "|" in {cmd} is passed to the shell, you cannot
  217. use it to append a Vim command. See |:bar|.
  218. Any "%" in {cmd} is expanded to the current file name.
  219. Any "#" in {cmd} is expanded to the alternate file name.
  220. Special characters are not escaped, use quotes or
  221. |shellescape()|: >
  222. :!ls "%"
  223. :exe "!ls " .. shellescape(expand("%"))
  224. <
  225. Newline character ends {cmd} unless a backslash
  226. precedes the newline. What follows is interpreted as
  227. another |:| command.
  228. After the command has been executed, the timestamp and
  229. size of the current file is checked |timestamp|.
  230. If the command produces too much output some lines may
  231. be skipped so the command can execute quickly. No
  232. data is lost, this only affects the display. The last
  233. few lines are always displayed (never skipped).
  234. To avoid the hit-enter prompt use: >
  235. :silent !{cmd}
  236. <
  237. *:!!*
  238. :!! Repeat last ":!{cmd}".
  239. *:ve* *:ver* *:version*
  240. :ve[rsion] Print editor version and build information.
  241. See also |feature-compile|.
  242. *:redi* *:redir*
  243. :redi[r][!] > {file} Redirect messages to file {file}. The messages which
  244. are the output of commands are written to that file,
  245. until redirection ends. The messages are also still
  246. shown on the screen. When [!] is included, an
  247. existing file is overwritten. When [!] is omitted,
  248. and {file} exists, this command fails.
  249. Only one ":redir" can be active at a time. Calls to
  250. ":redir" will close any active redirection before
  251. starting redirection to the new target. For recursive
  252. use check out |execute()|.
  253. To stop the messages and commands from being echoed to
  254. the screen, put the commands in a function and call it
  255. with ":silent call Function()".
  256. Alternatives are the 'verbosefile' option or
  257. |execute()| function, these can be used in combination
  258. with ":redir".
  259. :redi[r] >> {file} Redirect messages to file {file}. Append if {file}
  260. already exists.
  261. :redi[r] @{a-zA-Z}
  262. :redi[r] @{a-zA-Z}> Redirect messages to register {a-z}. Append to the
  263. contents of the register if its name is given
  264. uppercase {A-Z}. The ">" after the register name is
  265. optional.
  266. :redi[r] @{a-z}>> Append messages to register {a-z}.
  267. :redi[r] @*>
  268. :redi[r] @+> Redirect messages to the selection or clipboard. For
  269. backward compatibility, the ">" after the register
  270. name can be omitted. See |quotestar| and |quoteplus|.
  271. :redi[r] @*>>
  272. :redi[r] @+>> Append messages to the selection or clipboard.
  273. :redi[r] @"> Redirect messages to the unnamed register. For
  274. backward compatibility, the ">" after the register
  275. name can be omitted.
  276. :redi[r] @">> Append messages to the unnamed register.
  277. :redi[r] => {var} Redirect messages to a variable. If the variable
  278. doesn't exist, then it is created. If the variable
  279. exists, then it is initialized to an empty string.
  280. The variable will remain empty until redirection ends.
  281. Only string variables can be used. After the
  282. redirection starts, if the variable is removed or
  283. locked or the variable type is changed, then further
  284. command output messages will cause errors. When using
  285. a local variable (l:var in a function or s:var in a
  286. script) and another `:redir` causes the current one to
  287. end, the scope might be different and the assignment
  288. fails.
  289. To get the output of one command the |execute()|
  290. function can be used instead of redirection.
  291. :redi[r] =>> {var} Append messages to an existing variable. Only string
  292. variables can be used.
  293. :redi[r] END End redirecting messages.
  294. *:filt* *:filter*
  295. :filt[er][!] {pattern} {command}
  296. :filt[er][!] /{pattern}/ {command}
  297. Restrict the output of {command} to lines matching
  298. with {pattern}. For example, to list only xml files: >
  299. :filter /\.xml$/ oldfiles
  300. < If the [!] is given, restrict the output of {command}
  301. to lines that do NOT match {pattern}.
  302. {pattern} is a Vim search pattern. Instead of enclosing
  303. it in / any non-ID character (see |'isident'|) can be
  304. used, so long as it does not appear in {pattern}.
  305. Without the enclosing character the pattern cannot
  306. include the bar character. 'ignorecase' is not used.
  307. The pattern is matched against the relevant part of
  308. the output, not necessarily the whole line. Only some
  309. commands support filtering, try it out to check if it
  310. works. Some of the commands that support filtering:
  311. |:#| - filter whole line
  312. |:clist| - filter by file name or module name
  313. |:command| - filter by command name
  314. |:files| - filter by file name
  315. |:highlight| - filter by highlight group
  316. |:jumps| - filter by file name
  317. |:let| - filter by variable name
  318. |:list| - filter whole line
  319. |:llist| - filter by file name or module name
  320. |:marks| - filter by text in the current file,
  321. or file name for other files
  322. |:oldfiles| - filter by file name
  323. |:registers| - filter by register contents
  324. (does not work multi-line)
  325. |:set| - filter by option name
  326. Only normal messages are filtered, error messages are
  327. not.
  328. *:sil* *:silent* *:silent!*
  329. :sil[ent][!] {command} Execute {command} silently. Normal messages will not
  330. be given or added to the message history.
  331. When [!] is added, error messages will also be
  332. skipped, and commands and mappings will not be aborted
  333. when an error is detected. |v:errmsg| is still set.
  334. When [!] is not used, an error message will cause
  335. further messages to be displayed normally.
  336. Redirection, started with |:redir|, will continue as
  337. usual, although there might be small differences.
  338. This will allow redirecting the output of a command
  339. without seeing it on the screen. Example: >
  340. :redir >/tmp/foobar
  341. :silent g/Aap/p
  342. :redir END
  343. < To execute a Normal mode command silently, use the
  344. |:normal| command. For example, to search for a
  345. string without messages: >
  346. :silent exe "normal /path\<CR>"
  347. < ":silent!" is useful to execute a command that may
  348. fail, but the failure is to be ignored. Example: >
  349. :let v:errmsg = ""
  350. :silent! /^begin
  351. :if v:errmsg != ""
  352. : ... pattern was not found
  353. < ":silent" also skips the hit-enter prompt.
  354. Dialogs that prompt for user input (|confirm()|,
  355. 'swapfile', …) are never silent.
  356. *:uns* *:unsilent*
  357. :uns[ilent] {command} Execute {command} not silently. Only makes a
  358. difference when |:silent| was used to get to this
  359. command.
  360. Use this for giving a message even when |:silent| was
  361. used. In this example |:silent| is used to avoid the
  362. message about reading the file and |:unsilent| to be
  363. able to list the first line of each file. >
  364. :silent argdo unsilent echo expand('%') .. ": " .. getline(1)
  365. <
  366. *:verb* *:verbose*
  367. :[count]verb[ose] {command}
  368. Execute {command} with 'verbose' set to [count]. If
  369. [count] is omitted one is used. ":0verbose" can be
  370. used to set 'verbose' to zero.
  371. The additional use of ":silent" makes messages
  372. generated but not displayed.
  373. The combination of ":silent" and ":verbose" can be
  374. used to generate messages and check them with
  375. |v:statusmsg| and friends. For example: >
  376. :let v:statusmsg = ""
  377. :silent verbose runtime foobar.vim
  378. :if v:statusmsg != ""
  379. : " foobar.vim could not be found
  380. :endif
  381. < When concatenating another command, the ":verbose"
  382. only applies to the first one: >
  383. :4verbose set verbose | set verbose
  384. < verbose=4 ~
  385. verbose=0 ~
  386. For logging verbose messages in a file use the
  387. 'verbosefile' option.
  388. *:verbose-cmd*
  389. When 'verbose' is non-zero, listing the value of a Vim option or a key map or
  390. an abbreviation or a user-defined function or a command or a highlight group
  391. or an autocommand will also display where it was last defined. If they were
  392. defined in Lua they will only be located if 'verbose' is set. So Start
  393. nvim with -V1 arg to see them. If it was defined manually then there
  394. will be no "Last set" message. When it was defined while executing a function,
  395. user command or autocommand, the script in which it was defined is reported.
  396. *K*
  397. [count]K Runs the program given by 'keywordprg' to lookup the
  398. |word| (defined by 'iskeyword') under or right of the
  399. cursor. Default is "man". Works like this: >
  400. :tabnew | terminal {program} {keyword}
  401. < Special cases:
  402. - If 'keywordprg' begins with ":" it is invoked as
  403. a Vim command with [count].
  404. - If 'keywordprg' is empty, |:help| is used.
  405. - When 'keywordprg' is equal to "man", a [count]
  406. before "K" is inserted after the "man" command and
  407. before the keyword. For example, using "2K" while
  408. the cursor is on "mkdir", results in: >
  409. !man 2 mkdir
  410. < - When 'keywordprg' is equal to "man -s", a [count]
  411. before "K" is inserted after the "-s". If there is
  412. no count, the "-s" is removed.
  413. *v_K*
  414. {Visual}K Like "K", but use the visually highlighted text for
  415. the keyword. Only works when the highlighted text is
  416. not more than one line.
  417. *gO*
  418. gO Show a filetype-specific, navigable "outline" of the
  419. current buffer. For example, in a |help| buffer this
  420. shows the table of contents.
  421. Currently works in |help| and |:Man| buffers.
  422. [N]gs *gs* *:sl* *:sleep*
  423. :[N]sl[eep] [N][m] Do nothing for [N] seconds, or [N] milliseconds if [m]
  424. was given. "gs" always uses seconds.
  425. Default is one second. >
  426. :sleep "sleep for one second
  427. :5sleep "sleep for five seconds
  428. :sleep 100m "sleep for 100 milliseconds
  429. 10gs "sleep for ten seconds
  430. < Can be interrupted with CTRL-C.
  431. "gs" stands for "goto sleep".
  432. While sleeping the cursor is positioned in the text,
  433. if at a visible position.
  434. Queued messages are processed during the sleep.
  435. *:sl!* *:sleep!*
  436. :[N]sl[eep]! [N][m] Same as above. Unlike Vim, it does not hide the
  437. cursor. |vim-differences|
  438. ==============================================================================
  439. 2. Using Vim like less or more *less*
  440. If you use the less or more program to view a file, you don't get syntax
  441. highlighting. Thus you would like to use Vim instead. You can do this by
  442. using the shell script "$VIMRUNTIME/macros/less.sh".
  443. This shell script uses the Vim script "$VIMRUNTIME/macros/less.vim". It sets
  444. up mappings to simulate the commands that less supports. Otherwise, you can
  445. still use the Vim commands.
  446. This isn't perfect. For example, when viewing a short file Vim will still use
  447. the whole screen. But it works well enough for most uses, and you get syntax
  448. highlighting.
  449. The "h" key will give you a short overview of the available commands.
  450. If you want to set options differently when using less, define the
  451. LessInitFunc in your vimrc, for example: >
  452. func LessInitFunc()
  453. set nocursorcolumn nocursorline
  454. endfunc
  455. <
  456. vim:noet:tw=78:ts=8:ft=help:norl: