From 7065f4b043eea6270940f8711037b85588ecf0b8 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Sun, 21 May 2023 16:01:37 +0200 Subject: [PATCH] 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 `/`, so this is a smaller issue I can fix later. Found thanks to: https://github.com/kevinhwang91/nvim-hlslens/issues/34 --- .config/vim/vimrc.d/40-keys.vim | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.config/vim/vimrc.d/40-keys.vim b/.config/vim/vimrc.d/40-keys.vim index 5828c1e..f439269 100644 --- a/.config/vim/vimrc.d/40-keys.vim +++ b/.config/vim/vimrc.d/40-keys.vim @@ -276,9 +276,21 @@ vnoremap < n 'n'. (match(&fdo, 'search') > -1 ? 'zv' : '') .'zz' -noremap 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 call CenterNext(v:count1, 'n') +map N call CenterNext(v:count1, 'N') + cnoremap "" . \ (getcmdtype() == '/' \|\| getcmdtype() == '?' \ ? (match(&fdo, 'search') > -1 ? 'zv' : '') . "zz"