I have this shorcut in my vimrc that I use all the time (admittedly, I just copied it over from the web):
" bind K to grep word under cursor
nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
This works excellent, it displays the matched keywards in the window below in my vim session:
This is great, but I would like to create another keyboard shortcut that only searches for the keyword under the cursor for the current file only.
I searched how to do that online and found this command:
:vim /pattern/ % | cw
This works fine if I type it out manually on vim, but I'm trying to create a keyboard shortcut for it using this tutorial:
" bind L to grep word under cursor for current file only
nnoremap L :vim <C-R><C-W>% |<CR>:cw<CR>
This isn't working, it's giving me a syntax error. My question is: how can I add the %
option to the above vim command to the keyboard map?