In a terminal buffer, I want to auto-exit when I press "kk". Except for when I'm in some interactive session, like a pager (like the pager which is created when you git diff
).
To do that, I have this code
let g:_pager_bottom_texts = [":", "?", "/", "Pattern not found (press RETURN)", "(END)"]
function! MoveIfNotInPager()
let l:current_line = getline(".")
if index(g:_pager_bottom_texts, l:current_line) >= 0
normal i
call timer_start(0, {-> feedkeys("k")})
endif
endfunction
tnoremap kk <C-\><C-n>:call MoveIfNotInPager()<CR>
And it works moderately well, actually. I've noticed though that, in a pager, pressing k
is about 1/2 speed compared to j
when I'm in a terminal buffer. Can anyone recommend a better way which still gets what I'm looking for without causing terminal or pager experience to be slower?
<leader>k
instead ofkk
does the problem go away?kk
to anything (<leader>k
like you suggested,pp
, or literally anything). Now open a pager and observe how it's slower to scroll up than it is to scroll down withj
. I'm not really sure what exactly causes the slowness. But it's probably because thetimer_start
line isn't as efficient as it could be.