Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
nvim filenameMore generally, Nvim is started with:
nvim [option | filename] ..Option arguments and file name arguments can be mixed, and any number of them can be given. However, watch out for options that take an argument.
-file
---
filename One or more file names. The first one will be the current
file and read into the buffer. The cursor will be positioned
on the first line of the buffer.
To avoid a file name starting with a '-' being interpreted as
an option, precede the arglist with "--", e.g.:nvim -- -filename
echo text | nvim file
" Don't set 'modified' when reading from stdin au StdinReadPost * set nomodified
echo "ifoo" | nvim -s -
echo foo | nvim -- -
-t
-tag
-t {tag}
A tag. "tag" is looked up in the tags file, the associated
file becomes the current file, and the associated command is
executed. Mostly this is used for C programs, in which case
"tag" often is a function name. The effect is that the file
containing that function becomes the current file and the
cursor is positioned on the start of the function (see
tags).-q
-qf
-q [errorfile] QuickFix mode. The file with the name [errorfile] is read
and the first error is displayed. See quickfix.
If [errorfile] is not given, the 'errorfile' option is used
for the file name. See 'errorfile' for the default value.startup-options
The option arguments may be given in any order. Single-letter options can be
combined after one dash. There can be no option arguments after the "--"
argument.--clean
--clean Mimics a fresh install of Nvim:
--noplugin
--noplugin Skip loading plugins. Resets the 'loadplugins' option.
Note that the -u argument may also disable loading plugins:
{fname}
--startuptime
During startup write timing messages to the file {fname}
.
This can be used to find out where time is spent while loading
your config, plugins and opening the first file.
When {fname}
already exists new messages are appended.-+
+[num] The cursor will be positioned on line "num" for the first
file being edited. If "num" is missing, the cursor will be
positioned on the last line.-+/
+/{pat} The cursor will be positioned on the first line containing
"pat" in the first file being edited (see pattern for the
available search patterns). The search starts at the cursor
position, which can be the first line or the cursor position
last used from shada. To force a search from the first
line use "+1 +/pat".-+c
-c
-c {command}
{command}
will be executed after the first file has been
read (and after autocommands and modelines for that file have
been processed). "command" is interpreted as an Ex command.
If the "command" contains spaces, it must be enclosed in
double quotes (this depends on the shell that is used).
Example:vim "+set si" main.c vim "+find stdio.h" vim -c "set ff=dos" -c wq mine.mak
{command}
--cmd
{command}
will be executed before processing any vimrc file.
Otherwise, it acts like -c {command}
. You can use up to 10 of
these commands, independently from "-c" commands.-S
-S [file] Executes Vimscript or Lua (".lua") [file] after the first file
has been read. See also :source. If [file] is not given,
defaults to "Session.vim". Equivalent to:-c "source {file}"
{file}
cannot start with a "-".-L
-r
-r Recovery mode. Without a file name argument, a list of
existing swap files is given. With a file name, a swap file
is read to recover a crashed editing session. See
crash-recovery.-R
-R Readonly mode. The 'readonly' option will be set for all the
files being edited. You can still edit the buffer, but will
be prevented from accidentally overwriting a file. If you
forgot that you are in View mode and did make some changes,
you can overwrite a file by adding an exclamation mark to
the Ex command, as in ":w!". The 'readonly' option can be
reset with ":set noro" (see the options chapter, options).
Subsequent edits will not be done in readonly mode. Calling
the executable "view" has the same effect as the -R argument.
The 'updatecount' option will be set to 10000, meaning that
the swap file will not be updated automatically very often.
See -M for disallowing modifications.-m
-m Modifications not allowed to be written. The 'write' option
will be reset, so that writing files is disabled. However,
the 'write' option can be set to enable writing again.-M
-M Modifications not allowed. The 'modifiable' option will be
reset, so that changes are not allowed. The 'write' option
will be reset, so that writing files is disabled. However,
the 'modifiable' and 'write' options can be set to enable
changes and writing.-es
-Es
-s-ex
silent-mode
-Es Script mode, aka "silent mode", aka "batch mode". No UI,
disables most prompts and messages. Unrelated to -s.
See also -S to run script files.printf "put ='foo'\n%%print\n" | nvim -es
printf "foo\n" | nvim -Es +"%print"
nvim -es +":verbose echo 'foo'" nvim -V1 -es +foo
-l
-l {script}
[args]
Executes Lua {script}
non-interactively (no UI) with optional
[args] after processing any preceding Nvim cli-arguments,
then exits. Exits 1 on Lua error. See -S to run multiple Lua
scripts without args, with a UI.
lua-args
All [args] are treated as {script}
arguments and stored in the
Lua _G.arg
global table, thus "-l" ends processing of Nvim
arguments. The {script}
name is stored at _G.arg[0]
.print()
writes to
output.
If {script}
prints messages and doesn't cause Nvim to exit,
Nvim ensures output ends with a newline.{script}
.
This example quits before executing "foo.lua":nvim +q -l foo.lua
nvim +"lua require('bar')" -l foo.lua
-ll
-ll {script}
[args]
Execute a Lua script, similarly to -l, but the editor is not
initialized. This gives a Lua environment similar to a worker
thread. See lua-loop-threading.-l
no prior arguments are allowed.-b
-b Binary mode. File I/O will only recognize <NL>
to separate
lines. The 'expandtab' option will be reset. The 'textwidth'
option is set to 0. 'modeline' is reset. The 'binary' option
is set. This is done after reading the vimrc but before
reading any file in the arglist. See also edit-binary.-V
verbose
-V[N] Verbose. Sets the 'verbose' option to [N] (default: 10).
Messages will be given for each file that is ":source"d and
for reading or writing a ShaDa file. Can be used to find
out what is happening upon startup and exit.
Example:nvim -V8-V[N]{file} Like -V and sets 'verbosefile' to
{file}
(must not start with
a digit). Messages are not displayed, instead they are
written to {file}
.
Example:nvim -V20vimlog
-D
-D Debugging. Go to debugging mode when executing the first
command from a script. debug-mode-n
-n No swap-file will be used. Recovery after a crash will be
impossible. Handy if you want to view or edit a file on a
very slow medium (e.g., a floppy).
Can also be done with ":set updatecount=0". You can switch it
on again by setting the 'updatecount' option to some value,
e.g., ":set uc=100".
'updatecount' is set to 0 AFTER executing commands from a
vimrc file, but before the GUI initializations. Thus it
overrides a setting for 'updatecount' in a vimrc file, but not
in a gvimrc file. See startup.
When you want to reduce accesses to the disk (e.g., for a
laptop), don't use "-n", but set 'updatetime' and
'updatecount' to very big numbers, and type ":preserve" when
you want to save your work. This way you keep the possibility
for crash recovery.-o
-o[N] Open N windows, split horizontally. If [N] is not given,
one window is opened for every file given as argument. If
there is not enough room, only the first few files get a
window. If there are more windows than arguments, the last
few windows will be editing an empty file.-O
-O[N] Open N windows, split vertically. Otherwise, it's like -o.
If both the -o and the -O option are given, the last one on
the command line determines how the windows will be split.-p
-p[N] Open N tab pages. If [N] is not given, one tab page is opened
for every file given as argument. The maximum is set with
'tabpagemax' pages (default 50). If there are more tab pages
than arguments, the last few tab pages will be editing an
empty file. Also see tabpage.
-d
-d Start in diff-mode.-u
E282
-u {vimrc}
The file {vimrc}
is read for initializations. Most other
initializations are skipped; see initialization.alias vimc 'nvim -u ~/.config/nvim/c_init.vim \!*'
alias vimc='nvim -u ~/.config/nvim/c_init.vim'
{vimrc}
is "NONE" (all uppercase), all initializations
from files and environment variables are skipped. Plugins and
syntax highlighting are also skipped.{vimrc}
is "NORC" (all uppercase), this has the same
effect as "NONE", but plugins and syntax highlighting are not
skipped.-i
-i {shada}
The file {shada}
is used instead of the default ShaDa
file. If the name "NONE" is used (all uppercase), no ShaDa
file is read or written, even if 'shada' is set or when
":rsh" or ":wsh" are used. See also shada-file.-s
-s {scriptin}
Read script file {scriptin}
, interpreting characters as
Normal-mode input. The same can be done with ":source!"::source! {scriptin}
{scriptin}
is "-":echo "ifoo" | nvim -s -
-w
-w {scriptout}
All keys that you type are recorded in the file "scriptout",
until you exit Vim. Useful to create a script file to be used
with "vim -s" or ":source!". Appends to the "scriptout" file
if it already exists. {scriptout}
cannot start with a digit.
See also vim.on_key().
See also complex-repeat.-W
-W {scriptout}
Like -w, but do not append, overwrite an existing file.--api-info
--api-info Print msgpack-encoded api-metadata and exit.--embed
--embed Use stdin/stdout as a msgpack-RPC channel, so applications can
embed and control Nvim via the RPC API.nvim_ui_attach
(e.g. nvim_get_api_info
for feature-detection).
During this pre-startup phase the user config is of course not
available (similar to --cmd
).nvim --embed --headless
nvim_ui_attach
.
This is equivalent to:nvim --headless --cmd "call stdioopen({'rpc': v:true})"
nvim --embed --listen addr
--headless
--headless Start without UI, and do not wait for nvim_ui_attach
. The
builtin TUI is not used, so stdio works as an arbitrary
communication channel. channel-stdioecho foo | nvim --headless +"%print" +"q!" -
{addr}
--listen
Start RPC server on pipe or TCP address {addr}
. Sets the
primary listen address v:servername to {addr}
. serverstart()SHELL
COMSPEC
The environment variable SHELL, if it exists, is used to set the
'shell' option. On Win32, the COMSPEC variable is used
if SHELL is not set.:runtime! ftplugin.vim indent.vim
<NL>
).
config
init.vim
init.lua
vimrc
exrc
A file containing initialization commands is generically called
a "vimrc" or config file. It can be either Vimscript ("init.vim") or
Lua ("init.lua"), but not both. E5422
See also vimrc-intro and base-directories.{file}
" then {file}
is used as the config
and all initializations until 8. are skipped. $MYVIMRC is not set.
"nvim -u NORC" can be used to skip these initializations without
reading a file. "nvim -u NONE" also skips plugins and syntax
highlighting. -usystem-vimrc
sysinit.vim
a. The system vimrc file is read for initializations. If
nvim/sysinit.vim file exists in one of $XDG_CONFIG_DIRS, it will be
used. Otherwise the system vimrc file is used. The path of this file
is given by the :version command. Usually it's "$VIM/sysinit.vim".VIMINIT
EXINIT
$MYVIMRC
b. Locations searched for initializations, in order of preference:
{dir}
/nvim/init.vim (or init.lua) where {dir}
is any
directory in $XDG_CONFIG_DIRS.
:runtime! filetype.lua
:runtime! syntax/syntax.vim
load-plugins
This does the same as the command::runtime! plugin/**/*.{vim,lua}
trojan-horse
While reading the "vimrc" or the "exrc" file in the current directory, some
commands can be disabled for security reasons by setting the 'secure' option.
This is always done when executing the command from a tags file. Otherwise,
it would be possible that you accidentally use a vimrc or tags file that
somebody else created and contains nasty commands. The disabled commands are
the ones that start a shell, the ones that write to a file, and ":autocmd".
The ":map" commands are echoed, so you can see which keys are being mapped.
If you want Vim to execute all commands in a local vimrc file, you
can reset the 'secure' option in the EXINIT or VIMINIT environment variable or
in the global exrc or vimrc file. This is not possible in vimrc or
exrc in the current directory, for obvious reasons.
On Unix systems, this only happens if you are not the owner of the
vimrc file. Warning: If you unpack an archive that contains a vimrc or exrc
file, it will be owned by you. You won't have the security protection. Check
the vimrc file before you start Vim in that directory, or reset the 'exrc'
option. Some Unix systems allow a user to do "chown" on a file. This makes
it possible for another user to create a nasty vimrc and make you the owner.
Be careful!
When using tag search commands, executing the search command (the last
part of the line in the tags file) is always done in secure mode. This works
just like executing a command from a vimrc in the current directory.slow-start
If Vim takes a long time to start up, use the --startuptime argument to find
out what happens.bisect
The extreme flexibility of editors like Vim and Emacs means that any plugin or
setting can affect the entire editor in ways that are not initially obvious.:intro
When Vim starts without a file name, an introductory message is displayed. It
is removed as soon as the display is redrawn. To see the message again, use
the ":intro" command. To avoid the intro message on startup, add the "I" flag
to 'shortmess'.$VIM
The environment variable "$VIM" is used to locate various user files for Nvim,
such as the user config. This depends on the system, see
startup.nvim
executable.
4. Compile-time defined installation directory (see output of ":version").$VIMRUNTIME
The environment variable "$VIMRUNTIME" is used to locate various support
files, such as the documentation and syntax-highlighting files. For example,
the main help file is normally "$VIMRUNTIME/doc/help.txt".{version}
is the
Vim version number without '-' or '.'. For example: "$VIM/vim82".
3. Directory path "$VIM/runtime", if it exists.
4. Value of $VIM environment variable. This is for backwards compatibility
with older Vim versions.
5. If "../share/nvim/runtime" exists relative to v:progpath, it is used.
6. Path derived from the 'helpfile' option (if it doesn't contain '$') with
"doc/help.txt" removed from the end.VIMRUNTIME="$(nvim --clean --headless --cmd 'echo $VIMRUNTIME|q')"
CTRL-Z
v_CTRL-Z
CTRL-Z Suspend Nvim, like ":stop".
Works in Normal and in Visual mode. In Insert and
Command-line mode, the CTRL-Z
is inserted as a normal
character. In Visual mode Nvim goes back to Normal
mode.:sus
:suspend
:st
:stop
:st[op][!] Suspend Nvim using OS "job control"; it will continue
if you make it the foreground job again. Triggers
VimSuspend before suspending and VimResume when
resumed.
If "!" is not given and 'autowrite' is set, every
buffer with changes and a file name is written out.
If "!" is given or 'autowrite' is not set, changed
buffers are not written, don't forget to bring Nvim
back to the foreground later!:quit
. Only when there are no changes.
:quit!
. Also when there are changes.
:qall
. Only when there are no changes.
:qall!
. Also when there are changes.
:cquit
. Also when there are changes.
:cquit
or when there was an error message Vim exits with exit
code 1. Errors can be avoided by using :silent!
or with :catch
.:mk
:mkexrc
:mk[exrc] [file] Write current key mappings and changed options to
[file] (default ".exrc" in the current directory),
unless it already exists.:mkv
:mkvi
:mkvimrc
:mkv[imrc][!] [file] Like ":mkexrc", but the default is ".nvimrc" in the
current directory. The ":version" command is also
written to the file.vimrc-option-example
If you only want to add a single option setting to your vimrc, you can use
these steps:
1. Edit your vimrc file with Vim.
2. Play with the option until it's right. E.g., try out different values for
'guifont'.
3. Append a line to set the value of the option, using the expression register
'=' to enter the value. E.g., for the 'guifont' option:o:set guifont=<C-R>=&guifont<CR><Esc>
<C-R>
is a CTRL-R
, <CR>
is a return, <Esc>
is the escape key]
You need to escape special characters, esp. spaces.View
view-file
A View is a collection of settings that apply to one window. You can save a
View and when you restore it later, the text is displayed in the same way.
The options and mappings in this window will also be restored, so that you can
continue editing like when the View was saved.Session
session-file
A Session keeps the Views for all windows, plus the global settings. You can
save a Session and when you restore it later the window layout looks the same.
You can use a Session to quickly switch between different projects,
automatically loading the files you were last working on in that project.vim -S Session.vim
:mks
:mksession
:mks[ession][!] [file] Write a Vim script that restores the current editing
session.
When [!] is included, an existing file is overwritten.
When [file] is omitted, "Session.vim" is used.*x.vim
files to
specify additional settings and actions associated with a given Session,
such as creating menu items in the GUI version.:nmap <F2> :wa<Bar>exe "mksession! " .. v:this_session<CR>:so ~/sessions/This saves the current Session, and starts off the command to load another.
SessionLoad-variable
While the session file is loading, the SessionLoad global variable is set to
1. Plugins can use this to postpone some work until the SessionLoadPost event
is triggered.:mkvie
:mkview
:mkvie[w][!] [file] Write a Vim script that restores the contents of the
current window.
When [!] is included, an existing file is overwritten.
When [file] is omitted or is a number from 1 to 9, a
name is generated and 'viewdir' prepended. When the
last path part of 'viewdir' does not exist, this
directory is created. E.g., when 'viewdir' is
"$VIM/vimfiles/view" then "view" is created in
"$VIM/vimfiles".
An existing file is always overwritten then. Use
:loadview to load this view again.
When [file] is the name of a file ('viewdir' is not
used), a command to edit the file is added to the
generated file.:lo
:loadview
:lo[adview] [nr] Load the view for the current file. When [nr] is
omitted, the view stored with ":mkview" is loaded.
When [nr] is specified, the view stored with ":mkview
[nr]" is loaded.*.c
files:au BufWinLeave *.c mkview au BufWinEnter *.c silent! loadview
shada-read
When Vim is started and the 'shada' option is non-empty, the contents of
the ShaDa file are read and the info can be used in the appropriate places.
The v:oldfiles variable is filled. The marks are not read in at startup
(but file marks are). See initialization for how to set the 'shada'
option upon startup.shada-write
When Vim exits and 'shada' is non-empty, the info is stored in the ShaDa file
(it's actually merged with the existing one, if one exists shada-merging).
The 'shada' option is a string containing information about what info should
be stored, and contains limits on how much should be stored (see 'shada').shada-file-marks
Uppercase marks ('A to 'Z) are stored when writing the ShaDa file. The
numbered marks ('0 to '9) are a bit special. When the ShaDa file is written
(when exiting or with the :wshada command), '0 is set to the current cursor
position and file. The old '0 is moved to '1, '1 to '2, etc. This
resembles what happens with the "1 to "9 delete registers. If the current
cursor position is already present in '0 to '9, it is moved to '0, to avoid
having the same position twice. The result is that with "'0", you can jump
back to the file and line where you exited Vim. To do that right away, try
using this command:vim -c "normal '0"In a C shell descendant, you could make an alias for it:
alias lvim vim -c '"'normal "'"0'"'For a Bash-like shell:
alias lvim='vim -c "normal '\''0"'Use the "r" flag in 'shada' to specify for which files no marks should be remembered.
:rshada! ~/.my.shadacan be used to load this information. You could even have different ShaDa files for different types of files (e.g., C code) and load them based on the file name, using the ":autocmd" command (see :autocmd). More information on ShaDa file format is contained in shada-format section.
E136
E929
shada-error-handling
Some errors make Nvim leave temporary file named {basename}.tmp.X
(X is
any free letter from a
to z
) while normally it will create this file,
write to it and then rename {basename}.tmp.X
to {basename}
. Such errors
include::rsh
:rshada
E886
:rsh[ada][!] [file] Read from ShaDa file [file] (default: see above).
If [!] is given, then any information that is
already set (registers, marks, v:oldfiles, etc.)
will be overwritten.:wsh
:wshada
E137
:wsh[ada][!] [file] Write to ShaDa file [file] (default: see above).
The information in the file is first read in to make
a merge between old and new info. When [!] is used,
the old information is not read first, only the
internal info is written (also disables safety checks
described in shada-error-handling). If 'shada' is
empty, marks for up to 100 files will be written.
When you get error "E929: All .tmp.X files exist,
cannot write ShaDa file!", check that no old temp
files were left behind (e.g.
~/.local/state/nvim/shada/main.shada.tmp*).:o
:ol
:oldfiles
:o[ldfiles] List the files that have marks stored in the ShaDa
file. This list is read on startup and only changes
afterwards with :rshada!
. Also see v:oldfiles.
The number can be used with c_#<.
The output can be filtered with :filter, e.g.:filter /\.vim/ oldfiles
*
It is allowed to have any number of
additional keys with any data.
2 (SearchPattern) Map containing data describing last used search or
substitute pattern. Normally ShaDa file contains two
such entries: one with "ss" key set to true (describes
substitute pattern, see :substitute), and one set to
false (describes search pattern, see
search-commands). "su" key should be true on one of
the entries. If key value is equal to default then it
is normally not present. Keys:
*
any none Other keys are allowed for
compatibility reasons, see
shada-compatibility.
3 (SubString) Array containing last :substitute replacement string.
Contains single entry: binary, replacement string used.
More entries are allowed for compatibility reasons, see
shada-compatibility.
4 (HistoryEntry) Array containing one entry from history. Should have
two or three entries. First one is history type
(unsigned integer), second is history line (binary),
third is the separator character (unsigned integer,
must be in interval [0, 255]). Third item is only
valid for search history. Possible history types are
listed in hist-names, here are the corresponding
numbers: 0 - cmd, 1 - search, 2 - expr, 3 - input,
4 - debug.
5 (Register) Map describing one register (registers). If key
value is equal to default then it is normally not
present. Keys:
*
any none Other keys are allowed for
compatibility reasons, see
shada-compatibility.
9 (BufferList) Array containing maps. Each map in the array
represents one buffer. Possible keys:
*
any none Other keys are allowed for
compatibility reasons, see
shada-compatibility.
*
(Unknown) Any other entry type is allowed for compatibility
reasons, see shada-compatibility.E575
E576
Errors in ShaDa file may have two types:
1. E575 for “logical” errors.
2. E576 for “critical” errors.
When writing, critical errors trigger behaviour described in
shada-error-handling.
When reading, critical errors cause the rest of the file to be skipped.
Critical errors include:
shada-critical-contents-errors
base-directories
xdg
The "base" (root) directories conform to the XDG Base Directory Specification.
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
The $XDG_CONFIG_HOME, $XDG_DATA_HOME, $XDG_RUNTIME_DIR, $XDG_STATE_HOME,
$XDG_CACHE_HOME, $XDG_CONFIG_DIRS and $XDG_DATA_DIRS environment variables
are used if defined, else default values (listed below) are used.$XDG_CONFIG_HOME
Nvim: stdpath("config")
Unix: ~/.config ~/.config/nvim
Windows: ~/AppData/Local ~/AppData/Local/nvim$XDG_DATA_HOME
Nvim: stdpath("data")
Unix: ~/.local/share ~/.local/share/nvim
Windows: ~/AppData/Local ~/AppData/Local/nvim-data$XDG_RUNTIME_DIR
Nvim: stdpath("run")
Unix: /tmp/nvim.user/xxx /tmp/nvim.user/xxx
Windows: $TMP/nvim.user/xxx $TMP/nvim.user/xxx$XDG_STATE_HOME
Nvim: stdpath("state")
Unix: ~/.local/state ~/.local/state/nvim
Windows: ~/AppData/Local ~/AppData/Local/nvim-data$XDG_CACHE_HOME
Nvim: stdpath("cache")
Unix: ~/.cache ~/.cache/nvim
Windows: ~/AppData/Local/Temp ~/AppData/Local/Temp/nvim-data$NVIM_LOG_FILE
Nvim: stdpath("log")/log
Unix: ~/.local/state/nvim ~/.local/state/nvim/log
Windows: ~/AppData/Local/nvim-data ~/AppData/Local/nvim-data/log$XDG_CONFIG_DIRS
Nvim: stdpath("config_dirs")
Unix: /etc/xdg/ /etc/xdg/nvim
Windows: Not applicable Not applicable$XDG_DATA_DIRS
Nvim: stdpath("data_dirs")
Unix: /usr/local/share /usr/local/share/nvim
/usr/share /usr/share/nvim
Windows: Not applicable Not applicable$NVIM_APPNAME
environment variable. This variable controls the sub-directory that Nvim will
read from (and auto-create) in each of the base directories. For example,
setting $NVIM_APPNAME
to "foo" before starting will cause Nvim to look for
configuration files in $XDG_CONFIG_HOME/foo
instead of
$XDG_CONFIG_HOME/nvim
. $NVIM_APPNAME
must be a name, such as "foo", or a
relative path, such as "foo/bar".systemd-run --user -qt -p PrivateUsers=yes -p BindPaths=/home/user/profile_xy:/home/user/.config/nvim nvimNote: Throughout the help pages, wherever
$XDG_CONFIG_…/nvim
is mentioned it
is understood to mean $XDG_CONFIG_…/$NVIM_APPNAME
.