Want to exactly matching current word with below function.
function! My_Exact_Search () let CurrentWord = expand("<cword>") exec "/\<".CurrentWord."\>" endfunction
But get error:
E486: Pattern not found: <word>.
How to fix it?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
* command does this natively.
The problem with your function is you need to escape your
/ or use literal-string (I recommend).
let @/ = '/\<'.CurrentWord.'\>'
You also should be using
:normal to create the search.
execute "normal! /\\<".expand('<cword>')."\\>\<cr>"
For more help see:
:h * :h literal-string :h quote/