Execute command-line statements from within the vi editor
It is very simple and occasionally useful to access the power of the shell from within your vim text editor. In normal mode (esc from insert mode), simply type, colon included
:r
Commands must be preceded by a bang symbol (exclamation mark). Some examples:
:r !date
Personally, i'll find this useful simply for putting in paths from the file system that i may not be certain of but that bash's tab autocomplete will be able to verify for me.
:r !echo /var/local
In UNIX, everything is a file, so what :r
is doing is returning the output of the file created by a command (the standard output). This is just to mention that we can stick a file into our document directly.
:r ~/tmp/id_rsa.pub
That inserts the contents of the id_rsa.pub file right where you have your cursor in the document in vi normal mode.
Reference
http://princ3.wordpress.com/2007/08/27/insert-current-date-in-vim/
Comments
Post new comment