Executing shell commands in the VIM editor
The 11th Chapter VI and VIM text editors for Linux commands, editors, and shell programming, this chapter will briefly describe how to edit text using the VI and VIM editors. This section describes the execution of Shell commands in the Vim editor.
11.7.5 execute shell commands in the VIM editor
Sometimes you need to execute a shell command in the Vim editor, such as the need to verify that a shell command is correct for writing to a script, and that you need to reference the input of a shell command in a file. This section provides a brief description of how to execute shell commands in the Vim editor.
(1) When executing a separate shell command in the Vim editor, you need to add ":!" before the command. For example, executing the shell command ":!ls-l" in vim command mode, the VIM editor will display the output of the command, as shown in Figure 11.27.
|
Figure 11.27 Executing the shell command in the VIM editor |
As you can see from Figure 11.27, VIM will display the output of the command. If the user needs to return to edit the file, you can press the ENTER key.
(2) Sometimes you may need to refer to the output of the shell command in the file edited by the editor, and you can match the command ": R". For example, to read the output of the Ls-l command to the currently edited file, you can use ": R!ls-l". The VIM editor then reads the output of the command and inserts it into the currently edited file.