Skip to main content
added 827 characters in body
Source Link
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.


So, for example, if you want to write some tricky text and pipe it into pandoc immediately, you could just type:

<Esc>v

Then edit the Vim buffer until you have something like:

cat <<EOF | pandoc -o file.pdf
stuff for pandoc
more stuff for pandoc
EOF

Then save and exit (with :x) and the whole thing will be run as a shell command.

It will also be available in your shell's command history.

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.

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.


So, for example, if you want to write some tricky text and pipe it into pandoc immediately, you could just type:

<Esc>v

Then edit the Vim buffer until you have something like:

cat <<EOF | pandoc -o file.pdf
stuff for pandoc
more stuff for pandoc
EOF

Then save and exit (with :x) and the whole thing will be run as a shell command.

It will also be available in your shell's command history.

added 827 characters in body
Source Link
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.

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!

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.

Source Link
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!