vim 101 hacks
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Buyer: xiujuan lu (luxiujuan@gmail.com)<br />
Transaction ID: 85W16630AD8515549<br />
Vim <strong>101</strong> Hacks<br />
www.thegeekstuff.com<br />
Hack 78. Execute Unix Shell Command Inside Vim<br />
To execute a Unix shell command from inside the Vim editor, do the<br />
following.<br />
:!unix-command<br />
:!ls<br />
:!date<br />
You can also pass the current file name as a parameter to the Unix command<br />
using the following methods.<br />
Let us assume that you are running all the following commands when you<br />
have /etc/sysctl.conf file open in the Vim editor:<br />
Command<br />
:!echo %<br />
sysctl.conf<br />
Description<br />
% will pass the current file name to the Unix<br />
command.<br />
For example, :!ls –l % -- This will execute ls –l on<br />
the current file in Vim editor<br />
:!echo %:p<br />
/etc/sysctl.conf<br />
:!echo %:e<br />
conf<br />
%:p will pass the full path name of the file to the<br />
Unix command<br />
%:e will pass the extension of the file to the Unix<br />
command<br />
116