您的位置:首页 > 其它

Mac OS X下安装与配置ctags和tagbar.vim以开发obj-c

2014-01-17 00:21 501 查看

Mac OS X下安装与配置ctags和tagbar.vim以开发obj-c

ctags
原先不支持objective-c, 后来在其trunk分支上增加了对obj-c的支持(其stable版本 截止目前仍然不支持obj-c). 由于
ctags
早期不支持obj-c,
tagbar.vim
插件亦未内置obj-c 支持. 因此, 为了在obj-c文件中正常使用
tagbar.vim
以及使用tag跳转功能,
需要一 些比较hack的方式处理. 以下是安装与配置
ctags
tagbar.vim
的详细步骤.

安装与配置

安装
tagbar.vim


常规方式, 无须说明

使用Homebrew安装
ctags
的最新版本(trunk分支)

安装命令如下
brew install ctags --HEAD

如果已经安装stable版本的
ctags
, 安装前先
brew uninstall ctags


在Xcode工程根目录下运行以下命令创建tags文件

ctags --exclude='.git' --exclude='*.js' -R .


配置
tagbar.vim
. 在
.vimrc
文件中加入以下配置.

" add a definition for Objective-C to tagbar
let g:tagbar_type_objc = {
\ 'ctagstype' : 'ObjectiveC',
\ 'kinds'     : [
\ 'i:interface',
\ 'I:implementation',
\ 'p:Protocol',
\ 'm:Object_method',
\ 'c:Class_method',
\ 'v:Global_variable',
\ 'F:Object field',
\ 'f:function',
\ 'p:property',
\ 't:type_alias',
\ 's:type_structure',
\ 'e:enumeration',
\ 'M:preprocessor_macro',
\ ],
\ 'sro'        : ' ',
\ 'kind2scope' : {
\ 'i' : 'interface',
\ 'I' : 'implementation',
\ 'p' : 'Protocol',
\ 's' : 'type_structure',
\ 'e' : 'enumeration'
\ },
\ 'scope2kind' : {
\ 'interface'      : 'i',
\ 'implementation' : 'I',
\ 'Protocol'       : 'p',
\ 'type_structure' : 's',
\ 'enumeration'    : 'e'
\ }
\ }

按照以上步骤即可在vim使用tag跳转功能了, 也能使用tagbar显示outline了.

快捷键优化

Vim默认使用
Ctrl+]
往前跳tag, 使用
Ctrl + t
往回跳, 为什么不是
Ctrl+[
呢?
Ctrl+]
配对, 好记又方便. 在
.vimrc
加入以下代码可使得
Ctrl+[
往回跳.
" 注意 \[
nnoremap <C-\[> <C-T>

扩展阅读

How to make Tagbar work with Objective-C
John Goulah » Make Browsing Code Easier with Ack and Ctags
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: