how can I make vim send command to gnu screen session - vim

I am trying to figure out how to script vim to send a message to a gnu screen "window". i.e. I have a screen session open and in one window I have a vim session and in the other a scheme interpreter. When I save my vim session I would like it to restart the interpreter in the other window loading in the new environment. I can figure out everything other than how to have an "on save" hook in vim send a shell command to another "screen window" causing the script to terminate and restart. if I could figure out how to send commands I could kill the process and then start a new one - I just need to make sure it starts in the right "window".

Have vim issue shell commands, and use screen -X to issue commands to screen. Some permutation of :at <other-window> stuff <restart-command>. See man screen's customization section for more commands.
For example, if I was in screen window 1, using vim, and I had an irb session in window 0, to restart the irb session, I would do
:!screen -X at 0 stuff exit^Mirb^M
(^M entered via CTRL-V Enter).

If it is sufficient for you to have the scheme interpreter run every so many seconds, you could just run watch /path/to/scheme/interpreter /path/to/scheme/file in the second screen window. Adjusting the time intervals in which watch runs commands can be adjusted using command line parameters. The watch man page contains the details.

Related

Exit Vim without clearing the terminal before

Every time after I exit Vim, it looks like the "clear" command is called automatically in the shell. Everything left on the screen is a new command line for input.
More exactly, it seems that Vim shares the same terminal with shell. After exiting Vim, the shell commands and their output are pushed pages up, and a "clear" must be called, because otherwise the content in Vim will remain on the screen.
With man and less, there is no such problem. After exiting, the screen returns what it is before running man and less. What can I do so that Vim could act like this?
You can edit ~/.vimrc and add into it set t_ti= t_te=.

How to scroll within vim's shell command output?

When I enter a shell command via vim -- e.g., :!rake routes -- I'll get some output and then:
Press ENTER or type command to continue
If I press anything at that point, I am always taken back to the main vim UI. How do I stay in that shell mode for a bit longer, specifically I can scroll back to see all the output of the command?
For terminal vim scrolling is provided by terminal emulator (or terminal multiplexer like tmux/screen if you use it). I.e. if your terminal scrolls when using <S-PageUp> it must also scroll with Vim’s !. Same for mouse wheel (it works for me even if vim was configured to handle mouse on its own).
If have terminal vim and you need to view output after you pressed <CR> then you can use <C-z>/:susp. Both these capabilities will be spoiled with incorrect configuration of either vim or terminal (terminal multiplexer) (i.e. terminal configured not to support alternate screens (which is normally issue for terminal multiplexers rather then terminal emulators: screen requires altscreen on in .screenrc) or vim setting telling vim what to output to the terminal on startup/resume and shutdown/suspend was spoiled).
If you have GUI vim your options are very limited. It is better to follow link provided by #glts or #EricAndres advice in this case as I do not use GUI vim.
:r! [shell command] will read the output from the command into the buffer. So if you open a new buffer then use that command, you can search and scroll through it all you like. See Vimcasts episode 57 for more information.

Perform a command in another shell from Vim

I use two monitors in my development workflow, one is a fullscreen vim session for editing and the other is a fullscreen terminal where I run make && ./test to show results. Fairly often I find myself opening a bunch of other windows in the background (browers, more shells etc). I don't like this for a few reasons:
I don't like having to remember how many times I have to hit tab before I get my make window.
There's no strong visual feedback in Ubuntu for which window is currently in focus. I could probably do something about that but that's a separate problem.
To be honest I'm lazy, and :w alt-tab up-arrow enter alt-tab is far too many keystrokes.
I think a good solution might be to have a vim command that runs make && ./test in the other window, but I can't think of how to do this. I could write a server/client script that waits from some notification from vim then runs the command but it really seems like there should be a simpler solution. Any thoughts?
Thanks to Jim's comment for getting me started. This is what I'm doing now:
On the first monitor: tmux new-session -s dev (creates a new tmux session named dev)
On the second monitor: tmux new -t dev (connects to that new session)
On the second monitor: Ctrl-b + c (creates a new window)
I forked vimux and wrote functions to send commands to another window. So now in vim I can use :call VimuxRunCommandWin("make && ./test").
And I think that's probably enough procrastination for one day...

Interactive terminal in VIM

I'm using Vim for editing source code, but I would also like to have a terminal embedded in vim's window (just like in Kate, you know).
Now I have seen the vimsh plugin that turns a vim buffer into an interactive terminal, but I don't like 2 things about it:
It opens automatically at startup. Can I disable it and invoke the terminal with a special command whenever I wish?
It splits the window in two and occupies the top window, but I would like it to occupy the bottom window. Can this be arranged?
PS: I'm not exactly a vim guru :)
Maybe this is what you want: Conque Shell - VIM Plugin
There's also an older patch that you can apply. It requires recompilation of the VIM source code though.
http://www.wana.at/vimshell/
Maybe I am not going to reply exactly to your question but I'll propose anyway a different approach on working with Vim and the terminal.
The first approach is to run shell commands directly from vim in command mode prepending them with a "!":
:!ls
will run the shell ls command and display you the output in a temporary window. This is useful if you just want to run a single or few commands.
If you want to mess around longer I suggest to suspend your vim session with Ctrl-z, work in the shell and issue fg as your last command to get back to vim.
Hope it helps you.
Another option you could try is using tmux/screen to split your terminal, so that you can then run vim in one pane and have your shell in another. I also liberally use ControlZ to drop into a shell from vim and then fg to get back to vim after finishing with the shell.

after quitting VIM editor I am not able to see the original screen contents that were present before entering vim

I want to see the original contents of screen after quitting vim
as they were before opening a file , as of not my file quits but the original display is not there
THanks
The feature of returning screen contents after running a full screen application vs, leaving the contents there, is not specific to vi, but to your terminal emulator. The feature you want to turn on to return to the previous text is often known as 'altscreen'. If you are using xterm as your terminal emulator, this behaviour is default. However if you are running GNU Screen inside of an xterm (or other terminal), you need to add the line
altscreen on
to your ~/.screenrc file. Other terminals that support this feature will have other mechanisms to turn it on and off.
Instead of quitting, you can put vim into the background by typing control-z. This restores the previous screen, but leaves you the editor running 'stopped' with the current file. To get vim back, enter the command
fg %1 at the shell prompt. This brings vim back to the foreground again - at least assuming you only have one stopped job. The command jobs will give you a list of stopped jobs, which you can access by number.
So the work sequence becomes edit, save, control-z, compile, test, fg...
This works on linux, and Mac OS X - YMMV on other Unix variants.
If you are using xterm, then see :help xterm-screens, or ... read that anyway as it describes that your problem should be related to some terminfo setting - probably.
HTH

Resources