在linux下vim中使tags高亮 高亮標籤 *tag-highlight* www.2cto.com 如果你想高亮檔案裡的所有標籤,可以使用如下映射。 <F11> -- 產生 tags.vim 檔案,並高亮標籤。
<F12> -- 只根據已有的 tags.vim 檔案高亮標籤。 :map <F11> :sp tags<CR>:%s/^\([^ :]*:\)\=\([^ ]*\).*/syntax keyword Tag \2/<CR>:wq! tags.vim<CR>/^<CR><F12> :map <F12> :so tags.vim<CR> 警 告: 標籤檔案越長,這會越慢,而 Vim 消耗的記憶體也越多。 這裡只高亮 typedef,也可以針對 union 和 struct 進行設定。為此,你需要 Exuberant ctags (可在 http://ctags.sf.net 找到)。 在你的 Makefile 裡放入以下的行: # 建立 types 的高亮檔案。需要 Exuberant ctags 和 awk types: types.vim types.vim: *.[ch] ctags -i=gstuS -o- *.[ch] |\ awk 'BEGIN{printf("syntax keyword Type\t")}\ {printf("%s ", $$1)}END{print ""}' > $@ 在你的 .vimrc 裡放入以下的行: " 載入 types.vim 高亮檔案,如果存在的話 autocmd BufRead,BufNewFile *.[ch] let fname = expand('<afile>:p:h') . '/types.vim' autocmd BufRead,BufNewFile *.[ch] if filereadable(fname) autocmd BufRead,BufNewFile *.[ch] exe 'so ' . fname autocmd BufRead,BufNewFile *.[ch] endif ==================================================以上的F11隻能識別函數內部的定義,函數名等,不能識別宏定義。自己改成"根據tags檔案產生高亮檔案tags.vimmap <F11> :sp tags<CR>:set nohls<CR>:%s/file/fi le/<CR>:%s/^\([^ :]*:\)\=\([^ ]*\).*/syntax keyword Tag \2/<CR>:wq! tags.vim<CR>/^<CR><F12>"高亮檔案裡的所有標籤map <F12> :so tags.vim<CR>就可以識別宏了