Nvim :help pages, generated
from source
using the tree-sitter-vimdoc parser.
<Insert> key, you can toggle between inserting and overstriking characters.:cnoremap <C-A> <Home> :cnoremap <C-F> <Right> :cnoremap <C-B> <Left> :cnoremap <Esc>b <S-Left> :cnoremap <Esc>f <S-Right>(<> notation <>; type all this literally)
CTRL-V is often mapped to paste text.
Use CTRL-Q instead then.
c_CTRL-Q CTRL-V. But with some terminals it is used for
control flow, it doesn't work then.CTRL-V, but do not try to include the CTRL
modifier into the key.
Note: When CTRL-SHIFT-V is intercepted by your system (e.g.,
to paste text) you can often use CTRL-SHIFT-Q instead.
However, in some terminals (e.g. GNOME Terminal), CTRL-SHIFT-Q
quits the terminal without confirmation.<Left> cursor left. See 'wildmenu' for behavior during wildmenu
completion mode.
c_<Right> c_Right
<Right> cursor right. See 'wildmenu' for behavior during wildmenu
completion mode.
c_<S-Left> <S-Left> or <C-Left> c_<C-Left> <S-Right> or <C-Right> c_<C-Right> <Home> c_CTRL-B c_<Home> c_Home
cursor to beginning of command-line
CTRL-E or <End> c_CTRL-E c_<End> c_End
cursor to end of command-line. See 'wildmenu' for behavior
during wildmenu completion mode.<MiddleMouse> Paste the contents of the clipboard (for X11 the primary
selection). This is similar to using CTRL-R *, but no CR
characters are inserted between lines.<BS> Delete the character in front of the cursor.
c_<Del> c_Del
<Del> Delete the character under the cursor (at end of line:
character before the cursor).
c_CTRL-W :cnoremap <C-U> <C-E><C-U>
{char1} <BS> {char2} or c_digraph {char1} {char2} c_CTRL-K {char1} is a special
key, the code for that key is inserted in <> form.{register} c_CTRL-R c_<C-R>
Insert the contents of a numbered or named register. Between
typing CTRL-R and the second character '"' will be displayed
to indicate that you are expected to enter the name of a
register.
When used with named or clipboard registers (A-Z,a-z,0-9,+)
text is inserted literally like pasting with "p". For other
registers, the text is inserted as if you typed it, but
mappings and abbreviations are not used. Command-line
completion through 'wildchar' is not triggered though. And
characters that end the command line are inserted literally
(<Esc>, <CR>, <NL>, <C-C>). A <BS> or CTRL-W could still end
the command line though, and remaining characters will then be
interpreted in another mode, which might not be what you
intended.
Special registers:
'"' the unnamed register, containing the text of
the last delete or yank
'%' the current file name
'#' the alternate file name
"*" the clipboard contents (X11: primary
selection)
'+' the clipboard contents
'/' the last search pattern
':' the last command-line
'-' the last small (less than a line) delete
'.' the last inserted text
c_CTRL-R_= <C-R><C-R>=setcmdpos(2)[-1]<CR>
CTRL-R =@reg.
See registers about registers.
Implementation detail: When using the expression register
and invoking setcmdpos(), this sets the position before
inserting the resulting string. Use CTRL-R CTRL-R to set the
position afterwards.CTRL-F c_CTRL-R_CTRL-F c_<C-R>_<C-F>
CTRL-R CTRL-P c_CTRL-R_CTRL-P c_<C-R>_<C-P>
CTRL-R CTRL-W c_CTRL-R_CTRL-W c_<C-R>_<C-W>
CTRL-R CTRL-A c_CTRL-R_CTRL-A c_<C-R>_<C-A>
CTRL-R CTRL-L c_CTRL-R_CTRL-L c_<C-R>_<C-L>
Insert the object under the cursor:
CTRL-F the Filename under the cursor
CTRL-P the Filename under the cursor, expanded with
'path' as in gf
CTRL-W the Word under the cursor
CTRL-A the WORD under the cursor; see WORD
CTRL-L the line under the cursorCTRL-W the part of
the word that was already typed is not inserted again.CTRL-R {register CTRL-F CTRL-P CTRL-W CTRL-A CTRL-L}
CTRL-R CTRL-O {register CTRL-F CTRL-P CTRL-W CTRL-A CTRL-L}
Insert register or object under the cursor. Works like
c_CTRL-R but inserts the text literally. For example, if
register a contains "xy^Hz" (where ^H is a backspace),
"CTRL-R a" will insert "xz" while "CTRL-R CTRL-R a" will
insert "xy^Hz".CTRL-\ e {expr} c_CTRL-\_e {expr} and replace the whole command line with the
result. You will be prompted for the expression, type <Enter>
to finish it. It's most useful in mappings though. See
expression.
See c_CTRL-R_= for inserting the result of an expression.
Useful functions are getcmdtype(), getcmdline() and
getcmdpos().
The cursor position is unchanged, except when the cursor was
at the end of the line, then it stays at the end.
setcmdpos() can be used to set the cursor position.
The sandbox is used for evaluating the expression to avoid
nasty side effects.
Example::cmap <F7> <C-\>eAppendSome()<CR> :func AppendSome() :let cmd = getcmdline() .. " Some()" :" place the cursor on the ) :call setcmdpos(strlen(cmd)) :return cmd :endfunc
CTRL-Y is inserted as a character.
See 'wildmenu' for behavior during wildmenu completion mode.CTRL-[ c_CTRL-[ c_<Esc> c_Esc
<Esc> When typed and 'x' not present in 'cpoptions', quit
Command-line mode without executing. In macros or when 'x'
present in 'cpoptions', start entered command.
Note: If your <Esc> key is hard to hit on your keyboard, train
yourself to use CTRL-[.
c_META c_ALT
ALT (META) may act like <Esc> if the chord is not mapped.
For example <A-x> acts like <Esc>x if <A-x> does not have a
command-line mode mapping.
c_CTRL-C <Up> recall older command-line from history, whose beginning
matches the current command-line (see below). See 'wildmenu'
for behavior during wildmenu completion mode.
c_<Down> c_Down
<Down> recall more recent command-line from history, whose beginning
matches the current command-line (see below). See 'wildmenu'
for behavior during wildmenu completion mode.<S-Up> or <PageUp>
recall older command-line from history
c_<S-Down> c_<PageDown>
<S-Down> or <PageDown>
recall more recent command-line from historyCTRL-^ Toggle the use of language :lmap mappings and/or Input
Method.
When typing a pattern for a search command and 'imsearch' is
not -1, VAL is the value of 'imsearch', otherwise VAL is the
value of 'iminsert'.
When language mappings are defined:
CTRL-^, the new state is not used again
for the next command or Search pattern.
<Up> and <Down> keys take the current command-line as a search string.
The beginning of the next/previous command-lines are compared with this
string. The first line that matches is the new command-line. When typing
these two keys repeatedly, the same string is used again. For example, this
can be used to find the previous substitute command: Type ":s" and then <Up>.
The same could be done by typing <S-Up> a number of times until the desired
command-line is shown. (Note: the shifted arrow keys do not work on all
terminals){name}] [{first}][, [{last}]]
List the contents of history {name} which can be:
c[md] or : command-line history
s[earch] or / or ? search string history
e[xpr] or = expression register history
i[nput] or @ input line history
d[ebug] or > debug command history
a[ll] all of the above{first} and/or {last} are given, the respective
range of entries from a history is listed. These numbers can
be specified in the following form:
:history-indexing :history / 6,12
:history all -2
:history all -2,:keepp[atterns]
{command} :keepp :keeppatterns
Execute {command}, without adding anything to the search
history and, in case of :s or :&, without modifying the
last substitute pattern or substitute string.<Tab>),
see cmdline-autocompletion.<Tab> or <Esc> are mostly used as 'wildchar',
and these have a special meaning in some macros.) When typed
again and there were multiple matches, the next
match is inserted. After the last match, the first is used
again (wrap around).<CTRL-V><Tab> or "\t" to search for a
literal <Tab> instead of triggering completion.<S-Tab> Like 'wildchar' or <Tab>, but begin with the last match and
then go to the previous match.CTRL-L will add
one character from the end of the current match. If
'ignorecase' and 'smartcase' are set and the command line has
no uppercase characters, the added character is converted to
lowercase.CTRL-G
moves to the next match (without changing the jumplist).
The search-offset is applied when <CR> is pressed, but does
not affect the match highlighting.CTRL-T to move to the previous match.
Mnemonic: on a regular keyboard G is below T.CTRL-T
moves to the previous match (without changing the jumplist).
The search-offset is applied when <CR> is pressed, but does
not affect the match highlighting.CTRL-G to move to the next match.
Mnemonic: on a regular keyboard T is above G.<Tab> (CTRL-E when in Vi compatible mode; in
a previous version <Esc> was used). In the pattern standard wildcards are
accepted when matching file names.CTRL-N you cycle through the matches, eventually
ending up back to what was typed. If the first match is not what you wanted,
you can use <S-Tab> or CTRL-P to go straight back to what you typed.:cnoremap X <C-L><C-D>(Where X is the command key to use,
<C-L> is CTRL-L and <C-D> is CTRL-D)
This will find the longest match and then list all matching files.:set wildmode=longest,listThis will find the longest match with the first 'wildchar', then list all matching files with the next.
CTRL-N or CTRL-P. All files are included, also the ones with
extensions matching the 'suffixes' option.:e *.c$This will not match a file ending in ".cpp". Without the "$" it does match.
<S-Tab> for CTRL-P in an xterm, put this command in
your .cshrc:xmodmap -e "keysym Tab = Tab Find"And this in your vimrc:
:cmap <Esc>[1~ <C-P>
:set ai "set 'autoindent' optionIt is not possible to add a comment to a shell command ":!cmd" or to the ":map" command and a few others (mainly commands that expect expressions) that see the '"' as part of their argument:
:execute 'r !ls' | '[There is one exception: When the 'b' flag is present in 'cpoptions', with the ":map" and ":abbr" commands and friends
CTRL-V needs to be used instead of
'\'. You can also use "<Bar>" instead. See also map_bar.:!ls | wc view the output of two commands
:r !ls | wc insert the same output in the text
:%g/foo/p|> moves all matching lines one shiftwidth
:%s/foo/bar/|> moves one line one shiftwidth
:map q 10^V| map "q" to "10|"
:map q 10\| map \ l map "q" to "10\" and map "\" to "l"
(when 'b' is present in 'cpoptions')
You can also use <NL> to separate commands in the same way as with '|'. To
insert a <NL> use CTRL-V CTRL-J. "^@" will be shown. Using '|' is the
preferred method. But for external commands a <NL> must be used, because a
'|' is included in the external command. To avoid the special meaning of <NL>
it must be preceded with a backslash. Example::r !date<NL>-joinThis reads the current date into the file and joins it with the previous line.
:| print current line (like ":p") :3| print line 3 (like ":3p") :3 goto line 3A colon is allowed between the range and the command name. It is ignored (this is Vi compatible). For example:
:1,$:s/pat/stringWhen the character '%' or '#' is used where a file name is expected, they are expanded to the current and alternate file name (see the chapter "editing files" :_% :_#).
CTRL-V. Note that the ":next" command uses spaces to separate file names.
Escape the spaces to include them in a file name. Example::next foo\ bar goes\ to school\starts editing the three files "foo bar", "goes to" and "school ".
4,/this line/
5;/that line/
:-2,+,-2,. print<When semicolon separated, the leftmost specifier to the penultimate one are summed, e.g., -4 + 3 - 1 = -2, in this:
:-4;+3;-1;+2 print
{number} an absolute line number E1247
. the current line :. {a-z} mark)
'X the line of the position of mark X :'X {A-Z0-9} mark, though
when X is in another buffer it cannot
be used in a range)
'[ the first line of the most recent :'[ {pattern} matches :/ {pattern} matches :?
also see :range-pattern below
\/ the next line where the most recent
search pattern matches
\? the previous line where the most recent
search pattern matches
\& the next line where the most recent
substitute pattern matches:-11;+1 print
:-----------,-10 print
:?Each line?-;+ print
:'{+,'{+2 print
:'{+1;')-1 print:3,4+2printOn this text:
:2,4-1printOn this text:
{pattern} are required to separate the pattern from
anything that follows./pat1//pat2/ Find line containing "pat2" after line containing
"pat1", without moving the cursor.
7;/pat2/ Find line containing "pat2", after line 7, leaving
the cursor in line 7.
The {number} must be between 0 and the number of lines in the file. When
using a 0 (zero) this is interpreted as a 1 by most commands. Commands that
use it as a count do use it as a zero (:tag, :pop, etc). Some commands
interpret the zero as "before the first line" (:read, search pattern, etc)..+3 three lines below the cursor
/that/+1 the line below the next line containing "that"
.,$ from current line until end of file
0;/that the first line containing "that", also matches in the
first line.
1;/that the first line after line 1 containing "that"
Some commands allow for a count after the command. This count is used as the
number of lines to be used, starting with the line given in the last line
specifier (the default is the cursor line). The commands that accept a count
are the ones that use a range but do not have a file name argument (because
a file name can also be a number). The count cannot be negative.:s/x/X/g 5 substitute 'x' by 'X' in the current line and four
following lines
:23d 4 delete lines 23, 24, 25 and 26
Folds and Range:.,.+(count - 1)In words: The "count" lines at and after the cursor. Example: To delete three lines:
3:d<CR> is translated into: .,.+2d<CR>
{Visual}: Starts a command-line with the Visual selected lines as a
range. The code :'<,'> is used for this range, which makes
it possible to select a similar line from the command-line
history for repeating a command on different Visually selected
lines.:*.CTRL-R command. For
example, "%" stands for the current file name, while CTRL-R % inserts the
current file name right away. See c_CTRL-R.:!ls "%" :r !spell "%"To avoid the special meaning of '%' and '#' insert a backslash before it. Detail: The special meaning is always escaped when there is a backslash before it, no matter how many backslashes.
<cword> is replaced with the word under the cursor (like star)
:<cWORD> <cWORD>
<cWORD> is replaced with the WORD under the cursor (see WORD)
:<cexpr> <cexpr>
<cexpr> is replaced with the word under the cursor, including more
to form a C expression. E.g., when the cursor is on "arg"
of "ptr->arg" then the result is "ptr->arg"; when the
cursor is on "]" of "list[idx]" then the result is
"list[idx]".
:<cfile> <cfile>
<cfile> is replaced with the path name under the cursor (like what
gf uses)
:<afile> <afile>
<afile> When executing autocommands, is replaced with the file name
of the buffer being manipulated, or the file for a read or
write. E495
:<abuf> <abuf>
<abuf> When executing autocommands, is replaced with the currently
effective buffer number. It is not set for all events,
also see bufnr(). For ":r file" and ":so file" it is the
current buffer, the file being read/sourced is not in a
buffer. E496
:<amatch> <amatch>
<amatch> When executing autocommands, is replaced with the match for
which this autocommand was executed. E497
It differs from <afile> when the file name isn't used to
match with (for FileType, Syntax and SpellFileMissing
events).
When the match is with a file name, it is expanded to the
full path.
:<stack> <stack>
<stack> is replaced with the call stack, using
"function {function-name}[{lnum}]" for a function line
and "script {file-name}[{lnum}]" for a script line, and
".." in between items. E.g.:
"function {function-name1}[{lnum}]..{function-name2}[{lnum}]"
If there is no call stack you get error E489 .
:<script> <script> E498
<script> When executing a :source command, is replaced with the file
name of the sourced file. When executing a function, is
replaced with the file name of the script where it is
defined.
If the file name cannot be determined you get error E1274 .
:<slnum> <slnum>
<slnum> When executing a :source command, is replaced with the
line number. E842
When executing a function it's the line number relative to
the start of the function.
:<sflnum> <sflnum>
<sflnum> When executing a script, is replaced with the line number.
It differs from <slnum> in that <sflnum> is replaced with
the script line number in any situation. E961:!dir <cfile>:S
:call system('chmod +w -- ' .. expand('%:S'))
Examples, when the file name is "src/version.c", current dir
"/home/mool/vim"::p /home/mool/vim/src/version.c :p:. src/version.c :p:~ ~/vim/src/version.c :h src :p:h /home/mool/vim/src :p:h:h /home/mool/vim :t version.c :p:t version.c :r src/version :p:r /home/mool/vim/src/version :t:r version :e c :s?version?main? src/main.c :s?version?main?:p /home/mool/vim/src/main.c :p:gs?/?\\? \home\mool\vim\src\version.cExamples, when the file name is "src/version.c.gz":
:p /home/mool/vim/src/version.c.gz :e gz :e:e c.gz :e:e:e c.gz :e:e:r c :r src/version.c :r:e c :r:r src/version :r:r:r src/version
% current file name %< current file name without extension # alternate file name for current window #< idem, without extension #31 alternate file number 31 #31< idem, without extension <cword> word under the cursor <cWORD> WORD under the cursor (see |WORD|) <cfile> path name under the cursor <cfile>< idem, without extensionNote: Where a file name is expected wildcards expansion is done. On Unix the shell is used for this, unless it can be done internally (for speed). Backticks work also, like in
:n `echo *.c`But expansion is only done if there are any wildcards before expanding the '%', '#', etc.. This avoids expanding wildcards inside a file name. If you want to expand the result of
<cfile>, add a wildcard character to it.
Examples: (alternate file name is "?readme?")
command expands to:e # :e ?readme?
:e `ls #` :e {files matching "?readme?"}
:e #.* :e {files matching "?readme?.*"}
:cd <cfile> :cd {file name under cursor}
:cd <cfile>* :cd {file name under cursor plus "*" and then expanded}
Also see `=.<C-F> (or the 'cedit' key).
<Enter> Execute the command-line under the cursor, then close the
window(s) where cmdwin is visible. Works both in Insert and
in Normal mode.
CTRL-C Continue in Command-line mode. The command-line under the
cursor is pre-filled in the command-line. Works both in
Insert and in Normal mode.
:quit Discard the command line and go back to Normal mode.
":close", CTRL-W c, ":exit", ":xit" and CTRL-\ CTRL-N also
work.
:qall Quit Nvim, unless there are changes in some buffer.
:qall! Quit Nvim, discarding changes to any buffer.bufhidden=wipe). Any text edits other than the line executed by <Enter>
are lost.:autocmd CmdwinEnter * map <buffer> <F5> <CR>q:
<Tab>, and the command-line window is used
for an Ex command, then two mappings will be added to use <Tab> for completion
in the command-line window, like this::inoremap <buffer> <Tab> <C-X><C-V> :nnoremap <buffer> <Tab> a<C-X><C-V>Note that hitting
<Tab> in Normal mode will do completion on the next
character. That way it works at the end of the line.
If you don't want these mappings, disable them with:au CmdwinEnter [:>] iunmap <buffer> <Tab> au CmdwinEnter [:>] nunmap <buffer> <Tab>You could put these lines in your vimrc file.
autocmd CmdwinEnter [:>] syntax sync minlines=1 maxlines=1
:au CmdwinEnter : let b:cpt_save = &cpt | set cpt=. :au CmdwinLeave : let &cpt = b:cpt_saveThis sets 'complete' to use completion in the current window for i_CTRL-N. Another example:
:au CmdwinEnter [\/\?] startinsertThis will make Vim start in Insert mode in the command-line window. Note: The "/" and "?" needs to be escaped, as this is a file-pattern. See also cmdline-autocompletion.
- text for :insert or :appendautocmd CmdlineChanged [:\/\?] call wildtrigger() set wildmode=noselect:lastused,full set wildoptions=pumWith this configuration, suggestions appear immediately, and you can move through them with
<Tab> or the arrow keys.<Up>/<Down>:cnoremap <expr> <Up> wildmenumode() ? "\<C-E>\<Up>" : "\<Up>" cnoremap <expr> <Down> wildmenumode() ? "\<C-E>\<Down>" : "\<Down>"Options can also be applied only for specific command-lines. For example, to use a shorter popup menu height only during search:
autocmd CmdlineEnter [\/\?] set pumheight=8 autocmd CmdlineLeave [\/\?] set pumheight&
set findfunc=Find
func Find(arg, _)
if empty(s:filescache)
let s:filescache = globpath('.', '**', 1, 1)
call filter(s:filescache, '!isdirectory(v:val)')
call map(s:filescache, "fnamemodify(v:val, ':.')")
endif
return a:arg == '' ? s:filescache : matchfuzzy(s:filescache, a:arg)
endfunc
let s:filescache = []
autocmd CmdlineEnter : let s:filescache = []
The :Grep command searches for lines matching a pattern and updates the
results dynamically as you type (triggered after two characters; note: needs
the CmdlineLeavePre autocmd from the next section):
command! -nargs=+ -complete=customlist,<SID>Grep
\ Grep call <SID>VisitFile()
func s:Grep(arglead, cmdline, cursorpos)
if match(&grepprg, '\$\*') == -1 | let &grepprg ..= ' $*' | endif
let cmd = substitute(&grepprg, '\$\*', shellescape(escape(a:arglead, '\')), '')
return len(a:arglead) > 1 ? systemlist(cmd) : []
endfunc
func s:VisitFile()
let item = getqflist(#{lines: [s:selected]}).items[0]
let pos = '[0,\ item.lnum,\ item.col,\ 0]'
exe $':b +call\ setpos(".",\ {pos}) {item.bufnr}'
call setbufvar(item.bufnr, '&buflisted', 1)
endfunc
Automatically select the first item in the completion list when leaving the
command-line, and for :Grep, add the typed pattern to the command-line
history:
autocmd CmdlineLeavePre :
\ if get(cmdcomplete_info(), 'matches', []) != [] |
\ let s:info = cmdcomplete_info() |
\ if getcmdline() =~ '^\s*fin\%[d]\s' && s:info.selected == -1 |
\ call setcmdline($'find {s:info.matches[0]}') |
\ endif |
\ if getcmdline() =~ '^\s*Grep\s' |
\ let s:selected = s:info.selected != -1
\ ? s:info.matches[s:info.selected] : s:info.matches[0] |
\ call setcmdline(s:info.cmdline_orig) |
\ endif |
\ endif
For autocompletion in insert mode, see ins-autocompletion.