Vim Tips Wiki
Register
Advertisement
Tip 1665 Printable Monobook Previous Next

created August 16, 2010 · complexity basic · author Elementalvoid · version 7.0


More explaining please!

While the scripts in this tip may be very useful, nobody who isn't familiar with the subject matter will know what they do or why. This tip may need:

  • a problem statement explaining—in layman's terms—what the problem is that is solved by this tip
  • a "do it yourself" example showing how to do it manually without a complicated script, and telling why this may not be sufficient
  • explanations of how the script works at a basic level
  • comments in the script itself for the complicated bits

This tip was inspired by a tip on using bash completion with ctags.

This implementation is significantly simpler but gets the basic job done. The only downside that I see is that it does not work in concert with the other Vim completions for zsh. For example, if you type 'vim -o somefile.sh -t' then press the Tab key, it will not provide completions. It must be 'vim -t' then Tab to work.

Completing ctags with ZSH[]

Add the following to your ~/.zshrc file:

#vim tags
function _get_tags {
  [ -f ./tags ] || return
  local cur
  read -l cur
  echo $(echo $(awk -v ORS=" "  "/^${cur}/ { print \$1 }" tags))
}
compctl -x 'C[-1,-t]' -K _get_tags -- vim
#end vim tags

Then start a new shell or source your rc file:

source ~/.zshrc

What it does[]

Once you start a new shell or source your rc file, you can do

~$ vim -t MyC<tab key>

and it will auto-complete the tag the same way it does for files and directories:

MyClass MyClassFactory
~$ vim -t MyC

I find this really useful when I'm jumping into a quick bug fix.

See also[]

Comments[]

  • Cool! How would I do this using the new compsys (compdef?) instead of the old compctl?
  • It didn't work for me. The problem was that "$cur" was being populated with "vim -t", which most likely would not match anything in the tags file. I used the following,
#vim tags
function _get_tags {
  [ -f ./tags ] || return
  local cur
  read -l cur
  cur=`echo $cur | grep -o -- "-t[[:space:]]\+[[:alnum:]]\+" | cut -d' ' -f2`
  reply=(${=$(cat ./tags | grep "^${cur}" | cut -f1)})
}
compctl -x 'C[-1,-t]' -K _get_tags -- vim
#end vim tag
Advertisement