4.6 Shell Commands

The symbol ‘%’ is used in Ex shell commands to mean current file. If you want a ‘%’ in your command, it must be escaped as ‘\%’. However if ‘%’ is the first character, it stands as the address for the whole file. Similarly, ‘#’ expands to the previous file. The previous file is the first file in :args listing. This defaults to the previous file in the VI sense if you have one window.

Symbols ‘%’ and ‘#’ are also used in the Ex commands :e and :r <shell-cmd>. The commands :w and the regular :r <file> command don’t support these meta symbols, because file history is a better mechanism.

:sh

Execute a subshell in another window

:[x,y]!<cmd>

Execute a shell <cmd> [on lines x through y; % is replace by current file, \% is changed to %

:[x,y]!! [<args>]

Repeat last shell command [and append <args>].

:!<cmd>

Just execute command and display result in a buffer.

:!! <args>

Repeat last shell command and append <args>

<count> !<move><cmd>

The shell executes <cmd>, with standard input the lines described by <count><move>, next the standard output replaces those lines (think of ‘cb’, ‘sort’, ‘nroff’, etc.).

<count> !!<cmd>

Give <count> lines as standard input to the shell <cmd>, next let the standard output replace those lines.

:[x,y] w !<cmd>

Let lines x to y be standard input for <cmd> (notice the <sp> between w and !).

:<address>r !<cmd>

Put the output of <cmd> after the line <address> (default current).

:<address>r <name>

Read the file <name> into the buffer after the line <address> (default current).

:make

Run the make command in the current directory.