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?
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.