I have this alias to grep under the cursor (for the entire project):
" bind K to grep word under cursor nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR><ENTER>
How can I change this to only grep the contents of the currently opened file?
note: My grep is linked to the silver searcher like so:
if executable('ag') " Use ag over grep let &grepprg = "ag -w" endif
Update: How to avoid the hotkey window?
mas suggested I use fzf Blines command, which worked using this keyboard shortcut:
nnoremap L :BLines "\b<C-R><C-W>\b"<CR>
when I put the cursor on a word and type L, I get the results in a hotkey window like so:
However If I simply type the following into the command line
I have a much more pleasant window that appears in the middle of the screen
What is it in my keyboard shortcut that's preventing the middle screen window from appearing?
fzf.viminstalled, you can try
Blinesfrom the command mode.
*for searching a word under the cursor, I tried
:nnoremap * yiw:BLines <C-R><C-W><CR>and it works quite nicely. You don't have to remember a new command to search for a word under the cursor.
<C-R><C-W>for copying the word under the cursor in command notation? Why do you still have it in your command if you are already using
<C-r><C-w>pastes the contents of the register. First we have to yank the word under the cursor to the register via
yiwand then paste back the same for the query in the command mode. Hope that helps.