lyuts / vim-rtags

Vim bindings for rtags, llvm/clang based c++ code indexer.
BSD 2-Clause "Simplified" License
282 stars 56 forks source link

Open tag from command line? #78

Open Muzer opened 7 years ago

Muzer commented 7 years ago

With the built-in ctags support, I can type vim -t someTag to find some tag. Is there some way to have something similar for this project? I'm afraid I know very little about vim plugins so perhaps this is impossible.

pdavydov108 commented 7 years ago

@Muzer I have a command that does this in my .zshrc. Unfortunately, it's slow, so I dont use it much even for medium projects. Maybe it's possible to cache the results somehow or hack the rc tool to make it faster. Anyway, here it is:

vc() {
  local class=($(rc -S class | fzf-tmux --select-1 --exit-0 --query="$1"))
  local files=($(rc -F "${class}" --definition-only -K | head -n 1))
  local file=($(echo "${files}" | sed 's/:.*//'))
  local line=($(echo "${files}" | sed 's/.*:\([0-9]\+\):[0-9]\+.*/\1/'))
  local offset=($(echo "${files}" | sed 's/.*:\([0-9]\+\):\([0-9]\+\).*/\2/'))
  if [[ ! -z ${file} ]]; then
    ${EDITOR:-vim} ${file} +$line
  fi
}

I type vc in the terminal, hit enter and then fuzzy match the name with fzf, hit enter again and the location of the class is opened in vim. As you can see, it depends on fzf and fzf-tmux. Hope this helps. Please let me know if you come up with a better idea, or if you manage to speed up this.