3

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 '18 at 18:40
5

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.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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