I would like to map <Leader>a
to search with ag
the word under the cursor
I wrote this:
noremap <Leader>a :Ag!<C-u><C-r>=Escape(expand('<cword>'))<CR>
function! Escape(stuff)
return substitute(escape(a:stuff, '\/.*$^~[]'), "\n", '\\n', "g")
endfunction
Unfortunately when I hit <Leader>a
on the word foo
I get this:
:foo
The Ag!
vanished and the trailing <CR>
was not executed.
Where is my mistake?
Press e (“end”) to move the cursor to the last character of the current word.
you added <c-u>
in your mapping, it will remove :Ag!
You may want to use -Q
for ag
to do a literal search.
For the <CR>
problem, your <CR>
is for the <c-r>=
expression, you need one extra <CR>
to launch the command.
noremap <leader>a :Ag! "<cword>"<cr>
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