Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vim 将定义的类型着色为类型_Vim_Syntax Highlighting - Fatal编程技术网

Vim 将定义的类型着色为类型

Vim 将定义的类型着色为类型,vim,syntax-highlighting,Vim,Syntax Highlighting,有没有办法给C中用typedef语句定义的新类型添加语法着色 typedef struct { int a,b; } MyStruct; MyStruct *InitMyStruct(MyStruct *struct, int a, int b); ^ ^ ^ ^ ^ +---------+-----------+ +------+ Same 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节:突出显示标记
[…]
也只能突出显示typedef、联合和结构。为了这个你
必须使用丰富的CTAG(可在http://ctags.sf.net).
在Makefile中放入以下行:
#为类型创建高亮显示文件。需要丰富的CTAG和awk
类型:types.vim
types.vim:[ch]
ctags--c-种类=gstu-o-*[ch]|\
awk'BEGIN{printf(“语法关键字类型\t”)}\
{printf(“%s”,$$1)}结束{print”“}>$@
并将这些行放在您的.vimrc:>
“加载types.vim突出显示文件(如果存在)
autocmd BufRead,BufNewFile*[ch]让fname=expand(':p:h')。/types.vim'
autocmd BufRead,BufNewFile*[ch]如果文件可读(fname)
autocmd BufRead,BufNewFile*[ch]exe'so'.fname
autocmd BufRead,BufNewFile*[ch]endif

可能与类似。此处给出的链接描述了如何对函数执行此操作,应该可以将其更改为识别结构。感谢@joshhendo,尽管我正在寻找一个更“阅读我的代码并突出显示它”的链接,但问题是类似的“解决办法。不太一般。但我设法找到了解决办法。猜猜看在哪里?是的,在维姆的帮助下。检查我对这个问题的回答。
[...]
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 Type\t")}\
                        {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