Print terminal command output directly into vim - macOS - 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.
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.

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!
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 :).

Related

My emacs client automagically terminates when switching applications [OSX iTerm2]

I try to be brave and switch from vi to emacs.
Now, I set up Emacs 26 on macOS via homebrew and start Emacs as daemon in the background.
I can use files using emacsclient -t. However, whenever I bring the Terminal into the background emacsclient exits within a few seconds.
See example Video here: https://cloud.familie-ganter.de/s/QwbK8cFBHnPjQ4d
I did a plain install. My init file does not contain anything except what you see in the video. The funny thing is whenever I start emacs directly in the Terminal, nothing at all happens when bringing it to the background.
What seems to be the problem?
I am lost …
I expect it to be something dumb and simple -- so please be nice, this is my first stackoverflow post.

Emacs shell control of command output display

I've just upgraded OS from Ubuntu 16.04 to 18.04 and for some reason emacs disappeared.
On reinstalling I've just noticed that running M-x shell then hg diff produces an error message:
WARNING: terminal is not fully functional
- (press RETURN)
I think I may have fixed this by running:
export TERM=xterm
After which I got a very colourful shell experience and no warning on running hg diff
However, its only displaying one page of the hg diff output then pausing with a : at a time now, previously it printed the lot without stopping.
I think this may be acceptable, if I could figure out what key allows me to print the next page of hg diff output, and ideally, what key would allow printing all remaining hg diff output and return me to the shell prompt.
If I hit return I get an additional line at a time, but this is a bit slow and not really ideal.
I think this is maybe a question about xterm shortcut keys? Possibly not emacs specific, but I'm not sure..
shell-mode is line-buffered, meaning the input won't be sent to the underlying process until you enter RET. In this case, the output should be running through a program like less where RET would give you another page instead of a single line.
So, in shell-mode you can use SPC followed by a RET. In term-mode where the default is not line-buffered (to resemble the underlying shell as transparently as possible) a single RET should suffice to give you a new page.

how do you enable command line editing with vim keys using mac terminal?

I'm reading this book and I really do not understand what this author is talking about. It appears that you can program your mac to go forward one character by either hitting l or ^F. I do not understand the difference between emac key stroke and vim keystroke. He also says run this command and 'place it in your $HOME/.bash_profile but I cannot figure out how to place the command in the bas_profile.
The Author is talking about make you terminal console behaves like vi, this means typing set -o vi in your terminal, the console will work similar vi. So you will be able to navigate using the motion keys of vi, use INSERT mode, x to delete, etc.
You can set that permanently if you include this command in your ~/.bash_profile file.
If you are not sure what it does, I don't recommend so.

Execute a bash command in the text of a vim buffer

I know that I can get into bash while in vim via:
Ctrlz
or
:sh
or
:shell
etc.
Then use bash commands as normal, and get back out using fg.
What I am wondering is, can I execute a line of code from a script in vim straight to Bash, without having to exit vim, or having to copy it (via highlighting in visual mode for example) from vim, then going to a terminal and pasting it and hitting enter etc.?
Easiest way is to put the cursor on the line and type:
!!shreturn
This will replace the line with the output of the script. If you don't want that, simply follow up with u.
Arguably easiest way:
Yank the text you want to execute.
Open the cmdline (by pressing :)
type ! and then press ctrl-r and ", which will paste the content of the unnamed register to the cmdline (which will contain the text you wanted to execute)
press Enter

Break the current program without exiting VIM

When using VIM, I usually like to run programs by using the bang in command mode.
That is, use
:!<external shell command>
to test code without exiting vim or alt-tabbing to another open shell. So for example, when writing Java code, I might do something like
:!java Main
Or in C, maybe
:!cls & gcc -g -o main Program.c File.c & main
This works fine. The VIM window turns into a shell, my program runs, and then upon exit I get back into VIM.
The issue is when my program hits an infinite loop. I get stuck with the terminal displaying the standard output and then I can't get back to VIM. Control-C exits EVERYTHING and then I need to re-open VIM and re-open all my files and it's a big mess (especially if I didn't save something!).
tl;dr Is there a way to stop internally-running externally-defined shell commands in VIM?
In my case, Ctrl-c works just fine.
I am on vim 7.4 on ubuntu 14.04.
Control-z works instead of Control-c

Resources