Tmux Part 4: Vim Integration

Hi @ticsucty, there is a section in the readme on restoring clear clear screen. It maps <prefix> C-l to clear screen. The same approach can be used for C-k.

Hi Chris ā€“ Iā€™ve read through these posts and Iā€™m having the same problem as others: VTR: no runner pane attached.

Not sure how late I am to the party. Is there general agreement on how to fix this so I can run RSpec tests within VIM using the plugins specified in this Trail?

Hello Hunt, could you provide a bit more detail? I would expect things to work assuming you use the plugins as described in the show notes for this video. Specifically, you can use the following:

Bundle 'thoughtbot/vim-rspec'

let g:rspec_command = "VtrSendCommandToRunner! rspec {spec}"

map <Leader>t :call RunNearestSpec()<CR>

Note the ! at the end of the command, there is also a version without a !. The ! version will open a runner pane if none is attached. If you want to manually open and position the runner pane, you can use :VtrAttachToPane.

1 Like

Worked like a charm. Thanks!!

Hi @christoomey Iā€™m wondering why all the part of my vim+tmux navigation works but in vim, it canā€™t go to the left pane in vim when I press ctrl-h, everything else works. How do I debug this?

Hi @christiansakai, Iā€™d suggest taking a look at the issues on the repo, particularly Problems with ctrl-h in neovim. Iā€™ve not experienced this directly, but other users have reported it and that issue is collecting details.

If youā€™re not in neovim, then Iā€™d wonder what the output of tmux list-keys | grep 'C-h' is for you.

@christoomey hi Chris, yeah that solution worked! thanks

@christoomey hi Chris. I am trying to use your Vim Tmux Runner, and bind Space-nr to fire up a runner pane with node js repl on it. However I notice that when I kill the runner pane using Space-kr and then firing up a shell runner with Space-or, the runner pane fires up with node repl. If I never use the Space-nr, it works just fine

Hi @christiansakai, sorry to hear about the trouble. I believe the issue is that VTR ā€œremembersā€ the last runner you used. You should be able to work around this by explicitly stating the runner you want to use, or lack there of:

nnoremap <leader>nr :VtrOpenRunner {'orientation': 'h', 'percentage': 50, 'cmd': 'node'}<cr>
nnoremap <leader>or :VtrOpenRunner {'orientation': 'v', 'percentage': 30, 'cmd': ''}<cr>

Note Youā€™ll want to modify the orientation and percentage arguments to your desired values (or remove them to use the defaults).

@christoomey I tried ur solution, and it works when I am inside a tmux session, and source the .vimrc, however as soon as I get out of tmux session, and then begin another session, it doesnā€™t work anymore and I have to source the .vimrc again for it to be fixed

Hi @christoomey, did you add the lines I provided to your vimrc? If so, they should load on startup and be available in all Vim sessions.

Hi all,

Anyone know of a way to close the runner pane on passing specs? Maybe with some delay, so I can see it passed and it closes automatically.

Or maybe just a way to close to the runner pane easily that I could add to my .vimrc?

@johnnadeau there is no built in way to have the runner pane close automatically on passing test. tpopeā€™s dispatch.vim and will use tmux panes as needed.

With tmux-runner you can use the :VtrKillRunner command, which is by default bound to <leader>kr to manually close after a successful test run. I use this personally when I want more space (or I zoom the tmux pane wrapping Vim).

Hope that helps!

1 Like

This behavior wasnā€™t on by default on me so I took a peek in vim-tmux-runner.vim

and added let g:VtrUseVtrMaps = 1 to my .vimrc

This let me use those bindings including <leader>fr to focus the runner pane.

Thanks and great work with that plugin!

Ahhh yes, good point. Youā€™re finding my gradual shift in opinions about good plugin design over time played out. Thanks for updating!

@christoomey Great video, I have a question, when I use the vim-tmux-navigator, it does solve the problem and can navigate me between tmux pane and vim window well. However, when I was trying to navigate in the search list from CtrlP in vim and meanwhile Iā€™ve opened another tmux pane. and doesnā€™t work, I was using silver searcher with CtrlP. Do you have any solution for this? Thanks :slight_smile:

hey @kenshinji, not quite sure what youā€™re asking. I use fzf.vim at this point, but I believe it functions largely the same as CtrlP. When I am in results window, I can use C-j etc to navigate to other panes. I use C-n and C-p to move up and down in the list. Does that cover what youā€™re asking about?

@kenshinji I had a similar problem when using CtrlP in vim within a tmux pane. I use C-j and C-k to move up and down the CtrlP search result. Running tmux in 256-color mode helped fixed the navigation problem I had.

Hey @EduardoBorsa, I think I can help out here.

There are a few different ways to have tmux-runner connect to a pane.

  1. Use :VtrOpenRunner to have tmux-runner open a pane & attach to it
  2. Use :VtrSendCommandToRunner! will open a pane if needed, and then run the provided command
  3. Use :VtrAttachToPane to connect to an existing pane you opened manually. (If there is only one other pane it will pick that one, otherwise it will flash the display-panes numbers and prompt for the desired pane).

Between those three you should have all your bases covered.

1 Like

Hi Chris,

Iā€™m able to run :call RunAllSpecs() but when I try to run the other commands I get the following error:

/Users/cborders/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `loadā€™: cannot load such file ā€“ /Users/cborders/turing/3module/projects/ideabox_redux/turing/3module/projects/ideabox_redux/spec/models/user_spec.rb (LoadError)

I have the runner in the project directory. Any ideas why I can only run all the specs at once?