Macでctagsを使う

1.前提環境

OS Version:OS X 10.8.2

その他:portが使えること。

2.準備(portを使ったインストール)

Mac OS Xに標準でインストールされているctagsは、BSD由来で

一般的ではないらしいので、portを使ってインストールをし直します。

インストールは下記の通りです。

 

$ port info ctags
Warning: port definitions are more than two weeks old, consider using selfupdate
ctags @5.8 (devel)
Variants:             universal
Description:          Exuberant Ctags generates an index (or tag) file of source language objects in source files that
                      allows these items to be quickly and easily located by a text editor or other utility.
                      Alternatively, it can generate a cross reference file which lists, in human-readable form,
                      information about the various objects found in a set of source code files. Supported languages
                      include: Assembler, AWK, ASP, BETA, Bourne/Korn/Zsh Shell, C, C++, COBOL, Eiffel, Fortran, Java,
                      Lisp, Lua, Make, Pascal, Perl, PHP, Python, REXX, Ruby, S-Lang, Scheme, Tcl, Vim and Yacc.
Homepage:             http://ctags.sourceforge.net/
Platforms:            darwin, freebsd
License:              GPL-2
Maintainers:          mww@macports.org, openmaintainer@macports.org
$ sudo port install ctags
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.
To proceed, enter your password, or type Ctrl-C to abort.
Password:
Warning: port definitions are more than two weeks old, consider using selfupdate
--->  Fetching ctags
--->  Attempting to fetch ctags-5.8.tar.gz from http://jaist.dl.sourceforge.net/ctags
--->  Verifying checksum(s) for ctags
--->  Extracting ctags
--->  Configuring ctags
--->  Building ctags
--->  Staging ctags into destroot
--->  Installing ctags @5.8_0
--->  Activating ctags @5.8_0
--->  Cleaning ctags

 

プロンプトを再起動する。

下記コマンドで、インストールされている事を確認。

$ type ctags

ctags is hashed (/opt/local/bin/ctags)

3.ctagsの基本的な使い方

■タグの作成

$ ctags -R

 

■vimでのタグを使用する。

:set tags

 

■vimでジャンプ

Ctl-] カーソル位置の単語をタグとみなしてジャンプ。

Ctl-t 直前のタグに戻る。

g Ctl-] 複数候補がある場合に選択→ジャンプ。

Ctl-w } カーソル位置の単語の定義を、プレビューウィンドウで開く。

Ctl-w Ctl-z プレビューウィンドウを閉じる。

 

写真素材のピクスタ