Skip to main content
2 of 3
added 827 characters in body
Wildcard
  • 37.5k
  • 30
  • 149
  • 284

You can do this from within Vim:

:w !pandoc -o file.pdf

Or even write the buffer into a complex pipeline:

:w !grep pattern | somecommand > file.txt

And then you can exit Vim without saving:

:q!

However, considering your specific use case, there is probably a better solution by using vi as your command line editor. Assuming you use bash:

set -o vi

This sets your keybindings to vi. So you can edit your commands right on the command line with basic vi keybindings by pressing <Esc> and then typing vi commands such as x, cw, etc. (You can get back in insert mode by pressing i.)

Even better, and more relevant to this question, you can open Vim to create your command line content directly. Just type <Esc>v and you will get an empty Vim buffer. When you save and exit, that is the command on your command line and it is immediately run. This is much much more flexible than editing on the command line directly as you can write a whole mini-script if you want.

Wildcard
  • 37.5k
  • 30
  • 149
  • 284