keys:vim: Fix display of search count on n & N

When 'lazyredraw' is set the search count is not displayed. This seems
like a bug as it is being displayed if `n` and `N` are not remapped.

Fix this by shortly turning off lazyredraw and resetting it after.

This leads to the new problem that hlsearch is not triggered. It does
stay though after searching with `/<CR>`, so this is a smaller issue I
can fix later.

Found thanks to: https://github.com/kevinhwang91/nvim-hlslens/issues/34
This commit is contained in:
2023-05-21 16:01:37 +02:00
parent 848df05810
commit 7065f4b043

View File

@@ -276,9 +276,21 @@ vnoremap < <gv
vnoremap = =gv
" Center search results while still respecting 'foldopen'
" TODO: this hides the search result indicator (i.e. [5/10])
noremap <expr> n 'n'. (match(&fdo, 'search') > -1 ? 'zv' : '') .'zz'
noremap <expr> N 'N'. (match(&fdo, 'search') > -1 ? 'zv' : '') .'zz'
" TODO: This does not trigger hlsearch
function! s:CenterNext(count, command)
let l:foldopen = match(&foldopen, 'search') > -1 ? 'zv' : ''
" Search count (i.e. [5/10]) will not display with 'lazyredraw'
let l:lazyredraw_bkp = &lazyredraw
set nolazyredraw
execute 'normal! ' .. a:count .. a:command .. l:foldopen .. 'zz'
let &lazyredraw = l:lazyredraw_bkp
endfunction
map n <Cmd>call <SID>CenterNext(v:count1, 'n')<CR>
map N <Cmd>call <SID>CenterNext(v:count1, 'N')<CR>
cnoremap <expr> <CR> "<CR>" .
\ (getcmdtype() == '/' \|\| getcmdtype() == '?'
\ ? (match(&fdo, 'search') > -1 ? 'zv' : '') . "zz"