User login

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
Wed Apr 21 23:04:22 PDT 2010

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
/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/

Searched words: 
vi insert unix command insert value command-line access from within vim execute UNIX commands from inside vim editor vi improved editor stick in result of CLI statement

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.