ctags 无法找到包含连字符的变量

ctags unable to find variables that contain hyphen

我是 Vim 的 ctags ctrl-] 快捷方式的忠实用户。我最近制作了一个主要语言为 Make 的标记文件。当我尝试将光标放在带连字符的变量上时按 ctrl-](例如 dl-routines),出现错误。如果我的光标在 'dl-routines' 变量内的 'dl' 上方,我会得到错误

tag not found: dl

如果我的光标在 'dl-routines' 变量内的 'routines' 上方,我会收到错误消息

tag not found: routines

我知道Vim的

:ta tagname

但是我想使用 ctrl-],因为它可以减少出错的空间。

在这种情况下,可能值得更改 'iskeyword' 选项以包含破折号。它可能还有许多其他效果,但它们都应该非常有用。唯一的技巧是在本地进行这些更改:

autocmd FileType make setlocal iskeyword+=45

在本地设置 'iskeyword' 选项可能是最简单的解决方案。作为@Matt 答案的补充,如果你想保持你的选项干净并在你按下 <C-]> 时添加 45 ,你可以使用这个技巧功能。

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

将参数 key 添加到 iskeyword 并设置自毁自动命令以在 200 毫秒后恢复旧的 iskeyword

比在 ftplugin/make.vim 中重新映射 <C-]> 或使用 autocmd FileType make ... 作为上一个答案。

nnoremap <buffer> <silent> <C-]> :execute 'tag '.CWordWithKey(45)<CR>