Ag.vim: Use word under the cursor as *part* of a search pattern?

search, vim

Solution

I usually use one trick, just press `*` on you current word and then use `:AgFromSearch`, you could specify concrete path e.g `:AgFromSearch /any/path/`

If you really want to do word as part of your search pattern, you can use `<cword>` (current word)

 nmap  <silent> <D-f> :Ag "def <cword>" /any/path/<CR>   

Problem

Using the Ag.vim plugin you can easily search for the word under the cursor by calling `:Ag` without any arguments, but how can I include the word under the cursor as part of a search pattern? I'm trying to add a bit to my vimrc to search for method definitions in Ruby files. Something like: ``` autocmd FileType ruby noremap K :Ag! "\bdef <C-R><C-W>\b"<CR> ``` It doesn't recognize the `<C-R><C-W>`. Also, I've tried both `\b` and `\<`, `\>` as word boundaries. Ag uses `\b` outside the context of Vim, but I know it translates `\<` and `\>` to `\b` in some contexts (not sure about this context though).

Original source