Have terminal emulator send Vim's <leader>i for <C-i>
dblume

dblume commited on 2024-04-30 07:39:20
Showing 2 changed files, with 14 additions and 9 deletions.


Getting consistent behavior in and out of tmux has been a challenge.

In order to keep C-i/C-o jumps and remap Tab/S-Tab for buffers, I'm
having the terminal remap C-i to <leader>i for vim.

This'll bite me when I use another CLI that needs C-i.

* Use Windows Terminal instead of Windows Console Host
* Use Alacritty instead of Gnome-Console.

Investigations:

* Do C-i remapping in tmux config, but that affects Tab.
* No solution for PuTTY yet.
... ...
@@ -39,15 +39,16 @@ nnoremap <C-l> <C-w>l
39 39
 " clear search highlights
40 40
 nnoremap <cr> :noh<cr><cr>
41 41
 
42
-" tmux in Alacritty doesn't send C-i, so I have Alacritty map C-i to <leader>i
42
+" tmux 3.2+ doesn't send C-i, so have Alacritty iTerm2 map C-i to <leader>i
43
+" iTerm2: Settings > Keys > Key Bindings > + > Shortcut:^i Action:Send Text "\i"
43 44
 nnoremap <leader>i <C-i>
44
-" Use (Shift-)Tab to switch buffers if Tab different than C-i (usually not in tmux).
45
+" Use (Shift-)Tab to navigate buffers, retain C-i/C-o for jumps.
45 46
 " Test with this:
46 47
 " nvim -Nu NONE +'nno <C-i> :echom "C-i pressed"<cr>' +'nno <tab> :echom "Tab pressed"<cr>'
47
-if stridx(expand($TERM), 'xterm') == 0
48
+"if stridx(expand($TERM), 'xterm') == 0
48 49
   nnoremap <C-i> <C-i>
49 50
   nmap <Tab> :bn<cr>
50
-endif
51
+"endif
51 52
 nnoremap <S-Tab> :bp<cr>
52 53
 
53 54
 set t_Co=256
... ...
@@ -48,12 +48,16 @@ nnoremap <C-l> <C-w>l
48 48
 " clear search highlights
49 49
 nnoremap <cr> :noh<cr><cr>
50 50
 
51
-" Shift-Tab switches to prev buffer
52
-" (Not remapping Tab because Ctrl-i in use as 'go to next jump pos')
51
+" tmux 3.2+ doesn't send C-i, so have Alacritty iTerm2 map C-i to <leader>i
52
+" iTerm2: Settings > Keys > Key Bindings > + > Shortcut:^i Action:Send Text "\i"
53
+nnoremap <leader>i <C-i>
54
+" Use (Shift-)Tab to navigate buffers, retain C-i/C-o for jumps.
53 55
 " Test with this:
54
-" vim -Nu NONE +'nno <C-i> :echom "C-i pressed"<cr>' +'nno <tab> :echom "Tab pressed"<cr>'
55
-""nnoremap <C-i> <C-i>
56
-""nmap <Tab> :bn<cr>
56
+" nvim -Nu NONE +'nno <C-i> :echom "C-i pressed"<cr>' +'nno <tab> :echom "Tab pressed"<cr>'
57
+"if stridx(expand($TERM), 'xterm') == 0
58
+  nnoremap <C-i> <C-i>
59
+  nmap <Tab> :bn<cr>
60
+"endif
57 61
 nnoremap <S-Tab> :bp<cr>
58 62
 
59 63
 " Use yy to yank a whole line, use Y to yank to end of line like C and D
60 64