jason z
jason z

Reputation: 1377

Print terminal command output directly into vim - macOS

Whenever I enter a terminal command in vim (e.g., !echo hello), I am momentarily kicked out to view the result of that terminal command and then prompted with Press ENTER or type command to continue. This is a bit jarring. I would like to stay within vim and with the command output printed out at the bottom.

image of getting kicked out of vim to view and respond to a terminal command that was run within vim

I know vim :read will take the terminal output and actually put it into my buffer, but that is not what I am looking to do. Here is some reading if you are interested in a tangent.

It looks like when I run vim in Screen I get what I am looking for, but I am trying to get this to work with tmux and the stock Mac terminal.

Upvotes: 3

Views: 1411

Answers (1)

jason z
jason z

Reputation: 1377

After a ton of research, probably too much, I got it! It looks like vim will send commands to the terminal, which in turn defines the behavior of how the terminal commands are processed from vim. Put this into your .vimrc file:

set t_ti= t_te= " show results from terminal commands within vim!

From what I understand, this just makes sure to send nothing to the terminal, which yields my desired results!

image of terminal command run within vim showing output in vim

Side note: the above addition to your .vimrc file will also prevent the vim buffer from clearing when exiting vim (e.g., :wq). I am okay with this! It is kind of nice sometimes to see what you were just working on :).

Upvotes: 2

Related Questions