user91240192094
user91240192094

Reputation: 408

In terminal - show ouput in new vim buffer

I'm trying to get the functionality that I saw in a video. Essentially the person was in the terminal (I believe using tmux in case that matters) and with a shortcut turned stdout into a vim buffer and could easily navigate and select/copy text that way. How is this done?

Upvotes: 1

Views: 299

Answers (4)

sudo bangbang
sudo bangbang

Reputation: 28229

You're talking about tmux's copy mode

By default you can get in to copy mode by ctrlb[ If C-b is your prefix. Otherwise use prefix + [

You can use motion with hjklw^, search with ?/ etc.

Some related details

Upvotes: 2

romainl
romainl

Reputation: 196886

In readline, in the default emacs mode, you can press <C-x><C-e> to edit the current command line in $EDITOR.

If you use vi mode, you can press <Esc>v to do the same.

Upvotes: 0

ronakg
ronakg

Reputation: 4212

You can run :read !<cmd> to execute a command in shell and capture the output to current buffer.

For example - :read !date

If you want the output in a new buffer, use :new.

So both combined, :new | read !date

Upvotes: 0

SibiCoder
SibiCoder

Reputation: 1496

tabnew command is used to open a new tab.

You can use a pipeline symbol and then other commands. The output of those commands will be redirected to new buffer.

Example:

         :tabnew | r! pwd

pwd will print the current directory and r will read it. Tabnew will put that output in new buffer. You can use both shell commands as well as vim commands.

Similarly, enew command can be used instead of tabnew for new buffer. See here: https://superuser.com/questions/157987/pipe-output-of-shell-command-into-a-new-buffer-in-vim

How to redirect stdout output to a new Vim tab?

How do I dump output of an external command to a new buffer in Vim?

Upvotes: 0

Related Questions