5

I'm using tmux and Vim as my development IDE. I have 3 panes open in tmux: one for editing source code, one for debugging and one as a display console.

From Vim I would like to run the make command and send all the build information emitted by it to the display console pane. How would I do that?

0

2 Answers 2

5

You can run any shell command from one pane and display its output in another pane with the run-shell command. For example:

tmux run-shell -t 2 "echo hello"

...and "hello" will be printed to pane number 2. You can see pane numbers with prefix + q.

From vim you should be able to do:

:!tmux run-shell -t 2 "make ..."

Add -b to run the command in the background.

Update: Addressing a couple things that @SLN brought up in this comment...

  • tmux puts the output pane into copy-mode, the same mode it is in when you do scrolling, so break out of it however you normally do (Ctrl+C is one way). Note: you'll know you're in this mode if you see something like [12/34] (i.e. page-num/total-pages) in the upper-right corner of the pane.
  • As for Vim requiring you to hit Enter (or Ctrl+L) after make or other command completes, this is just how Vim works with external commands (:!cmd). I'm not aware of any way to avoid this but I believe you can hit Enter before the command finishes and it will return as soon as it's done. (This might be system dependent.)

Update 2: I do know a workaround for the second item. If you use a mapping to run the external command you can embed an exit key. Here's an example where I'm just doing ls as my shell command:

nnoremap <leader>ls :!ls<CR><C-L>

From Normal mode I hit \ls and the ls command will run but then the console output will close and return me to vim right away. Perhaps you can adapt to this whatever your command is.

4
  • @B Layer, Seem working for me, but after I run the run-shell command the with the background in my vim, it still print some information to me, I have to tap Enter key to get back to vim, is this normal? Another issue is the run-shell command seems has frezzed my 2nd pane, how can I jump out the frezze mode? Thanks
    – SLN
    Jan 12, 2018 at 9:38
  • 1
    @SLN see my updated answer.
    – B Layer
    Jan 12, 2018 at 10:20
  • In case anyone needs it, the default pane numbers seem to start at 0 (not very surprising though). When running the above, -t 2 doesn't exist, so it would print "lost server" and fail. And if it matters, this is bash on Windows. I should have read the "prefix + q" part first though...
    – making3
    Nov 13, 2019 at 7:54
  • 1
    @making3 Okay, but I chose pane number 2 just as an example. (Still, you don't have more than 2 panes in any of your windows?) Anyways, try this: put setw -g pane-base-index 1 in your .tmux.conf file and pane numbering will start at 1.
    – B Layer
    Nov 13, 2019 at 8:52
0

You can touch a file in advance & tail -f file : it in one pane ... so inside vim launching the make with redirection of output to that file it will display your make session ....

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .