当前位置: 移动技术网 > 科技>操作系统>Linux > linux下vim 语法高亮显示方法

linux下vim 语法高亮显示方法

2019年03月19日  | 移动技术网科技  | 我要评论

曹小洋,菜园里ppt,湿润的女人 torrent

高亮标签 *tag-highlight*
如果你想高亮文件里的所有标签,可以使用如下映射。
<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.vim
map <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>
就可以识别宏了

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网