I understand that this is super-old, but I came across the same thing in Vim 8.0 and Neovim. If I enter :tag mymethod!
from the vim command line, it will find the corresponding tag, but if I try <C-]>
with my pointer to the method name, these are errors E426: tag not found: mymethod
(note the absence !
in the name that he was looking for).
You can fix it by adding !
to the list of characters recognized as keywords in Ruby syntax:
:set iskeyword+=!
You can add this to ~/.vim/after/syntax/ruby.vim
to apply it to any Ruby file you open. I have not tested this, so I canโt say if it will affect anything else. I know that this will change the behavior of jumps. w
will, for example, consider !
as part of a "little" word.
On the other hand, it will certainly misunderstand things like !some_test
. If you press <C-]>
with the cursor somewhere there, it will look for a method called !some_test
, which is definitely not what you want. A better solution would be to write a wrapper function around the tag search for Ruby files. I'm actually working on something for this, so I will post when I have something presentable.
Update: I found a surprisingly simple way:
nnoremap <buffer><silent> <C-]> :tag <CR><CW><CR>
For some reason, the behavior of <CR><CW>
in command line mode is different from the behavior of expand('<cword>')
and possibly from the documentation. Even if !
is not a 'iskeyword'
, but expand('<cword>')
leads to mymethod
, <CR><CW>
leads to mymethod!
. Does the same apply to is_this_your_method?
. You can apply this workaround by putting the following in ~/.vim/ftplugin/ruby.vim
:
nnoremap <buffer><silent> <C-]> :tag <CR><CW><CR> nnoremap <buffer><silent> g] :tselect <CR><CW><CR> nnoremap <buffer><silent> g<C-]> :tjump <CR><CW><CR>
Update 2
It turns out that the special <CR><CW>
behavior was provided by vim-ruby (and is included by default in Vim files). This script sets up <CR><CW>
and also adds a <Plug><cword>
to correctly identify the Ruby cursor id. I just ran into abuse !
because I inadvertently sealed the mappings already provided by vim-ruby when I add what I find more convenient for keyboards:
nnoremap <C-.> <C-]>
If I did nmap
, then the vim-ruby conversion could do its job. Alternatively, you can use what vim-ruby provides (in the ruby โโftplugin file):
nnoremap <buffer><silent> <C-]> :<CU>exe v:count1."tag <Plug><cword>"<CR> nnoremap <buffer><silent> g] :<CU>tselect <Plug><cword><CR> nnoremap <buffer><silent> g<C-]> :<CU>tjump <Plug><cword><CR>