LoginSignup
33
33

More than 5 years have passed since last update.

vimのコードジャンプをgtagsでやってみるぞい

Last updated at Posted at 2017-06-17

概要

  • ctagsって全然メンテされてなくね。後継とかないわけ?
  • GNU global とかいうのがあるらしい
  • Vimで飛べるようにしたら快適だよぉ

注意:ただのメモ

インストール(mac)

brewでズン

$ brew install global --with-ctags --with-pygments

設定ファイル作成

設定ファイルをデフォルトからコピー

cp /usr/local/Cellar/global/6.5.7/share/gtags/gtags.conf ~/.globalrc

globalのビルトインのファイル形式以外をpygmentで処理するように修正

これを

~/.globalrc
default:\
    :tc=native:

こう

~/.globalrc
default:\
    :tc=native:tc=pygments:

参考

GNU GLOBALの対応言語を大幅に増やすPygmentsパーサーを導入する
ソースコードを快適に読むための GNU GLOBAL 入門

プラギン導入

gtags.vim

カーソル下の文字列に対して定義、参照をそれぞれquickfixで表示。
deinでズン。ちなみにgithubリポジトリに、公式プラグインの最新版が公開されてなかったので、リポジトリ作っといた。


[[plugins]]
repo = 'lighttiger2505/gtags.vim'
hook_add = '''
    " Options
    let g:Gtags_Auto_Map = 0
    let g:Gtags_OpenQuickfixWindow = 1
    " Keymap
    " Show definetion of function cousor word on quickfix
    nmap <silent> K :<C-u>exe("Gtags ".expand('<cword>'))<CR>
    " Show reference of cousor word on quickfix
    nmap <silent> R :<C-u>exe("Gtags -r ".expand('<cword>'))<CR>
'''

gen_tags.vim

gtagsを非同期で自動更新してくれる。
deinでズン。

[[plugins]]
repo = 'jsfaint/gen_tags.vim'
hook_add = '''
    let g:gen_tags#gtags_auto_gen = 1
'''

denite-gtags.vim

denite表示用のソース。
deinでズン。期待した挙動をしてくれなかったので暇があったらプラグイン作りたい。

[[plugins]]
repo = 'ozelentok/denite-gtags'
hook_add = '''
    " Prefix key
    nmap [denite] <Nop>
    map <C-j> [denite]
    " Keymap
    nmap <silent> [denite]<C-D> :Denite -buffer-name=gtags_completion gtags_completion<cr>
'''
33
33
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
33