When Tab distinguished from C-i, map it Buffer Next
dblume

dblume commited on 2024-04-24 12:47:02
Showing 1 changed files, with 7 additions and 2 deletions.


When in 'xterm' it seems like Neovim can distinguish between Tab and
Ctrl-i. But when in 'tmux' it can't. We always want to preserve
the C-i/C-o jump pairs, so only map Tab to :bn if it's different.

References:
https://vi.stackexchange.com/questions/16161/how-to-map-c-i-separate-from-tab/23344#23344
https://www.reddit.com/r/tmux/comments/114kzoo/tmux_cant_tell_ci_and_tab_apart/
https://github.com/tmux/tmux/issues/2705
... ...
@@ -38,8 +38,13 @@ nnoremap <C-l> <C-w>l
38 38
 " clear search highlights
39 39
 nnoremap <cr> :noh<cr><cr>
40 40
 
41
-" Shift-Tab switches to prev buffer
42
-" (Not remapping Tab because Ctrl-i in use as 'go to next jump pos')
41
+" Use (Shift-)Tab to switch buffers if Tab different than C-i (usually not in tmux).
42
+" Test with this:
43
+" nvim -Nu NONE +'nno <C-i> :echom "C-i pressed"<cr>' +'nno <tab> :echom "Tab pressed"<cr>'
44
+if stridx(expand($TERM), 'xterm') == 0
45
+  nnoremap <C-i> <C-i>
46
+  nnoremap <Tab> :bn<cr>
47
+endif
43 48
 nnoremap <S-Tab> :bp<cr>
44 49
 
45 50
 set t_Co=256
46 51