Vim keyword completion for ctags with backslashes?

匿名 (未验证) 提交于 2019-12-03 09:05:37

问题:

I'm using ctags for keyword completion on a PHP project in vim. Since ctags doesn't handle PHP namespaces out of the box, I've added a regex option to my ctags command:

ctags (...) --regex-PHP='^namespace\s+([^;]*)/\1/c/' (...) 

This works fairly well: if I type Foo<Ctrl+N> I get suggestions for Foo, Foo\Bar, Foo\Bar\Baz and so on.

However, the backslash seems to count as a word separator when vim determines the keyword to look up in the tags file.

In other words, typing Foo\Ba<Ctrl+N> does not give me suggestions for Foo\Bar\Baz etc, which is what I wish. It will only suggest tags that actually start with Ba (i.e. none of my namespaces).

This is also an issue when jumping to a tag. If I have Foo\Bar\Baz under the cursor and do Ctrl+], it will take me to the file containing Baz, which may or may not be the one containing Foo\Bar\Baz. If the backslash wasn't treated as a word separator, I imagine this would work much better.

So, is there a way to make vim treat the backslash as a part of the word when doing tag lookups?

回答1:

In ~/.vim/after/ftplugin/php.vim (this makes the change local to PHP files), add the following:

:setlocal iskeyword+=\\ 

Note that this change also affects other stuff, e.g. the w motion, aw text object, and potentially even syntax highlighting.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!