I'm in a Ruby file, and because !
is not an iskeyword
character, if I place the cursor on a call to mymethod!
and attempt a tag lookup via C - ], Vim searches for mymethod
(without the !
). Adding !
to the iskeyword
option causes other problems, which I won't go into here.
Given the above behavior, I expected hitting C - RC - W from command-line mode would insert mymethod
on the command-line, but it actually inserts mymethod!
(including the !
). Running expand('<cword>')
, on the other hand, results in mymethod
.
What's going on here? The documentation describes C - RC - W, saying:
Insert the object under the cursor:
...CTRL-W the Word under the cursor
CTRL-A the WORD under the cursor; see WORD
and <cword>
:
<cword>
is replaced with the word under the cursor (like star)
This is actually helpful in my case, as it means I can get tag lookups working correctly by putting the following in my .vim/ftplugin/ruby.vim
:
nnoremap <buffer><silent> <C-]> :tag <C-R><C-W><CR>
But I'm curious where the nuanced behavior comes from and whether it's intentional, or whether it's likely to be fixed at some point, breaking my solution.
$VIMRUNTIME/ftplugin/ruby.vim
, which include a mapping of<C-R><C-W>
to<Plug><cword>
which is then mapped to a call toRubyCursorIdentifier()
. That function contains expressions more complicated than I wished to follow, but it probably sees the!
as belonging to the identifiermymethod
and adds it to the result of<C-R><C-W>
.