In Vim I can switch between tab pages with :tabnext-
to go left and tabnext+
to go right, simulating the tabs on an IDE. In Tmux I can switch between windows using <prefix>p
and <prefix>n
respectively. I'd like to combine these functions:
I'm trying to remap the Altleft and Altright keys to switch between tab pages in Vim and session windows (which are like tabs) in Tmux when Tmux is available.
Example
https://www.codeography.com/2014/06/19/navigating-vim-and-tmux-splits The plugin 'Vim-Tmux-Navigator' provides a way to seamlessly navigate between Tmux and Vim panes via for left and right and and for up and down. (It looks like when the window number in Vim is maxed it just sends the key commands to Tmux so that there's no need for me to think about which pane in which window I want to switch to.) I'm trying to do the same thing but for switching between Vim Tab pages (created via :tabnew) and Tmux Windows (created via c) (not buffers/windows in Vim or panes in Tmux but tab pages vs Windows).
What I've tried
In ~/.vimrc I have:
if exists('$TMUX')
function! TmuxOrTabSwitch(tabcmd, tmuxdir)
let previous_winnr = tabpagenr()
silent! execute "tabnext " . a:tabcmd
if previous_winnr == tabpagenr()
call system("tmux select-window -t " . a:tmuxdir)
redraw!
endif
endfunction
let previous_title = substitute(system("tmux display-message -p '#{pane_title}'"), '\n', '', '')
let &t_ti = "\<Esc>]2;vim\<Esc>\\" . &t_ti
let &t_te = "\<Esc>]2;". previous_title . "\<Esc>\\" . &t_te
nnoremap <silent> <A-Left> :call TmuxOrTabSwitch('-', '-')<cr>
nnoremap <silent> <A-Right> :call TmuxOrTabSwitch('+', '+')<cr>
else
noremap <A-Left> :tabprevious<Cr>
noremap <A-Right> :tabnext<Cr>
endif
In ~/.tmux.conf I have:
# Move Window left and right
bind -n M-Left run "(tmux display-message -p '#{pane_title}' | grep -iq vim && tmux send-keys M-Left) || tmux select-window -t -"
bind -n M-Right run "(tmux display-message -p '#{pane_title}' | grep -iq vim && tmux send-keys M-Right) || tmux select-window -t +"
Unfortunately, this doesn't work! How can I get this to work the way I described above? Any help would be appreciated.
tmux source-file ~/.tmux.conf
– selmansamet Jun 4 at 17:14