Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to open file in another pane in Tmux

I'm new to tmux, and split a window into 3 panes, left half(main pane), top-right quarter and bottom-right quarter. Is it possible that I use command to open an editable file in the left main pane, say vim myFile.py, and myFile.py will open in another pane, say top-right pane, such that I can always edit file in the top-right pane and keep input commands int eh left main pane?

like image 600
Emerson Xu Avatar asked Sep 03 '25 06:09

Emerson Xu


1 Answers

This is possible to do using features of vim, but it has nothing to do with tmux specifically. If the version of vim you are using was compiled with the +clientserver option, then there is a way to do this. To check, run :version in vim, and look for +clientserver. The client server capabilities of vim depend on X11, so if you don't see it, installing gvim might help. See https://unix.stackexchange.com/a/23601 for more information on the X11 dependency.

Now on to how to use it. First, set up your tmux panes however you want. In the pane that you would like to be the dedicated editor, the following command will create a vim "server."

vim --servername tmuxEditor

Now from another pane, you can run

vim --servername tmuxEditor --remote files...

and the editor will open the specified file(s). Other useful commands are

vim --servername tmuxEditor --remote-tab files...
vim --servername tmuxEditor --remote-send keys

The first opens the specified file(s) in separate tabs, and the second sends the specified key sequence to the server.

See http://vimdoc.sourceforge.net/htmldoc/remote.html or run :help remote in vim for more information on vim's client server features.

like image 97
dpk2442 Avatar answered Sep 04 '25 23:09

dpk2442