Running Neovim 0.9, I have this mapping:

nnoremap <silent> <leader>l :<c-u>let @/ = '\<'.expand('<cword>').'\>'\|set hlsearch<CR>wb

which is a shortcut to highlight search the whole word under cursor. The problem is that it doesn't display the matched pattern count (the e.g. [5/20] count at the bottom right of the window). How can I trigger this mapping to also display the count? Or how can I implement a different mapping that highlights the current word under cursor without causing the screen to jump (e.g. not with * or #)

1 Answer 1



set shortmess-=S

If 'S' is present you won't get this message, but I suggest using :normal instead of let @/ = to achieve what you want instead of setting the register, which I tested it will not trigger the message.

:nnoremap <leader>l :set hlsearch<CR>/<C-R>=expand('<cword>')<CR><CR>

Add the ^M-character (CR, carriage return) by pressing CTRL+V+Enter, it will not work if you simply type ^M caret-m.

Also check out https://github.com/obcat/vim-hitspop I think its a good fit for a popup, since normally this message is limited to 99 matches.

  • 1
    Your use of expand in the middle of the :normal / doesn’t look quite right. FWIW I would write nnoremap <leader>l * or nnoremap <leader>l /\<<C-r><C-w>\><Enter>
    – D. Ben Knoble
    Feb 7, 2023 at 13:06
  • Thanks for catching.
    – dza
    Feb 7, 2023 at 16:24
  • 1
    @D.BenKnoble the macros you provided cause the screen to jump if there are other occurrences of the word, which I'm trying to avoid. Feb 7, 2023 at 23:39
  • @reject-cookies tried to put this in place of setting let @/ ?
    – dza
    Feb 8, 2023 at 0:45
  • @dza I tried this but it doesn't do anything nnoremap <silent> <leader>l :<c-u>:normal /expand('<cword>')/^M:set hlsearch<CR>wb Feb 8, 2023 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.