c_CTRL-D
CTRL-D List names that match the pattern in front of the cursor.
When showing file names, directories are highlighted (see
highlight-groups). Names where 'suffixes' matches are moved
to the end.
The 'wildoptions' option can be set to "tagfile" to list the
file of matching tags.
c_CTRL-I c_wildchar c_<Tab>
'wildchar' option
A match is done on the pattern in front of the cursor. The
match (if there are several, the first match) is inserted
in place of the pattern. (Note: does not work inside a
macro, because <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).
The behavior can be changed with the 'wildmode' option.
c_CTRL-N
CTRL-N After using 'wildchar' which got multiple matches, go to next
match. Otherwise recall more recent command-line from history.
<S-Tab> c_CTRL-P c_<S-Tab>
CTRL-P After using 'wildchar' which got multiple matches, go to
previous match. Otherwise recall older command-line from
history. <S-Tab> only works with the GUI.
c_CTRL-A
CTRL-A All names that match the pattern in front of the cursor are
inserted.
c_CTRL-L
CTRL-L A match is done on the pattern in front of the cursor. If
there is one match, it is inserted in place of the pattern.
If there are multiple matches the longest common part is
inserted in place of the pattern. If the result is shorter
than the pattern, no completion is done.
/_CTRL-L
When 'incsearch' is set, entering a search pattern for "/" or
"?" and the current match is displayed then 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.
c_CTRL-G /_CTRL-G
CTRL-G When 'incsearch' is set, entering a search pattern for "/" or
"?" and the current match is displayed then CTRL-G will move
to the next match (does not take search-offset into account)
Use CTRL-T to move to the previous match. Hint: on a regular
keyboard T is above G.
c_CTRL-T /_CTRL-T
CTRL-T When 'incsearch' is set, entering a search pattern for "/" or
"?" and the current match is displayed then CTRL-T will move
to the previous match (does not take search-offset into
account).
Use CTRL-G to move to the next match. Hint: on a regular
keyboard T is above G.
The 'wildchar' option defaults to <Tab> (CTRL-E when in Vi compatible mode; in
a previous version <Esc> was used). In the pattern standard wildcards '*' and
'?' are accepted when matching file names. '*' matches any string, '?'
matches exactly one character.
The 'wildignorecase' option can be set to ignore case in filenames.
The 'wildmenu' option can be set to show the matches just above the command
line.
If you like tcsh's autolist completion, you can use this mapping:
: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.
If you like tcsh's autolist completion, you can use the 'wildmode' option to
emulate it. For example, this mimics autolist=ambiguous:
:set wildmode=longest,list
This will find the longest match with the first 'wildchar', then list all
matching files with the next.
suffixes
For file name completion you can use the 'suffixes' option to set a priority
between files with almost the same name. If there are multiple matches,
those files with an extension that is in the 'suffixes' option are ignored.
The default is ".bak,~,.o,.h,.info,.swp,.obj", which means that files ending
in ".bak", "~", ".o", ".h", ".info", ".swp" and ".obj" are sometimes ignored.
An empty entry, two consecutive commas, match a file name that does not
contain a ".", thus has no suffix. This is useful to ignore "prog" and prefer
"prog.c".
Examples:
pattern: files: match:
test* test.c test.h test.o test.c
test* test.h test.o test.h and test.o
test* test.i test.h test.c test.i and test.c
It is impossible to ignore suffixes with two dots.
If there is more than one matching file (after ignoring the ones matching
the 'suffixes' option) the first file name is inserted. You can see that
there is only one match when you type 'wildchar' twice and the completed
match stays the same. You can get to the other matches by entering
'wildchar', CTRL-N or CTRL-P. All files are included, also the ones with
extensions matching the 'suffixes' option.
To completely ignore files with some extension use 'wildignore'.
To match only files that end at the end of the typed text append a "$". For
example, to match only files that end in ".c":
e *.c$
This will not match a file ending in ".cpp". Without the "$" it does match.
The old value of an option can be obtained by hitting 'wildchar' just after
the '='. For example, typing 'wildchar' after ":set dir=" will insert the
current value of 'dir'. This overrules file name completion for the options
that take a file name.
If you would like using <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>
The Ex commands have a few specialties:
:bar :\bar
'|' can be used to separate commands, so you can give multiple commands in one
line. If you want to use '|' in an argument, precede it with '\'.
These commands see the '|' as their argument, and can therefore not be
followed by another Vim command:
:argdo
:autocmd
:bufdo
:cdo
:cfdo
:command
:cscope
:debug
:folddoopen
:folddoclosed
:function
:global
:help
:lcscope
:ldo
:lfdo
:make
:normal
:promptfind
:promptrepl
:pyfile
:python
:registers
:read !
:scscope
:sign
:vglobal
:windo
:write !
:[range]!
a user defined command without the "-bar" argument :command
Note that this is confusing (inherited from Vi): With ":g" the '|' is included
in the command, with ":s" it is not.
To be able to use another command anyway, use the ":execute" command.
Example (append the output of "ls" and jump to the first line):
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.
Examples:
:!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>-join
This reads the current date into the file and joins it with the previous line.
Note that when the command before the '|' generates an error, the following
commands will not be executed.
Because of Vi compatibility the following strange commands are supported:
| print current line (like ":p")
3| print line 3 (like ":3p")
3 goto line 3
A colon is allowed between the range and the command name. It is ignored
(this is Vi compatible). For example:
1,$:s/pat/string
When 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" :_% :_#).
Trailing spaces in filenames will be ignored, unless escaped with a backslash
or 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 ".
When you want to use the special characters '"' or '|' in a command, or want
to use '%' or '#' in a file name, precede them with a backslash. The
backslash is not required in a range and in the ":substitute" command.
See also `=.
{number} an absolute line number
. the current line :.
$ the last line in the file :$
% equal to 1,$ (the entire file) :%
't position of mark t (lowercase) :'
'T position of mark T (uppercase); when the mark is in
another file it cannot be used in a range
/{pattern}[/] the next line where {pattern} matches :/
?{pattern}[?] the previous line where {pattern} matches :?
\/ the next line where the previously used search
pattern matches
\? the previous line where the previously used search
pattern matches
\& the next line where the previously used substitute
pattern matches
Each may be followed (several times) by '+' or '-' and an optional number.
This number is added or subtracted from the preceding line number. If the
number is omitted, 1 is used.
The "/" and "?" after {pattern} are required to separate the pattern from
anything that follows.
The "/" and "?" may be preceded with another address. The search starts from
there. The difference from using ';' is that the cursor isn't moved.
Examples:
/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).
Examples:
.+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).
Examples:
: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
When folds are active the line numbers are rounded off to include the whole
closed fold. See fold-behavior.
When giving a count before entering ":", this is translated into:
:.,.+(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>
Note: These are special characters in the executed command line. If you want
to insert special things while typing you can use the 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.
Note: If you want to avoid the effects of special characters in a Vim script
you may want to use fnameescape(). Also see `=.
In Ex commands, at places where a file name can be used, the following
characters have a special meaning. These can also be used in the expression
function expand().
% Is replaced with the current file name. :_% c_%
# Is replaced with the alternate file name. :_# c_#
This is remembered for every window.
#n (where n is a number) is replaced with :_#0 :_#n
the file name of buffer n. "#0" is the same as "#". c_#n
## Is replaced with all names in the argument list :_## c_##
concatenated, separated by spaces. Each space in a name
is preceded with a backslash.
#<n (where n is a number > 0) is replaced with old :_#< c_#<
file name n. See :oldfiles or v:oldfiles to get the
number. E809
{only when compiled with the +eval and +shada features}
Note that these, except "#<n", give the file name as it was typed. If an
absolute path is needed (when using the file name from a different directory),
you need to add ":p". See filename-modifiers.
The "#<n" item returns an absolute path, but it will start with "~/" for files
below your home directory.
Note that backslashes are inserted before spaces, so that the command will
correctly interpret the file name. But this doesn't happen for shell
commands. For those you probably have to use quotes (this fails for files
that contain a quote and wildcards):
!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.
you type: result
# alternate.file
\# #
\\# \#
Also see `=.
:<cword> :<cWORD> :<cfile> <cfile>
:<sfile> <sfile> :<afile> <afile>
:<abuf> <abuf> :<amatch> <amatch>
:<cexpr> <cexpr>
<slnum> E495 E496 E497 E499 E500
Note: these are typed literally, they are not special keys!
<cword> is replaced with the word under the cursor (like star)
<cWORD> is replaced with the WORD under the cursor (see WORD)
<cfile> is replaced with the path name under the cursor (like what
gf uses)
<afile> When executing autocommands, is replaced with the file name
of the buffer being manipulated, or the file for a read or
write.
<abuf> When executing autocommands, is replaced with the currently
effective buffer number (for ":r file" and ":so file" it is
the current buffer, the file being read/sourced is not in a
buffer).
<amatch> When executing autocommands, is replaced with the match for
which this autocommand was executed. It differs from
<afile> only when the file name isn't used to match with
(for FileType, Syntax and SpellFileMissing events).
<sfile> When executing a ":source" command, is replaced with the
file name of the sourced file. E498
When executing a function, is replaced with:
"function {function-name}[{lnum}]"
function call nesting is indicated like this:
"function {function-name1}[{lnum}]..{function-name2}[{lnum}]"
Note that filename-modifiers are useless when <sfile> is
used inside a function.
<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.
filename-modifiers
:_%: ::8 ::p ::. ::~ ::h ::t ::r ::e ::s ::gs ::S
%:8 %:p %:. %:~ %:h %:t %:r %:e %:s %:gs %:S
The file name modifiers can be used after "%", "#", "#n", "<cfile>", "<sfile>",
"" or "". They are also used with the fnamemodify() function.
These are not available when Vim has been compiled without the +modify_fname
feature.
These modifiers can be given, in this order:
:p Make file name a full path. Must be the first modifier. Also
changes "~/" (and "~user/" for Unix) to the path for the home
directory. If the name is a directory a path separator is
added at the end. For a file name that does not exist and
does not have an absolute path the result is unpredictable.
On MS-Windows an 8.3 filename is expanded to the long name.
:8 Converts the path to 8.3 short format (currently only on
MS-Windows). Will act on as much of a path that is an
existing path.
:~ Reduce file name to be relative to the home directory, if
possible. File name is unmodified if it is not below the home
directory.
:. Reduce file name to be relative to current directory, if
possible. File name is unmodified if it is not below the
current directory.
For maximum shortness, use ":~:.".
:h Head of the file name (the last component and any separators
removed). Cannot be used with :e, :r or :t.
Can be repeated to remove several components at the end.
When the file name ends in a path separator, only the path
separator is removed. Thus ":p:h" on a directory name results
on the directory name itself (without trailing slash).
When the file name is an absolute path (starts with "/" for
Unix; "x:\" for Windows), that part is not removed.
When there is no head (path is relative to current directory)
the result is empty.
:t Tail of the file name (last component of the name). Must
precede any :r or :e.
:r Root of the file name (the last extension removed). When
there is only an extension (file name that starts with '.',
e.g., ".nvimrc"), it is not removed. Can be repeated to
remove several extensions (last one first).
:e Extension of the file name. Only makes sense when used alone.
When there is no extension the result is empty.
When there is only an extension (file name that starts with
'.'), the result is empty. Can be repeated to include more
extensions. If there are not enough extensions (but at least
one) as much as possible are included.
:s?pat?sub?
Substitute the first occurrence of "pat" with "sub". This
works like the :s command. "pat" is a regular expression.
Any character can be used for '?', but it must not occur in
"pat" or "sub".
After this, the previous modifiers can be used again. For
example ":p", to make a full path after the substitution.
:gs?pat?sub?
Substitute all occurrences of "pat" with "sub". Otherwise
this works like ":s".
:S Escape special characters for use with a shell command (see
shellescape()). Must be the last one. Examples:
!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.c
Examples, 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
extension-removal :_%<
If a "<" is appended to "%", "#", "#n" or "CTRL-V p" the extension of the file
name is removed (everything after and including the last '.' in the file
name). This is included for backwards compatibility with version 3.0, the
":r" form is preferred. Examples:
% 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 extension
Note: 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).
Unless in restricted-mode, 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 `=.
When the expanded argument contains a "!" and it is used for a shell command
(":!cmd", ":r !cmd" or ":w !cmd"), the "!" is escaped with a backslash to
avoid it being expanded into a previously used command. When the 'shell'
option contains "sh", this is done twice, to avoid the shell trying to expand
the "!".
CLOSE E199
There are several ways to leave the command-line window:
<CR> Execute the command-line under the cursor. Works both in
Insert and in Normal mode.
CTRL-C Continue in Command-line mode. The command-line under the
cursor is used as the command-line. Works both in Insert and
in Normal mode. There is no redraw, thus the window will
remain visible.
:quit Discard the command line and go back to Normal mode.
":close", ":exit", ":xit" and CTRL-\ CTRL-N also work.
:qall Quit Vim, unless there are changes in some buffer.
:qall! Quit Vim, discarding changes to any buffer.
Once the command-line window is closed the old window sizes are restored. The
executed command applies to the window and buffer where the command-line was
started from. This works as if the command-line window was not there, except
that there will be an extra screen redraw.
The buffer used for the command-line window is deleted. Any changes to lines
other than the one that is executed with <CR> are lost.
If you would like to execute the command under the cursor and then have the
command-line window open again, you may find this mapping useful:
autocmd CmdwinEnter * map <buffer> <F5> <CR>q:
VARIOUS
The command-line window cannot be used when there already is a command-line
window (no nesting).
Some options are set when the command-line window is opened:
'filetype' "vim", when editing an Ex command-line; this starts Vim syntax
highlighting if it was enabled
'rightleft' off
'modifiable' on
'buftype' "nofile"
'swapfile' off
It is allowed to write the buffer contents to a file. This is an easy way to
save the command-line history and read it back later.
If the 'wildchar' option is set to <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:
imap <buffer> <Tab> <C-X><C-V>
nmap <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 <Tab>
au CmdwinEnter [:>] nunmap <Tab>
You could put these lines in your vimrc file.
While in the command-line window you cannot use the mouse to put the cursor in
another window, or drag statuslines of other windows. You can drag the
statusline of the command-line window itself and the statusline above it.
Thus you can resize the command-line window, but not others.
The getcmdwintype() function returns the type of the command-line being
edited as described in cmdwin-char.
AUTOCOMMANDS
Two autocommand events are used: CmdwinEnter and CmdwinLeave. Since this
window is of a special type, the WinEnter, WinLeave, BufEnter and BufLeave
events are not triggered. You can use the Cmdwin events to do settings
specifically for the command-line window. Be careful not to cause side
effects!
Example:
au CmdwinEnter : let b:cpt_save = &cpt | set cpt=.
au CmdwinLeave : let &cpt = b:cpt_save
This sets 'complete' to use completion in the current window for i_CTRL-N.
Another example:
au CmdwinEnter [/?] startinsert
This will make Vim start in Insert mode in the command-line window.