← Back to Upcase

Tmux Part 4: Vim Integration


(Chris Toomey) #43

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.


(Hunt Norment) #44

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?


(Chris Toomey) #45

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.


(Hunt Norment) #46

Worked like a charm. Thanks!!


(Christian Sakai) #47

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?


(Chris Toomey) #48

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.


(Christian Sakai) #49

@christoomey hi Chris, yeah that solution worked! thanks


(Christian Sakai) #50

@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


(Chris Toomey) #51

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


(Christian Sakai) #52

@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


(Chris Toomey) #53

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.


(John Nadeau) #54

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?


(Chris Toomey) #55

@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!


(John Nadeau) #56

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!


(Chris Toomey) #57

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


(kenshinji) #58

@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:


(Chris Toomey) #59

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?


(Eric Ti-Yu Chiang) #60

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


(Chris Toomey) #62

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.


(Cody Borders) #63

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?