【VIM自动补全】NeoComplCache

NeoComplCache这个自动插件简直屌爆了。用vim.org的官方选项来评价,就是:
Life Changing。

安装也很简单:

1. 下载插件,将里面的文件拷贝到~/vim/vimfile里对应的文件夹下。
2. 在.vimrc文件里加入自动启动的命令:

 let g:neocomplcache_enable_at_startup = 1

   或者运行:

:NeoComplCacheEnable 

   命令。

以上两步官方说明十分齐全。

配置:

"使用带force的选项,使一个键只帮一个作用。比较清爽
"
open the snippet
imap <silent><C-l> <Plug>(neocomplcache_snippets_force_expand)
smap <silent><C-l> <Plug>(neocomplcache_snippets_force_expand)

"jump to next placeholder
imap <silent><C-k> <Plug>(neocomplcache_snippets_force_jump)
smap <silent><C-k> <Plug>(neocomplcache_snippets_force_jump)

" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"



 

另外:因为冲突的原因,所以需要额外设置shiftwidth选项

set shiftwidth=4

 否则自动生成的模板缩进为8个空格。这不是一般人想要的。

 

修改snippet的模板:

将大括号从原来的行末变成新起一行,左对齐,可以通过修改snippet模板来实现,路径为

autoload\neocomplcache\sources\snippets_complete\c.snip

修改后的文件如下:

c.snip
snippet     if
abbr if () {}
if (${1:/* condition */})
{
${0:/* code */}
}

snippet else
else
{
${0}
}

snippet elseif
else if (${1:/* condition */})
{
${0}
}

snippet ifelse
abbr if () {} else {}
if (${1:condition})
{
${2}
}
else
{
${3}
}

snippet for
abbr for () {}
for (${1} = 0; $1 < ${2}; $1++)
{
${0}
}

snippet while
abbr while () {}
while (${1:/* condition */})
{
${0:/* code */}
}

snippet do_while
do
{
${0:/* code */}
} while (${1:/* condition */});

snippet switch
abbr switch () {}
switch (${1:var})
{
case ${2:val}:
${0}
break;
}

snippet function
abbr func() {}
${1:void} ${2:func_name}(${3})
{
${0}
}

snippet struct
abbr struct {}
struct ${1:name}
{
${0:/* data */}
};

# Typedef struct
snippet struct_typedef
typedef struct ${1:name}
{
${0:/* data */}
};

snippet enum
abbr enum {}
enum ${1:name}
{
${0}
};

# main function.
snippet main
int main(int argc, char const* argv[])
{
${0}
return 0;
}

# #include <...>
snippet inc
#include <${1:stdio}.h>${0}
# #include "..."
snippet Inc
#include "${1:}.h"${0}

snippet Def
abbr #ifndef ... #define ... #endif
#ifndef $1
#define ${1:SYMBOL} ${2:value}
#endif${0}

snippet def
#define

# Include-Guard
snippet once
abbr include-guard
#ifndef ${1:SYMBOL}
#define $1

${0}
#endif /* end of include guard */

# Tertiary conditional
snippet conditional
(${1:/* condition */})? ${2:a} : ${3:b}

# Typedef
snippet typedef
typedef ${1:base_type} ${2:custom_type};

snippet printf
printf("${1}\n"${2});${0}

snippet fprintf
fprintf(${1:stderr}, "${2}\n"${3});${0}

snippet comment
alias /*
/* ${1:comment}
*/
${0}



 





posted on 2011-12-06 12:48  LateStop  阅读(4186)  评论(0)    收藏  举报

导航