I want to send commands to tmux to run Elixir tests from vim. Using the % variable allows me to run the command to run a test for a single file. The relevant line in my .vimrc is

nmap <silent> <leader>ef :! tmux send -t 0.1 'mix test %:p' Enter<CR><c-L>

This sends, for example, mix test /path/to/spec.exs when I'm in a spec. That works for testing a single file.

Now I want to be able to run a single test. The command would have the format

mix test /path/to/test.exs:<lineno>, so the path, a colon, and the line number. I tried things like line(.), but I can't figure out how to interpolate that inside of a tmux send string.

1 Answer 1


Here's an example of inserting line number in a shell command:

:exe "!echo " . line(".")

So your mapping would be something like this:

nnoremap <silent> <leader>ef :exe "!tmux send -t 0.1 'mix test %:p:" . line(".") . "' Enter"<CR><C-L>

I run tmux so I was able to test that the command appeared in a tmux pane (though I can't actually verify the command since I don't have 'mix').

  • 1
    Turns out I was using the wrong concatenation operator. Also, <c-L> clears the output of the shell exit code so vim doesn't switch to the output. Thanks. Commented Oct 16, 2017 at 15:11
  • 1
    Oh, so it does. That's handy. I'll add it back. Cheers.
    – B Layer
    Commented Oct 16, 2017 at 17:18

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.