Command-Line Mode


In addition to the normal text interface, Vim provides commands that allow you to modify the buffer in various ways using a simple command-line interface.

Executing Terminal Commands

Enter command-line mode from normal mode by typing :, which opens the command line at the bottom of the screen, and awaits further input. These commands generally follow one of several patterns:

You are actually already familiar with many command-line mode commands. For example, when we write to a file :write we are using command-line mode to interact with the filesystem.

To run a terminal command without input or output

:! {command}

To run a terminal command using content from Vim as input:

:! {command}

To run a terminal and pass the output to the current buffer

:read !{command}

As you can see from the syntax structure preceding, the :! command allows you to pass to it any command that you would typically run from the terminal command-line interface. So, as an example, if you wanted to see what the current working directory was, run the :! pwd command. The result of executing this command is that Vim is pushed into a background process long enough for the command you specified to be run and for you to review the result of the command. Vim will only return to the foreground once you press the key.

Note

Be sure to review how to review our article detailing how to navigate in the command line.