/\< matches beginning of all words as expected.

/\<a matches beginning of all words starting with a

but /\<# doesn't match words starting with #

what am I missing here?

Was planning on using this search pattern to navigate sections in a markdown document.

  • 1
    See :help /\< and look at the mention of 'iskeyword'
    – D. Ben Knoble
    Jul 19, 2022 at 15:00

2 Answers 2


As mentioned by @Ben the problem you have is that '#' is probably not in iskeyword and the # is not a word boundary.

You can fake it:


or if you would like to avoid the \v magic flag:



  • (^|\s) match either the beginning of the line
  • ^ or a space (e.g. ' ' or <tab>)
  • \zs set the beginning of the match
  • # match #

The problem was that the /\< pattern then uses the iskeyword option.

solved the issue by automatically adding # to iskeyword automatically on opening markdown documents, by adding this to my vimrc:

autocmd BufNewFile,BufRead *.md setlocal iskeyword+=#

see also this reddit post: https://www.reddit.com/r/vim/comments/w2uco4/vim_wont_match_beginning_of_word_followed_by/

  • You probably want to use put setlocal iskeyword+=# in ~/.vim/after/ftplugin/markdown.vim (or your neovim equivalent).
    – D. Ben Knoble
    Jul 19, 2022 at 18:50

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.