My knowledge of vim is just a source code editor, used under Linux to edit the program source code or some service configuration files. Recently inadvertently seen in Vim can execute shell commands. First time See, say the truth feel good cool! Not much to say, I looked up some information, one to try, leave a note, for reference.
The shell commands are executed in Vim in the following ways:
The first type :!command
Do not exit Vim, and execute the command command of the shell, the output of commands displayed in the VIM command area, will not change the contents of the currently edited file. Execute : The!ls-al command, as shown in:
Special to run :!bash to launch a bash shell and execute commands without having to exit vim. This point in the Linux penetration test is very useful, about the log cleanup related content, do not want to say too clear, feel it. (Finally, the log files generated by Vim are removed.) Oh, Kali inside is . Viminfo, using rm-rf Force purge in vim)
The second type : R!command
Inserts the result of the shell command to the next line in the current row. For example: R!date. Reads the system time and inserts the next line into the current row. As shown in the following:
Third type : start line number, end line number!command
Lets the shell command command handle the contents of the range specified by the starting and ending line numbers and replaces the processing result with the starting line number and ending line number in the specified range. For example : 1,4!sort, sort the contents of lines 1th through 4th. As shown in the following:
You can specify only the starting line, for example : 1!tr [A-z] [a-z], and the lowercase letter of line 1th to uppercase. As shown in the following:
In addition to specifying the line extra, you can also use . Represents the row where the current cursor is located. For example :.! tr [A-z] [a-z]to capitalize the lower case of the current line. As shown in the following:
Fourth type : Start line number, end line number W!command
The input of the range specified by the starting line number and the end line number as the command, does not alter the contents of the currently edited file.
For example : 1,4 w!sort, the contents of rows 1th through 4th are sorted, but the results of the sorting are not directly exported to the currently edited file, but instead are displayed to the area of the vim knocking command. As shown in the following:
Special can use the following command : 1 w!bash, will be the content of the 1th line as a bash command to execute and display the results, and will not change the contents of the currently edited file. The same :. W!bash Executes the contents of the current line as a bash command.
Well, refer to someone else's information, try it out, tidy up the content. This is so cool.
Execute shell command in vim (cool)