Fails if changes have been made to the current buffer,
unless 'hidden' is set.
If {cmd} is omitted, and the 'shell' job exits with no
error, the buffer is closed automatically
|default-autocmds|.
To enter |Terminal-mode| automatically: >
autocmd TermOpen * startinsert
<
*:!cmd* *:!*
:!{cmd} Execute {cmd} with 'shell'. See also |:terminal|.
For the filter command, see |:range!|.
The command runs in a non-interactive shell connected
to a pipe (not a terminal). Use |:terminal| to run an
interactive shell connected to a terminal.
Backgrounded ("&") commands must not write to stdout
or stderr, the streams are closed immediately. |E5677|
Use |jobstart()| instead. >
:call jobstart('foo', {'detach':1})
<
For powershell, chaining a stringed executable path
requires using the call operator (&). >
:!Write-Output "1`n2" | & "C:\Windows\System32\sort.exe" /r
<
Vim builds command line using options 'shell', 'shcf',
'sxq' and 'shq' in the following order:
`&sh &shcf &sxq &shq {cmd} &shq &sxq`
So setting both 'sxq' and 'shq' is possible but rarely
useful. Additional escaping inside `{cmd}` may also
be due to 'sxe' option.
Also, all |cmdline-special| characters in {cmd} are
replaced by Vim before passing them to shell.
*E34*
Any "!" in {cmd} is replaced with the previous
external command (see also 'cpoptions'), unless
escaped by a backslash. Example: ":!ls" followed by
":!echo ! \! \\!" executes "echo ls ! \!".
Any "|" in {cmd} is passed to the shell, you cannot
use it to append a Vim command. See |:bar|.
Any "%" in {cmd} is expanded to the current file name.
Any "#" in {cmd} is expanded to the alternate file name.
Special characters are not escaped, use quotes or
|shellescape()|: >
:!ls "%"
:exe "!ls " .. shellescape(expand("%"))
<
Newline character ends {cmd} unless a backslash
precedes the newline. What follows is interpreted as
another |:| command.
After the command has been executed, the timestamp and
size of the current file is checked |timestamp|.
If the command produces too much output some lines may
be skipped so the command can execute quickly. No
data is lost, this only affects the display. The last
few lines are always displayed (never skipped).
To avoid the hit-enter prompt use: >
:silent !{cmd}
<
*:!!*
:!! Repeat last ":!{cmd}".
*:ve* *:ver* *:version*
:ve[rsion] Print editor version and build information.
See also |feature-compile|.
*:redi* *:redir*
:redi[r][!] > {file} Redirect messages to file {file}. The messages which
are the output of commands are written to that file,
until redirection ends. The messages are also still
shown on the screen. When [!] is included, an
existing file is overwritten. When [!] is omitted,
and {file} exists, this command fails.
Only one ":redir" can be active at a time. Calls to
":redir" will close any active redirection before
starting redirection to the new target. For recursive
use check out |execute()|.
To stop the messages and commands from being echoed to
the screen, put the commands in a function and call it
with ":silent call Function()".
Alternatives are the 'verbosefile' option or
|execute()| function, these can be used in combination
with ":redir".
:redi[r] >> {file} Redirect messages to file {file}. Append if {file}
already exists.
:redi[r] @{a-zA-Z}
:redi[r] @{a-zA-Z}> Redirect messages to register {a-z}. Append to the
contents of the register if its name is given
uppercase {A-Z}. The ">" after the register name is
optional.
:redi[r] @{a-z}>> Append messages to register {a-z}.
:redi[r] @*>
:redi[r] @+> Redirect messages to the selection or clipboard. For
backward compatibility, the ">" after the register
name can be omitted. See |quotestar| and |quoteplus|.
:redi[r] @*>>
:redi[r] @+>> Append messages