Emacs: Opening a file within the same Emacs session from a tmux session in ansi-term - session

I often come across the situation where I want to open a file that I am viewing from my tmux session in ansi-term into my Emacs session. I tried to use find-file-at-point (see Max Bozzi's answer below), but in tmux it only directs me to the working directory of my ansi-term session, and it does not detect the file in my tmux session. With ansi-term alone, find-file-at-point works fine, but I prefer to use a session manager, or at least a solid terminal multiplexer.
Any suggestions?
For example, here is my tmux session in ansi-term:
lucas#~/Downloads$ ls
A CHRISTMAS CAROL (ILLUSTRATED with Special Kindle Format).azw3
bleachbit_1.0_all_ubuntu1310.deb
Island of the Blue Dolphins.azw3
javaPong.jnlp
test.txt
How do I open test.txt within my Emacs session?

One option is to place point on the name of the file and then run find-file-at-point. I find that to be useful enough to bind to M-'.
Another is to just use the standard C-c C-f and tab-complete the name, or maybe if you really wanted to, to have recursive Emacs and have Emacs running inside Emacs' own terminal buffer. Presumably you wouldn't, though, so I would stick to find-file-at-point.

Related

Opening files into an existing vim session (Cygwin/mintty)

I am looking for ideas to open files into an existing vim session.
I am working on Windows + Cygwin + Mintty. I usually have 3 to 4 opened terminals (2-3 vim sessions + 1 shell, build environment). I don't use tmux/screen because it's easier to use the native Windows's window manager to switch in between my terminal windows. Because I have 2 wide-screen monitors I can use the 2 half of both screens for my terminals which gives me an awesome working environment. With the help of an AHK script, I can use shortcuts to switch/rotate or even to reposition my terminals in the desired position.
I rather prefer vim over gvim for many reasons. I can achieve almost all the gvim features (scroll, mouse selection, copy, paste, etc. I am one of those who think that using the respectable y/P commands is a bit crippling when you need to use plenty of other softwares that use /. I always get confused to use different shortcuts for each software I am using.
Now the core issue. I would like to open a file from the Windows explorer into an existing vim session. I found a horrible solution using a Perl script with the Win32::API in order to look for an existing mintty terminal with Vim in the title. Then I activate the window and send <esc>:e path/file<cr> to it.
It works pretty well but I am looking for a better solution like gvim --remote that works with my console vim. Unfortunately I don't have such options with my vim even though if I built it with the -with-x configure option.
So, I am looking for some suggestions to achieve a more honorable solution (socket/adding the feature directly to vim/using a smarter ahk script/etc.)
gvim --remote should work with console vim if you start vim with vim --servername GVIM. Alternatively, choose another servername and use vim --servername foo --remote.

End of lines are grey with vim and zsh

I use vim and ZSH. When I open a document, the background seems to not be correct at the end of each lines as you can see here :
I tried with different colorscheme and it do the same thing. It works with bash.
What is the solution?
These visual problems usually occur when Vim cannot fully control the terminal: Basic stuff like screen updates work, but things that are handled differently in different terminals (like setting the background color) do not.
Check and compare the values for $TERM in bash and zsh; it's likely the latter one is wrong. You shouldn't hard-code them in a startup file like ~/.bashrc; instead, this variable should be set by your terminal emulator(s). This way, you can also work when you connect remotely via a different terminal emulator (e.g. PuTTY on Windows).

Run terminal inside vim on a macbook?

I searched some old answers on stackoverflow, some of them seem relevant, but none of the solutions work on my macbook (with mountain lion). e.g. The shortcuts mentioned in answers here do not work on my computer: How do I run a terminal inside of Vim?
So I'm wondering if it's because vim on mac/unix is different from a normal linux one. I don't think so, but I'm not sure.
Since I can split the screen with :sp, I'm wondering if it's possible to use one split as terminal and another as the regular vim editor, just like emacs. If so, what's the correct way to do it? (Maybe particularly for mac) If not, it's sad.
Why don't you do things the other way around?
You can use a terminal multiplexer such as Tmux and split a terminal window into two panes using C-b %.
Inside the second pane you can run macvim inside a terminal with $ mvim -v
You can navigate between the two panes with C-b o, (And do much more, but I'll leave it up to you to discover!)
Doing things this way around is much more sane in my opinion, you get the full power of both the terminal and vim without having to hack around with Vim too much (Plus Tmux is very handy for many other uses).
I hope doing things this way around is appealing enough for you!
Having a terminal inside of vim would go against the author's philosophy and design so no: that feature will probably never appear nativelyly in vim.
There are a couple of plugins that more or less work like conqueterm, try them if you really want that feature. Or simply use a separate terminal window like everybody.
You should definitely look at programs like tmux or screen.
But an even simpler solution is to use C-z (which halt vim) to access the terminal and fg to bring back vim into the foreground.

leave vim split window in insert mode

I want to view the output of a bash command in a vim split window :split. To this end I installed "Conque Shell" which displays bash in a split window upon :ConqueTermSplit bash. I can then run my shell command and watch the output in insert mode. However, to return to the other window I need to type <CTRL-W> <Up> in command mode, so I need to leave insert mode. Hence the display of the command output freezes and continues only if I return to this window and enter insert mode. So how can I leave "Conque Shell" without leaving insert mode.
Note that other ways of viewing the bash output in a second window might solve my problem as well. However it should update while I am working in the other window and allow me to signal e.g. <CTRL-C> to the application.
The ConqueTerm documentation says:
3.1.5 Keep updating terminal buffer *ConqueTerm_ReadUnfocused*
If set to 1 then your Conque buffers will continue to update after you've
switched to another buffer.
Note: Conque buffers may continue to update, but they will not scroll down as
new lines are added beyond the bottom of the visible buffer area. This is a
limitation of the Vim scripting language for which I haven't found a
workaround.
>
let g:ConqueTerm_ReadUnfocused = 1
AFAIK Vim has no support for asynchronous sessions, so this is more of a response to your request for potential alternative options.
The way that I currently get around this issue is by using tmux, which is described as:
a terminal multiplexer: it enables a number of terminals (or windows),
each running a separate program, to be created, accessed, and
controlled from a single screen.
So, basically, instead of splitting your screen in Vim you would split it using tmux, and then in one window run Vim and in the other run whatever other program you want which will update completely independently of Vim. And just like Vim you can switch between the windows (or panes as they are called in tmux lingo) using a couple of key strokes.
There is another terminal multiplexer available called GNU screen, which is also quite popular. And the reason I mention that is because I like to have options, and also there are two plugins for Vim that allow you to send output directly to an attached screen or tmux session. For GNU screen, slime.vim, and for tmux, tslime.vim.
Using VIM and ConqueTerm you can use CTRL + W and UP / Down to change windows in split mode.
Just click on ESC first to exit the insert mode.
It works well on my side.

Annoyance when running scripts in Vim (Windows, Ruby)

I started using vim for my programming projects (mostly Ruby) and mostly everything works just as I want but I have a problem with compiling.
Lets say I am working on a Ruby script and I want to run it. I type :ruby sometging.rb (mapped to some other key). Then vim opens a new cmd.exe window and runs 'ruby something.rb'. Then it waits for me to press ENTER to close the window and continue working on the script.
Is there a way to configure vim on windows so that it always runs the script I'm working on in a separete window (always the same one, if none exists => open one), and not ask me to confirm with enter?
Don't know about gvim, but in normal vim you could put something like
map R <ESC>:tabnew<CR><ESC>:;%!ruby filename.rb<CR>
in your ~/.vimrc which would execute a Ruby file in a newtab when pressing R in command mode.
I've not used Ruby, but for I've found Dr Chip's RunView plugin really useful for running other interpreted languages.
Once it's installed, you can enter:
:RunView! <interpreter>
(where <interpreter> is presumably 'ruby' in your case) and it will open a (vertically if you include the !) split window with the output from passing the contents of the current window to the interpreter. Each time it is run, a new result log is appended to the end of the file (with a date and time stamp separating them).
If you have any issues with it, I'd recommend you contact Dr Chip via the Vim mailing list: he's very helpful (in fact he wrote the original version of RunView in response to a request I made on the mailing list).
This isn't exactly perfect but I use this to launch Python scripts.
command -nargs=* PY3 !start cmd /K Python.exe "%:p" <args>
It starts up a window that stays alive and doesn't interfere with my VIM window. Unfortunately it doesn't load it into an existing window.

Resources