0

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.

2
  • 1
    It is probably the result of the mappings in $VIMRUNTIME/ftplugin/ruby.vim, which include a mapping of <C-R><C-W> to <Plug><cword> which is then mapped to a call to RubyCursorIdentifier(). That function contains expressions more complicated than I wished to follow, but it probably sees the ! as belonging to the identifier mymethod and adds it to the result of <C-R><C-W>.
    – garyjohn
    Commented Jul 26, 2017 at 14:30
  • @garyjohn Wow, good find. It's definitely in there. If you want to submit this as an answer I'll accept it.
    – ivan
    Commented Jul 26, 2017 at 19:44

1 Answer 1

1

It is probably the result of the mappings in $VIMRUNTIME/ftplugin/ruby.vim, which include a mapping of <C-R><C-W> to <Plug><cword> which is then mapped to a call to RubyCursorIdentifier(). That function contains expressions more complicated than I wished to follow, but it probably sees the ! as belonging to the identifier mymethod and adds it to the result of <C-R><C-W>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.