I can't find info in help about whether it should or shouldn't turn on highlighting, but I find it strange that I have to press n or N after * or # to turn on search highlighting.

How do I enable this in vim if that's 'normal' behaviour.

I've got only these lines in my vimrc related to search highlighting.

if !has('nvim')
    set smartcase
    set hlsearch      " highlight search terms
    set incsearch     " show search matches as you type
  • 3
    This is the default behavior for hlsearch. Try starting vim with vim -u NONE, then put :set hlsearch and see if the behavior is unchanged.
    – Tumbler41
    Jun 3, 2016 at 20:06

1 Answer 1


You can hook up the hlsearch command like so:

nnoremap * :set hlsearch<CR>*
nnoremap # :set hlsearch<CR>#

And if you want to highlight the current word without moving the cursor you can add the N movement afterwards:

nnoremap * :set hlsearch<CR>*N
nnoremap # :set hlsearch<CR>#N
  • Thanks for you help. Do you have any idea what the logic behind vim default behaviour? Jun 4, 2016 at 22:26

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.