vim – 将定义的类型着色为类型
发布时间:2020-12-16 01:34:28 所属栏目:安全 来源:网络整理
导读:有没有办法为C语言中使用typedef语句定义的新类型添加语法着色? typedef struct { int a,b;} MyStruct;MyStruct *InitMyStruct(MyStruct *struct,int a,int b); ^ ^ ^ ^ ^ +---------+-----------+ +------+ Same Color Correct type color 如果它本身不可
|
有没有办法为C语言中使用typedef语句定义的新类型添加语法着色?
typedef struct {
int a,b;
} MyStruct;
MyStruct *InitMyStruct(MyStruct *struct,int a,int b);
^ ^ ^ ^ ^
+---------+-----------+ +------+
Same Color Correct type color
如果它本身不可能(我猜是这样),是否有任何插件可以使这个视觉线索工作?
我在Vim的帮助下找到了我问题的确切解决方案,我将在此发布,以防将来有人需要.这正是我想要的:一种阅读代码并相应地突出显示它的方法.
syntax.txt 第15节:突出显示标签 [...]
Only highlighting typedefs,unions and structs can be done too. For this you
must use Exuberant ctags (found at http://ctags.sf.net).
Put these lines in your Makefile:
# Make a highlight file for types. Requires Exuberant ctags and awk
types: types.vim
types.vim: *.[ch]
ctags --c-kinds=gstu -o- *.[ch] |
awk 'BEGIN{printf("syntax keyword Typet")}
{printf("%s ",$$1)}END{print ""}' > $@
And put these lines in your .vimrc: >
" load the types.vim highlighting file,if it exists
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
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
