I have this script to search for the word under cursor in the current project:
nnoremap <leader>K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
It works just fine except when the word starts with b.
This is due to <C-R><C-W> only completing the remaining of the word. For example, if I'm searching for "branch", my pattern gets something like this:
\branch\b
Which is equivalent to search for the work "ranch".
Any thoughts on how to figure this out?
Try this: nnoremap <leader>K :execute 'grep! "\b"'.expand("<cword>").'"\b"'<CR>:cw<CR>.
<cword> will expand to the current word under the cursor, as :help :<cword> explains, along with others:
<cword> is replaced with the word under the cursor (like |star|)
<cWORD> is replaced with the WORD under the cursor (see |WORD|)
<cfile> is replaced with the path name under the cursor (like what|gf| uses)
Check the help for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With