Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
current-file
As long as you don't write the buffer, the original file remains unchanged.
If you start editing a file (read a file into the buffer), the file name is
remembered as the "current file name". This is also known as the name of the
current buffer. It can be used with "%" on the command line :_%.alternate-file
If there already was a current file name, then that one becomes the alternate
file name. It can be used with "#" on the command line :_# and you can use
the CTRL-^ command to toggle between the current and the alternate file.
However, the alternate file name is not changed when :keepalt is used.
An alternate file name is remembered for each window.:keepalt
:keepa
:keepalt {cmd}
Execute {cmd}
while keeping the current alternate file
name. Note that commands invoked indirectly (e.g.,
with a function) may still set the alternate file
name.CTRL-^
.CTRL-G
:f
:fi
:file
:f[ile] Prints the current file name (as typed, unless ":cd"
was used), the cursor position (unless the 'ruler'
option is set), and the file status (readonly,
modified, read errors, new file). See the 'shortmess'
option about how to make this message shorter.{count}
CTRL-G
Like CTRL-G
, but prints the current file name with
full path. If the count is higher than 1 the current
buffer number is also given.g_CTRL-G
word-count
byte-count
g CTRL-G
Prints the current position of the cursor in five
ways: Column, Line, Word, Character and Byte. If the
number of Characters and Bytes is the same then the
Character position is omitted.<Tab>
or special
character), or characters using more than one byte per
column (characters above 0x7F when 'encoding' is
utf-8), both the byte column and the screen column are
shown, separated by a dash.v_g_CTRL-G
{Visual}
g CTRL-G
Similar to "g CTRL-G
", but Word, Character, Line, and
Byte counts for the visually selected region are
displayed.
In Blockwise mode, Column count is also shown. (For
{Visual}
see Visual-mode.):file_f
:f[ile][!] {name}
Sets the current file name to {name}
. The optional !
avoids truncating the message, as with :file.
If the buffer did have a name, that name becomes the
alternate-file name. An unlisted buffer is created
to hold the old name.
:0file
:0f[ile][!] Remove the name of the current buffer. The optional !
avoids truncating the message, as with :file.home-replace
If the environment variable $HOME is set, and the file name starts with that
string, it is often displayed with HOME replaced with "~". This was done to
keep file names short. When reading or writing files the full name is still
used, the "~" is only used when displaying file names. When replacing the
file name would result in just "~", "~/" is used instead (to avoid confusion
between options set to $HOME with 'backupext' set to "~").vim testfile [change the buffer with editor commands] :w newfile :qThis will create a file "newfile", that is a modified copy of "testfile". The file "testfile" will remain unchanged. Anyway, if the 'backup' option is set, Vim renames or copies the original file before it will be overwritten. You can use this file if you discover that you need the original file. See also the 'patchmode' option. The name of the backup file is normally the same as the original file with 'backupext' appended. The default "~" is a bit strange to avoid accidentally overwriting existing files. If you prefer ".bak" change the 'backupext' option. The backup file can be placed in another directory by setting 'backupdir'.
not-edited
Because the file name was set without really starting to edit that file, you
are protected from overwriting that file. This is done by setting the
"notedited" flag. You can see if this flag is set with the CTRL-G
or ":file"
command. It will include "[Not edited]" when the "notedited" flag is set.
When writing the buffer to the current file name (with ":w!"), the "notedited"
flag is reset.abandon
Vim remembers whether you have changed the buffer. You are protected from
losing the changes you made. If you try to quit without writing, or want to
start editing another file, Vim will refuse this. In order to overrule this
protection, add a '!' to the command. The changes will then be lost. For
example: ":q" will not work if the buffer was changed, but ":q!" will. To see
whether the buffer was changed use the "CTRL-G" command. The message includes
the string "[Modified]" if the buffer has been changed, or "+" if the 'm' flag
is in 'shortmess'.:e
:edit
reload
:e[dit][!] [++opt] [+cmd]
Edit the current file. This is useful to re-edit the
current file, when it has been changed outside of Vim.
:edit!
discard
If [!] is given, unsaved changes in the current buffer
are discarded. Without [!] the command fails if there
are unsaved changes, unless 'autowriteall' is set and
the file can be written.
Also see ++opt and +cmd.:edit_f
:e[dit][!] [++opt] [+cmd] {file}
Edit {file}
.
:edit!_f
If [!] is given, unsaved changes in the current buffer
are discarded. Without [!] the command fails if there
are unsaved changes, unless 'hidden' is set or
'autowriteall' is set and the file can be written.
Also see ++opt and +cmd.:edit_#
:e#
:e[dit] [++opt] [+cmd] #[count]
Edit the [count]th buffer (as shown by :files).
This command does the same as [count] CTRL-^
. But ":e
#" doesn't work if the alternate buffer doesn't have a
file name, while CTRL-^
still works then.
Also see ++opt and +cmd.:ene
:enew
:ene[w] Edit a new, unnamed buffer. This fails when changes
have been made to the current buffer, unless 'hidden'
is set or 'autowriteall' is set and the file can be
written.
If 'fileformats' is not empty, the first format given
will be used for the new buffer. If 'fileformats' is
empty, the 'fileformat' of the current buffer is used.:ene!
:enew!
:ene[w]! Edit a new, unnamed buffer. Discard any changes to
the current buffer.
Set 'fileformat' like :enew.{file}
Just like ":find", but use the {count}
match in
'path'. Thus ":2find file" will find the second
"file" found in 'path'. When there are fewer matches
for the file in 'path' than asked for, you get an
error message.:vi
:visual
:vi[sual][!] [++opt] [+cmd] [file]
When used in Ex mode: Leave Ex-mode, go back to
Normal mode. Otherwise same as :edit.:vie
:view
:vie[w][!] [++opt] [+cmd] file
When used in Ex mode: Leave Ex-mode, go back to
Normal mode. Otherwise same as :edit, but set
'readonly' option for this buffer.CTRL-^
CTRL-6
CTRL-^
Edit the alternate file. Mostly the alternate file is
the previously edited file. This is a quick way to
toggle between two files. It is equivalent to ":e #",
except that it also works when there is no file name.CTRL-^
.
But on some non-US keyboards CTRL-^
is produced in
another way.{count}
CTRL-^
Edit [count]th file in the buffer list (equivalent to
":e #[count]"). This is a quick way to switch between
files.
See CTRL-^ above for further details.gf
E446
E447
[count]gf Edit the file whose name is under or after the cursor.
Mnemonic: "goto file".
Uses the 'isfname' option to find out which characters
are supposed to be in a file name. Trailing
punctuation characters ".,:;!" are ignored. Escaped
spaces "\ " are reduced to a single space.
Uses the 'path' option as a list of directory names to
look for the file. See the 'path' option for details
about relative directories and wildcards.
Uses the 'suffixesadd' option to check for file names
with a suffix added.
If the file can't be found, 'includeexpr' is used to
modify the name and another attempt is done.
If a [count] is given, the count'th file that is found
in the 'path' is edited.
This command fails if Vim refuses to abandon the
current file.
If you want to edit the file in a new window use
CTRL-W_CTRL-F.
If you do want to edit a new file, use::e <cfile>
:map gf :e <cfile><CR>
v_gf
{Visual}
[count]gf Same as "gf", but the highlighted text is used as the
name of the file to edit. 'isfname' is ignored.
Leading blanks are skipped, otherwise all blanks and
special characters are included in the file name.
(For {Visual}
see Visual-mode.)gF
[count]gF Same as "gf", except if a number follows the file
name, then the cursor is positioned on that line in
the file.
The file name and the number must be separated by a
non-filename (see 'isfname') and non-numeric
character. " line " is also recognized, like it is
used in the output of :verbose command UserCmd
White space between the filename, the separator and
the number are ignored.
Examples:
v_gF
{Visual}
[count]gF Same as "v_gf".:filename
{file}
Besides the things mentioned here, more special items for where a filename is
expected are mentioned at cmdline-special.wildcard
wildcards
Wildcards in {file}
are expanded, but as with file completion, 'wildignore'
and 'suffixes' apply. Which wildcards are supported depends on the system.
These are the common ones:
?
matches one character
*
matches anything, including nothing
**
matches anything, including nothing, recurses into directories
[abc] match 'a', 'b' or 'c'starstar-wildcard
Expanding "**" is possible on Unix, Win32, macOS and a few other systems (but
it may depend on your 'shell' setting on Unix and macOS. It's known to work
correctly for zsh; for bash this requires at least bash version >= 4.X).
This allows searching a directory tree. This goes up to 100 directories deep.
Note there are some commands where this works slightly differently, see
file-searching.
Example::n **/*.txtFinds files:
:n /usr/inc**/types.hFinds files:
backtick-expansion
`-expansion
On Unix and a few other systems you can also use backticks for the file name
argument, for example::next `find . -name ver\\*.c -print` :view `ls -t *.patch \| head -n1`Vim will run the command in backticks using the 'shell' and use the standard output as argument for the given Vim command (error messages from the shell command will be discarded). To see what shell command Vim is running, set the 'verbose' option to 4. When the shell command returns a non-zero exit code, an error message will be displayed and the Vim command will be aborted. To avoid this make the shell always return zero like so:
:next `find . -name ver\\*.c -print \|\| true`The backslashes before the star are required to prevent the shell from expanding "ver*.c" prior to execution of the find program. The backslash before the shell pipe symbol "|" prevents Vim from parsing it as command termination. This also works for most other systems, with the restriction that the backticks must be around the whole item. It is not possible to have text directly before the first or just after the last backtick.
`=
You can have the backticks expanded as a Vim expression, instead of as an
external command, by putting an equal sign right after the first backtick,
e.g.::e `=tempname()`The expression can contain just about anything, thus this can also be used to avoid the special meaning of '"', "|", '%' and '#'. However, 'wildignore' does apply like to other wildcards.
:e `=$HOME .. '/.vimrc'`This uses $HOME inside a string and it will be used literally, most likely not what you intended:
:e `='$HOME' .. '/.vimrc'`If the expression returns a string then names are to be separated with line breaks. When the result is a List then each item is used as a name. Line breaks also separate names. Note that such expressions are only supported in places where a filename is expected as an argument to an Ex-command.
++opt
[++opt]
The [++opt] argument can be used to set some options for one command, and to
specify the behavior for bad characters. The form is:++{optname}Or:
++{optname}={value}Where
{optname}
is one of: ++ff
++enc
++bin
++nobin
++edit
ff or fileformat overrides 'fileformat'
enc or encoding overrides 'fileencoding'
bin or binary sets 'binary'
nobin or nobinary resets 'binary'
bad specifies behavior for bad characters
edit for :read: keeps options as if editing a file
p for :write: creates the file's parent directory{value}
cannot contain whitespace. It can be any valid value for the options.
Examples::e ++ff=unixThis edits the same file again with 'fileformat' set to "unix".
:w ++enc=latin1 newfileThis writes the current buffer to "newfile" in latin1 format.
++p
The "++p" flag creates the parent directory of the file if it does not exist.
For example if you edit "foo/bar/file.txt", the ":write ++p" command creates
"foo/bar/" if necessary before writing the file.:edit foo/bar/file.txt :write ++pIf you want :write (without "++p") to always create missing parent directories, add this autocmd to your config:
" Auto-create parent directories (except for URIs "://"). au BufWritePre,FileWritePre * if @% !~# '\(://\)' | call mkdir(expand('<afile>:p:h'), 'p') | endif
++bad
The argument of "++bad=" specifies what happens with characters that can't be
converted and illegal bytes. It can be one of three things:
++bad=X A single-byte character that replaces each bad character.
++bad=keep Keep bad characters without conversion. Note that this may
result in illegal bytes in your text!
++bad=drop Remove the bad characters.+cmd
[+cmd]
The [+cmd] argument can be used to position the cursor in the newly opened
file, or execute any other command:
+ Start at the last line.
+{num} Start at line {num}
.
+/{pat} Start at first line containing {pat}
.
+{command} Execute {command}
after opening the new file.
{command}
is any Ex command.
To include a white space in the {pat}
or {command}
, precede it with a
backslash. Double the number of backslashes.:edit +/The\ book file :edit +/dir\ dirname\\ file :edit +set\ dir=c:\\\\temp fileNote that in the last example the number of backslashes is halved twice: Once for the "+cmd" argument and once for the ":set" command.
file-formats
The 'fileformat' option sets the <EOL>
style for a file:
<CR>
<NL>
or <NL>
DOS format DOS-format
"unix" <NL>
Unix format Unix-format
"mac" <CR>
Mac format Mac-format
<EOL>
.
In DOS format (default for Windows), <CR>
<NL>
and <NL>
are both interpreted as
the <EOL>
. Note that when writing the file in DOS format, <CR>
characters will
be added for each single <NL>
. Also see file-read.<EOL>
. For DOS
format <CR>
<NL>
is used. Also see DOS-format-write.<CR>
<NL>
pairs by <NL>
(assuming 'fileformats' includes "dos")::e file :set fileformat=unix :wIf you read a file in Unix format and write with DOS format, all
<NL>
characters will be replaced with <CR>
<NL>
(assuming 'fileformats' includes
"unix")::e file :set fileformat=dos :wIf you start editing a new file and the 'fileformats' option is not empty (which is the default), Vim will try to detect whether the lines in the file are separated by the specified formats. When set to "unix,dos", Vim will check for lines with a single
<NL>
(as used on Unix) or by a <CR>
<NL>
pair
(MS-Windows). Only when ALL lines end in <CR>
<NL>
, 'fileformat' is
set to "dos", otherwise it is set to "unix". When 'fileformats' includes
"mac", and no <NL>
characters are found in the file, 'fileformat' is set to
"mac".<CR>
<NL>
, "[CR missing]" will be included in
the file message.
If the 'fileformats' option is empty and Mac format is used, but while reading
a file a <NL>
was found, "[NL missing]" will be included in the file message.<NL>
characters are unexpectedly replaced with <CR>
<NL>
.<EOL>
style: Unix, DOS, Mac
'endofline' whether the last line ends with a <EOL>
'endoffile' whether the file ends with a CTRL-Z
'fixendofline' whether to fix eol and eofCTRL-Z
isn't there (an
exception is when 'binary' is set, it works differently then).setl ff=unix fixeolYou should probably do this on any Unix-like system. Also modern MS-Windows systems tend to work well with this. It is recommended to always use this format for Vim scripts.
CTRL-Z
, but keeping the <CR>
<NL>
style <EOL>
:setl ff=dos fixeolThis is useful for many MS-Windows programs, they regularly expect the
<CR>
<NL>
line endings.<EOL>
and add a final CTRL-Z
(e.g. for an old
system like CP/M):setl ff=dos nofixeol noeol eofIf you want to preserve the fileformat exactly as-is, including any final
<EOL>
and final CTRL-Z
:setl nofixeol
{arglist}
:args_f
Define {arglist}
as the new argument list and edit
the first one. This fails when changes have been made
and Vim does not want to abandon the current buffer.
Also see ++opt and +cmd.{arglist}
:args_f!
Define {arglist}
as the new argument list and edit
the first one. Discard any changes to the current
buffer.
Also see ++opt and +cmd.{name}
.. :arge
:argedit
Add {name}
s to the argument list and edit it.
There is no check for duplicates, it is possible to
add a file to the argument list twice :argded.
This is like using :argadd and then :edit (with
the small exception that :edit does not change the
argument list, so the argument list pointer isn't
changed).
Spaces in filenames have to be escaped with "\".
[count] is used like with :argadd.
If the current file cannot be abandoned {name}
s will
still be added to the argument list, but won't be
edited. No check for duplicates is done.
Also see ++opt and +cmd.{name}
.. :arga
:argadd
E479
:[count]arga[dd] E1156
Add the {name}
s to the argument list. When {name}
is
omitted add the current buffer name to the argument
list.
If [count] is omitted, the {name}
s are added just
after the current entry in the argument list.
Otherwise they are added after the [count]'th file.
If the argument list is "a b c", and "b" is the
current argument, then these commands result in:
:argadd *.txt | argdedupe
:args ## x
:argded
:argdedupe
Remove duplicate filenames from the argument list.
If your current file is a duplicate, your current file
will change to the original file index.{pattern}
.. :argd
:argdelete
E480
E610
Delete files from the argument list that match the
{pattern}
s. {pattern}
is used like a file pattern,
see file-pattern. "%" can be used to delete the
current entry.
This command keeps the currently edited file, also
when it's deleted from the argument list.
Example::argdel *.obj:[range]argd[elete] Delete the [range] files from the argument list. Example:
:10,$argdel
:$argd
:argd :.argd
:%argd
:argu
:argument
:[count]argu[ment] [count] [++opt] [+cmd]
Edit file [count] in the argument list. When [count]
is omitted the current entry is used. This fails
when changes have been made and Vim does not want to
abandon the current buffer.
Also see ++opt and +cmd.:n
:ne
:next
E165
E163
Edit [count] next file. This fails when changes have
been made and Vim does not want to abandon the
current buffer. Also see ++opt and +cmd.{arglist}
Same as :args_f!.:Next
:N
E164
Edit [count] previous file in argument list. This
fails when changes have been made and Vim does not
want to abandon the current buffer.
Also see ++opt and +cmd.:rew
:rewind
:rew[ind] [++opt] [+cmd]
Start editing the first file in the argument list.
This fails when changes have been made and Vim does
not want to abandon the current buffer.
Also see ++opt and +cmd.:la
:last
:la[st] [++opt] [+cmd]
Start editing the last file in the argument list.
This fails when changes have been made and Vim does
not want to abandon the current buffer.
Also see ++opt and +cmd.:wn
:wnext
:[count]wn[ext] [++opt]
Write current file and start editing the [count]
next file. Also see ++opt and +cmd.{file}
Write current file to {file}
and start editing the
[count] next file, unless {file}
already exists and
the 'writeany' option is off. Also see ++opt and
+cmd.{file}
Write current file to {file}
and start editing the
[count] next file. Also see ++opt and +cmd.:wN
:wNext
:[count]wp[revious][!] [++opt] [file] :wp
:wprevious
Same as :wnext, but go to previous file instead of
next.{arglist}
The wildcards in the argument list are expanded and the file names are sorted.
Thus you can use the command vim *.c
to edit all the C files. From within
Vim the command :n *.c
does the same.:next foo\ barOn Unix and a few other systems you can also use backticks, for example:
:next `find . -name \\*.c -print`The backslashes before the star are required to prevent "*.c" to be expanded by the shell before executing the find program.
arglist-position
When there is an argument list you can see which file you are editing in the
title of the window (if there is one and 'title' is on) and with the file
message you get with the "CTRL-G" command. You will see something like
(4 of 11)
If you are not really editing the file at the current position in the argument
list it will be
((4) of 11)
This means that you are position 4 in the argument list, but not editing the
fourth file in the argument list. This happens when you do ":e file".:arglocal
:argl[ocal] Make a local copy of the global argument list.
Doesn't start editing another file.{arglist}
Define a new argument list, which is local to the
current window. Works like :args_f otherwise.:argglobal
:argg[lobal] Use the global argument list for the current window.
Doesn't start editing another file.{arglist}
Use the global argument list for the current window.
Define a new global argument list like :args_f.
All windows using the global argument list will see
this new list.:argdo
:[range]argdo[!] {cmd}
Execute {cmd}
for each file in the argument list or,
if [range] is specified, only for arguments in that
range. It works like doing this::rewind :{cmd} :next :{cmd} etc.
{cmd}
can contain '|' to concatenate several commands.
{cmd}
must not change the argument list.
Note: While this command is executing, the Syntax
autocommand event is disabled by adding it to
'eventignore'. This considerably speeds up editing
each file.
Also see :windo, :tabdo, :bufdo, :cdo, :ldo,
:cfdo and :lfdo.:args *.c :argdo set ff=unix | updateThis sets the 'fileformat' option to "unix" and writes the file if it is now changed. This is done for all
*.c
files.:args *.[ch] :argdo %s/\<my_foo\>/My_Foo/ge | updateThis changes the word "my_foo" to "My_Foo" in all "*.c" and "*.h" files. The "e" flag is used for the ":substitute" command to avoid an error for files where "my_foo" isn't used. ":update" writes the file only if changes were made.
:w
:write
E502
E503
E504
E505
E512
E514
E667
E949
:w[rite] [++opt] Write the whole buffer to the current file. This is
the normal way to save changes to a file. Fails when
'readonly' is set or when there is another reason why
the file can't be written, such as when the parent
directory doesn't exist (use ++p to avoid that).
For ++opt see ++opt, but only ++p, ++bin, ++nobin,
++ff and ++enc are effective.:w_f
:write_f
:[range]w[rite] [++opt] {file}
Write the specified lines to {file}
, unless it
already exists and the 'writeany' option is off.:w!
:[range]w[rite]! [++opt] {file}
Write the specified lines to {file}
. Overwrite an
existing file.:w_a
:write_a
E494
:[range]w[rite][!] [++opt] >Append the specified lines to the current file.:[range]w[rite][!] [++opt] >>
{file}
Append the specified lines to {file}
. '!' forces the
write even if file does not exist.:w_c
:write_c
:[range]w[rite] [++opt] !{cmd}
Execute {cmd}
with [range] lines as standard input
(note the space in front of the '!'). {cmd}
is
executed like with ":!{cmd}", any '!' is replaced with
the previous command :!.:sav
:saveas
:sav[eas][!] [++opt] {file}
Save the current buffer under the name {file}
and set
the filename of the current buffer to {file}
. The
previous name is used for the alternate file name.
The [!] is needed to overwrite an existing file.
When 'filetype' is empty filetype detection is done
with the new name, before the file is written.
When the write was successful 'readonly' is reset.:up
:update
:[range]up[date][!] [++opt] [>>] [file]
Like ":write", but only write when the buffer has been
modified.:wa
:wall
:wa[ll] Write all changed buffers. Buffers without a file
name cause an error message. Buffers which are
readonly are not written.backup
E207
E506
E507
E508
E509
E510
If you write to an existing file (but do not append) while the 'backup',
'writebackup' or 'patchmode' option is on, a backup of the original file is
made. The file is either copied or renamed (see 'backupcopy'). After the
file has been successfully written and when the 'writebackup' option is on and
the 'backup' option is off, the backup file is deleted. When the 'patchmode'
option is on the backup file may be renamed.backup-table
write-permissions
When writing a new file the permissions are read-write. For unix the mask is
0o666 with additionally umask applied. When writing a file that was read Vim
will preserve the permissions, but clear the s-bit.write-readonly
When the 'cpoptions' option contains 'W', Vim will refuse to overwrite a
readonly file. When 'W' is not present, ":w!" will overwrite a readonly file,
if the system allows it (the directory must be writable).write-fail
If the writing of the new file fails, you have to be careful not to lose
your changes AND the original file. If there is no backup file and writing
the new file failed, you have already lost the original file! DON'T EXIT VIM
UNTIL YOU WRITE OUT THE FILE! If a backup was made, it is put back in place
of the original file (if possible). If you exit Vim, and lose the changes
you made, the original file will mostly still be there. If putting back the
original file fails, there will be an error message telling you that you
lost the original file.DOS-format-write
If the 'fileformat' is "dos", <CR>
<NL>
is used for <EOL>
. This is default
for Windows. On other systems the message "[dos]" is shown to
remind you that an unusual <EOL>
was used.
Unix-format-write
If the 'fileformat' is "unix", <NL>
is used for <EOL>
. On Windows
the message "[unix]" is shown.
Mac-format-write
If the 'fileformat' is "mac", <CR>
is used for <EOL>
. The
message "[mac]" is shown.ACL
ACL stands for Access Control List. It is an advanced way to control access
rights for a file. It is used on new MS-Windows and Unix systems, but only
when the filesystem supports it.
Vim attempts to preserve the ACL info when writing a file. The backup file
will get the ACL info of the original file.
The ACL info is also used to check if a file is read-only (when opening the
file).xattr
E1506
E1508
E1509
xattr stands for Extended Attributes. It is an advanced way to save metadata
alongside the file in the filesystem. It depends on the actual filesystem
being used and Vim supports it only on a Linux system.
Vim attempts to preserve the extended attribute info when writing a file.
The backup file will get the extended attribute of the original file.read-only-share
When MS-Windows shares a drive on the network it can be marked as read-only.
This means that even if the file read-only attribute is absent, and the ACL
settings on NT network shared drives allow writing to the file, you can still
not write to the file. Vim on Win32 platforms will detect read-only network
drives and will mark the file as read-only. You will not be able to override
it with :write.write-device
When the file name is actually a device name, Vim will not make a backup (that
would be impossible). You need to use "!", since the device already exists.
Example for Unix::w! /dev/lpt0and MS-Windows:
:w! lpt0For Unix a device is detected when the name doesn't refer to a normal file or a directory. A fifo or named pipe also looks like a device to Vim. For MS-Windows the device is detected by its name: CON CLOCK$ NUL PRN COMn n=1,2,3... etc LPTn n=1,2,3... etc The names can be in upper- or lowercase.
:q
:quit
:q[uit] Quit the current window. Quit Vim if this is the last
edit-window. This fails when changes have been made
and Vim refuses to abandon the current buffer, and
when the last file in the argument list has not been
edited.
If there are other tab pages and quitting the last
window in the current tab page the current tab page is
closed tab-page.
Triggers the QuitPre autocommand event.
See CTRL-W_q for quitting another window.:wq
:wq [++opt] Write the current file and close the window. If this
was the last edit-window Vim quits.
Writing fails when the file is read-only or the buffer
does not have a name. Quitting fails when the last
file in the argument list has not been edited.{file}
Write to {file}
and close the window. If this was the
last edit-window Vim quits. Quitting fails when the
last file in the argument list has not been edited.{file}
Write to {file}
and close the current window. Quit
Vim if this was the last edit-window.:x
:xit
:[range]x[it][!] [++opt] [file]
Like ":wq", but write only when changes have been
made.
When 'hidden' is set and there are more windows, the
current buffer becomes hidden, after writing the file.ZZ
ZZ Write current file, if modified, and close the current
window (same as ":x").
If there are several windows for the current file,
only the current window is closed.ZQ
ZQ Quit without checking for changes (same as ":q!").:qa
:qall
:qa[ll] Exit Vim, unless there are some buffers which have been
changed. (Use ":bmod" to go to the next modified buffer).
When 'autowriteall' is set all changed buffers will be
written, like :wqall.:wqa
:wqall
:xa
:xall
:xa[ll] Write all changed buffers and exit Vim. If there are buffers
without a file name, which are readonly or which cannot be
written for another reason, Vim will not quit.:confirm
:conf
:conf[irm] {command}
Execute {command}
, and use a dialog when an
operation has to be confirmed. Can be used on the
:edit, :q, :qa and :w commands (the latter to
override a read-only setting), and any commands that
can fail because of unsaved changes, such as :only,
:buffer, :bdelete, etc.:confirm w foo
:confirm q
:confirm qa
:browse
:bro
E338
E614
E615
E616
:bro[wse] {command}
Open a file selection dialog for an argument to
{command}
. At present this works for :e, :w,
:wall, :wq, :wqall, :x, :xall, :exit,
:view, :sview, :r, :saveas, :sp, :mkexrc,
:mkvimrc, :mksession, :mkview, :split,
:vsplit, :tabe, :tabnew, :cfile, :cgetfile,
:caddfile, :lfile, :lgetfile, :laddfile,
:diffsplit, :diffpatch, :pedit, :redir,
:source, :update, :visual, :vsplit,
and :qall if 'confirm' is set.
Note: only in Win32 GUI; in console :browse edit
works if the FileExplorer autocommand group exists.
When ":browse" is not possible you get an error
message. If {command}
doesn't support browsing, the
{command}
is executed without a dialog.
":browse set" works like :options.
See also :oldfiles for ":browse oldfiles".:browse e $vim/foo
:browse e
:browse w
:browse w C:/bar
browsefilter
For MS-Windows you can modify the filters that are used in the browse
dialog. By setting the g:browsefilter or b:browsefilter variables, you can
change the filters globally or locally to the buffer. The variable is set to
a string in the format "{filter label}\t{pattern};{pattern}\n" where "{filter
label}" is the text that appears in the "Files of Type" comboBox, and {pattern}
is the pattern which filters the filenames. Several patterns can be given,
separated by ';'.let g:browsefilter = "Vim Scripts\t*.vim\nVim Startup Files\t*vimrc\n"You can override the filter setting on a per-buffer basis by setting the b:browsefilter variable. You would most likely set b:browsefilter in a filetype plugin, so that the browse dialog would contain entries related to the type of file you are currently editing. Disadvantage: This makes it difficult to start editing a file of a different type. To overcome this, you may want to add "All Files (
.
)\t*\n" as the final filter on Windows or "All
Files ()\t
\n" on other platforms, so that the user can still access any
desired file.if has("browsefilter") let g:browsefilter = "whatever" endif
:cd
E747
E472
:cd[!] On non-Unix systems when 'cdhome' is off: Print the
current directory name.
Otherwise: Change the current directory to the home
directory. Clear any window-local directory.
Use :pwd to print the current directory on all
systems.{path}
Change the current directory to {path}
.
If {path}
is relative, it is searched for in the
directories listed in 'cdpath'.
Clear any window-local directory.
Does not change the meaning of an already opened file,
because its full path name is remembered. Files from
the arglist may change though!
On MS-Windows this also changes the active drive.
To change to the directory of the current file::cd %:h
:cd-
E186
:cd[!] - Change to the previous current directory (before the
previous ":cd {path}
" command).:tc
:tcd
:tc[d][!] {path}
Like :cd, but only set the directory for the current
tab. The current window will also use this directory.
The current directory is not changed for windows in
other tabs and for windows in the current tab that
have their own window-local directory.:tcd-
:tc[d][!] - Change to the previous current directory (before the
previous ":tcd {path}
" command).:lc
:lcd
:lc[d][!] {path}
Like :cd, but only set the current directory for the
current window. The current directory for other
windows or tabs is not changed.:lcd-
:lc[d][!] - Change to the previous current directory (before the
previous ":lcd {path}
" command).:pw
:pwd
E187
:pw[d] Print the current directory name.
Also see getcwd().
:pwd-verbose
When 'verbose' is non-zero, :pwd will also display
what scope the current directory was set. Example:" Set by :cd :verbose pwd [global] /path/to/current " Set by :lcd :verbose pwd [window] /path/to/current " Set by :tcd :verbose pwd [tabpage] /path/to/currentSo long as no :lcd or :tcd command has been used, all windows share the same current directory. Using a command to jump to another window doesn't change anything for the current directory.
<EOL>
s, the lines will become very long. If you
want to edit a line that does not fit on the screen reset the 'wrap' option.
Horizontal scrolling is used then. If a line becomes too long (see limits)
you cannot edit that line. The line will be split when reading the file.
It is also possible that you get an "out of memory" error when reading the
file.
<CR>
<NL>
and <NL>
are considered to end a line
and when the file is written the <NL>
will be replaced with <CR>
<NL>
.
<Nul>
characters are shown on the screen as ^@. You can enter them with
"CTRL-V CTRL-@
" or "CTRL-V 000".
<NL>
character in the file split a line. When writing the
buffer to a file a <NL>
will be written for the <EOL>
.
<EOL>
at the end of the file if there is none.
Setting the 'binary' option prevents this. If you want to add the final
<EOL>
, set the 'endofline' option. You can also read the value of this
option to see if there was an <EOL>
for the last line (you cannot see this
in the text).
:X
E817
E818
E819
E820
Support for editing encrypted files has been removed.
https://github.com/neovim/neovim/issues/694
https://github.com/neovim/neovim/issues/701E321
E462
If you want to automatically reload a file when it has been changed outside of
Vim, set the 'autoread' option. This doesn't work at the moment you write the
file though, only when the file wasn't changed inside of Vim.
ignore-timestamp
If you do not want to be asked or automatically reload the file, you can use
this:set buftype=nofileOr, when starting gvim from a shell:
gvim file.log -c "set buftype=nofile"Note that if a FileChangedShell autocommand is defined you will not get a warning message or prompt. The autocommand is expected to handle this.
:checkt
:checktime
:checkt[ime] Check if any buffers were changed outside of Vim.
This checks and warns you if you would end up with two
versions of a file.
If this is called from an autocommand, a ":global"
command or is not typed the actual check is postponed
until a moment the side effects (reloading the file)
would be harmless.
Each loaded buffer is checked for its associated file
being changed. If the file was changed Vim will take
action. If there are no changes in the buffer and
'autoread' is set, the buffer is reloaded. Otherwise,
you are offered the choice of reloading the file. If
the file was deleted you get an error message.
If the file previously didn't exist you get a warning
if it exists now.
Once a file has been checked the timestamp is reset,
you will not be warned again.
Syntax highlighting, marks, diff status,
'fileencoding', 'fileformat' and 'binary' options
are not changed. See v:fcs_choice to reload these
too (for example, if a code formatting tools has
changed the file).{filename}
:[N]checkt[ime] [N]
Check the timestamp of a specific buffer. The buffer
may be specified by name, number or with a pattern.E813
E814
Vim will reload the buffer if you chose to. If a window is visible that
contains this buffer, the reloading will happen in the context of this window.
Otherwise a special window is used, so that most autocommands will work. You
can't close this window. A few other restrictions apply. Best is to make
sure nothing happens outside of the current buffer. E.g., setting
window-local options may end up in the wrong window. Splitting the window,
doing something there and closing it should be OK (if there are no side
effects from other autocommands). Closing unrelated windows and buffers will
get you into trouble.has('nanotime')
to check if sub-second time stamp checks are
available.starstar
Downward search uses the wildcards "*", "**" and possibly others
supported by your operating system. "*" and "**" are handled inside Vim,
so they work on all operating systems. Note that "**" only acts as a
special wildcard when it is at the start of a name./usr /usr/include /usr/include/sys /usr/include/g++ /usr/lib /usr/lib/X11 ....
/usr/**/sys/* /usr/*tory/sys/** /usr/**2/sys/*2) Upward search: Here you can give a directory and then search the directory tree upward for a file. You could give stop-directories to limit the upward search. The stop-directories are appended to the path (for the 'path' option) or to the filename (for the 'tags' option) with a ';'. If you want several stop-directories separate them with ';'. If you want no stop-directory ("search upward till the root directory") just use ';'.
/usr/include/sys;/usr
/usr/include/sys /usr/include /usr
:set path=include;/u/user_x
/u/user_x/work/release/include /u/user_x/work/include /u/user_x/include
set path=**;/u/user_x
/u/user_x/work/release/** /u/user_x/work/** /u/user_x/**
:set path=**,/u/user_x/**
/u/user_x/work/release/** /u/user_x/**