Our Blog

Ongoing observations by End Point people

VIM Tip of the Day: running external commands in a shell

By Selena Deckelmann
March 10, 2009

A common sequence of events when editing files is to make a change and then need to test by executing the file you edited in a shell. If you’re using vim, you could suspend your session (ctrl-Z), and then run the command in your shell.

That’s a lot of keystrokes, though.

So, instead, you could use vim’s built-in “run a shell command”!

:!{cmd} Run a shell command, shows you the output and prompts you before returning to your current buffer.

Even sweeter, is to use the vim special character for current filename: %

Here’s :! % in action!

A few more helpful shortcuts related to executing things in the shell:

  • :! By itself, runs the last external command (from your shell history)
  • :!! Repeats the last command
  • :silent !{cmd} Eliminates the need to hit enter after the command is done
  • :r !{cmd} Puts the output of $cmd into the current buffer.

tips vim


Comments

Popular Tags


Archive


Search our blog