1

Ok, so I run vim inside of tmux and recently (today in fact) I suddenly can't use ctrl+hjkl to switch between panes in tmux and vim, instead it just makes the bell sound and refuses to switch.

If I select the tmux pane with the mouse I can switch back to the vim pane using ctrl+hjkl but again can't switch back out unless I use my mouse ( I know, I know).

The problem only occurs in the pane that has vim loaded in it.

In my tmux.conf I have:

# smart pane switching with awareness of vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"

and I have the following keybindings set in my vim config:

so ~/.vim/config/key_codes.vim

" Buffer switching
nnoremap <S-l> :bnext<CR>
nnoremap <S-h> :bprev<CR>

" \d delete buffer
nnoremap <S-x> :Kwbd<CR> 

"tagbar toggling
map <F8> :TagbarToggle<CR> 
map <F7> :NERDTreeToggle<CR>

" Increment numbers
nnoremap <A-a> <C-a>
nnoremap <A-x> <C-x>

nmap <C-W>! <Plug>Kwbd

nmap <C-p> :CommandT<CR>

map <Leader>c :call vroom#RunTestFile()<CR>
map <Leader>s :call vroom#RunNearestTest()<CR>
" \t to jump to test file
map <leader>t :A<CR>
" \t to jump to related file
map <leader>r :r<cr>
" \E to open file explorer in root
map <leader>E :Explore .<cr>
" \e to open file explorer in current dir
map <leader>e :Explore<cr>

"nerd tree mapings
" map <C-n> <plug>NERDTreeFocusToggle<CR>

" shift plus arrow for selection mode
" shift+arrow selection
map  <Del> <Esc>x1i
vmap  <Del> <Esc>x1v

"multi-cursor mappings"
let g:multi_cursor_next_key='<C-n>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'

" Removing escape
ino jj <esc>
cno jj <c-c>
vno v <esc>

" Remove highlights with leader + enter
nmap <Leader><CR> :nohlsearch<cr>

" Ruby hash syntax conversion
nnoremap <F12> :%s/:\([^ ]*\)\(\s*\)=>/\1:/g<return>

" bind K to grep word under cursor
vmap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>

key_codes.vim:

function Allmap(mapping)
  execute 'map' a:mapping
  execute 'map!' a:mapping
endfunction


call Allmap('   <ESC>[A         <Up>')
call Allmap('   <ESC>[B         <Down>')
call Allmap('   <ESC>[C         <Right>')
call Allmap('   <ESC>[D         <Left>')
call Allmap('   <ESC>[F         <End>')
call Allmap('   <ESC>[H         <Home>')
call Allmap('   <ESC>[5~        <PageUp>')
call Allmap('   <ESC>[6~        <PageDown>')
call Allmap('   <ESC>[k4~       <C-Left>')
call Allmap('   <ESC>[5D        <C-Left>')
call Allmap('   <ESC>Od         <C-Left>')
call Allmap('   <ESC>[k6~       <C-Right>')
call Allmap('   <ESC>[5C        <C-Right>')
call Allmap('   <ESC>Oc         <C-Right>')
call Allmap('   <ESC>[1;2       <S>')
call Allmap('   <ESC>[1;2A      <S-Up>')
call Allmap('   <ESC>[1;2B      <S-Down>')
call Allmap('   <ESC>[1;2C      <S-Right>')
call Allmap('   <ESC>[1;2D      <S-Left>')
call Allmap('   <ESC>[1;2d      <S-d>')
call Allmap('   <ESC>[1;2x      <S-x>')
call Allmap('   <ESC>[1;2s      <S-s>')
call Allmap('   <ESC>[3~        <Del>')
call Allmap('   <ESC>[1;2h       <S-h>')
call Allmap('   <ESC>[1;2l       <S-l>')

and becuase it might be important my dotfiles.

EDIT: Holding ctrl and pressing h makes my cursor move left and doing the same but with l cuases my cursor to blink into Nerdtree and then it immediately blinks back to the main text buffer.

The same thing happens with j and k except it moves the cursor down and refuses to switch upwards.

1 Answer 1

0

Ok, so On recommendation from someone else I installed a plugin called vim-tmux-navigator like so:

Bundle "tmux-plugins/vim-tmux"

and It fixed my problem, whilst I'm not happy that I had to install a plugin to get back the functionality that I had before it stopped working, at least it's working now, on the brightside, I didn't have to alter my tmux-conf as what I already had was good enough.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .