I'm a big user of Vim's ctags ctrl-] shortcut. I recently made a tag file in which the primary language is Make. When I try to ctrl-] with my cursor over a variable with a hyphen (ex. dl-routines), I get an error. If my cursor is over 'dl' within the 'dl-routines' variable I get the error
tag not found: dl
If my cursor is over 'routines' within the 'dl-routines' variable I get the error
tag not found: routines
I'm aware of Vim's
:ta tagname
However I'd like to use ctrl-] as it gives me less room for error.
In this case it's probably worth altering 'iskeyword' option to include dash. It may have many other effects, but they all should be quite useful. The only trick is to make these changes locally:
autocmd FileType make setlocal iskeyword+=45
Setting 'iskeyword' option locally is probably the simplest solution. As an addendum to @Matt's answer, if you want to keep your option clean and add 45 only when you press <C-]>, you could use this trick function.
function! CWordWithKey(key) abort
let s:saved_iskeyword = &iskeyword
let s:saved_updatetime = &updatetime
if &updatetime > 200 | let &updatetime = 200 | endif
augroup CWordWithKeyAuGroup
autocmd CursorHold,CursorHoldI <buffer>
\ let &updatetime = s:saved_updatetime |
\ let &iskeyword = s:saved_iskeyword |
\ autocmd! CWordWithKeyAuGroup
augroup END
execute 'set iskeyword+='.a:key
return expand('<cword>')
endfunction
which adds the parameter key to iskeyword and sets a self-destructing autocmd to restore your older iskeyword after 200 ms.
Than remap <C-]> in ftplugin/make.vim or with autocmd FileType make ... as the previous answer.
nnoremap <buffer> <silent> <C-]> :execute 'tag '.CWordWithKey(45)<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