behave test language need to execute different lines of the behave feature file, for example, if I want to test the line number 99, I'll need to input the following line in the terminal

behave features/target.feature:99 -k

Currently I'm using Tmux and vim as my IDE. I have 2 tmux panes and A and B, vim editor is opened in pane A (as the editing/developing environment). pane B is simply a terminal used as the running the test

What I want' to achieve is: Get the current cursor-marked line number in the file open by vim in pane A(ex. 99) and send this line information to create a shell command: behave features/target.feature:99 -k and send this command to Tmux pane B to excut

So far I've tried

let runLine = line('.')
"autocmd FileType text nnoremap <space>r !sh -xc 'behave features/navmemory.feature:&runLine -k'

But the part for sending it to pane B and execute is missing and I don't know how can I do it

  • There are a number of vim plugins that specialize in sending commands to tmux; alternatively, your mapping can call a function that grabs the line number and runs tmux commands. Use that as a starting point to solve your problem
    – D. Ben Knoble
    Sep 5, 2018 at 18:40

3 Answers 3


To send to another pane you'll need to call tmux from Vim. Specifically, you'll need the send-keys command (alias: send). For example, this will cause the current line number in Vim to be printed to the terminal in pane 2 using echo:

:exe "!tmux send -t 2 'echo " . line(".") . "' Enter"

Applying the same form to your command:

:exe "!tmux send -t 2 'behave features/target.feature:" . line(".") . " -k' Enter"

A few notes on -t:

  • The -t flag, in its simplest form, takes the target pane index as argument.
  • Since you are sending your command to another pane in the same window that's the only form we need to know.
  • You can display pane indexes in the current window with tmux-prefix + q.

FYI, that spelled-out Enter at the end of the command tells tmux to emit an actual carriage return at that point...submitting the command to the shell for execution, in these examples.

If you want to put this in a mapping the RHS is simply the full command from above followed by <CR>. So...

:MAPCMD LHS :exe "!tmux send -t 2 'behave features/target.feature:" . line(".") . " -k' Enter"<CR>

(I like to follow the <CR> with <C-L> to eliminate the need to hit Enter when the command is done.)

Update - What if the pane was moved?

@JDG asked, How [do I send] a command to a particular pane, despite the fact that the pane may have changed position and thus has a different index? It's a good question so I'm relocating my reply here...

I would suggest you use the pane ID rather than the index.

Every tmux pane is assigned both an "index" and an "ID". The former can change if the pane is moved but the latter is fixed for the life of the pane. In addition to accepting an index, -t also accepts an ID. You just need to prepend % to indicate this. Example: tmux send -t %8 .... Consult man tmux to learn how to get a pane's ID.

  • how would i write a script that sends a command to a particular pane, despite the fact that the pane may have changed position (and thus has a different index)?
    – JDG
    Dec 30, 2022 at 2:16

Uploaded my personal config tvp-repl

Copy from one pane with Ctrl+c and paste to another (requires xclip)
vim with +clipboard, .vimrc:

set clipboard=unnamedplus
vnoremap <C-c> "+y

tmux bindings to dump the clipboard .tmux.conf:

bind-key Enter run "tmux send-keys -t 0 C-c" \; 
run "tmux select-pane -t 1" \; 
run "tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer" \; 
run "tmux send-keys -t 1 Enter" \; 
run "tmux select-pane -t 0"


  • Enter in tmux will send CTRL+C to Pane 0 (vim).
    We bind CTRL+C in vim, to copy to the system clipboard.
  • We select Pane 1, where we want to paste the content.
  • Next the system clipboard will be extracted with xclip to the tmux buffer and immediately paste the buffer into the current selection (Pane 1).
  • Lastly, we send Enter and jump back to Pane 0 (vim).

The .tmux.conf is pretty human-readable. I personally call tmux with vim in 0 and ipython in 1 and prefer to keep it hard-coded. Alternatively, you could use run "tmux last-pane" to jump between the next and previous pane.

  • It would be nice if you edited to explain how to use this better—I understand you say <C-c> to copy from one pane, but you only bind it for vim (so I'm not sure how you could do that in any tmux pane), and you don't mention the paste binding or how it works. Having glanced at that code, it appears it also won't work if you're not interested in exactly panes 0 and 1...
    – D. Ben Knoble
    Mar 3, 2020 at 15:36
  • @D.BenKnoble added the explanation. You are correct, that the solution is rather static w.r.t. the panes. My goal is to not remember another plugin such as vimux, which could be an alternative you want more flexibility. Probably you could also run CTRL+b q to display the pane numbering and select the target pane, which would introduce another keystroke.
    – dariohett
    Mar 5, 2020 at 23:52

VimSlime is a vim plugin that does exactly what you are looking for. You can check out a demo for it here.

  • I'll give it a try
    – SLN
    Oct 26, 2020 at 22:24
  • loved, just what I was seeking for!
    – Math
    May 31, 2021 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.