每次建立 .c文件 总要有一大堆的头文件要放进去。如下代码实现了自动化头文件:
autocmd BufNewFile *.c exec ":call AddTitleForShell()" function AddTitleForShell() call append(0,"//Author:kunshanpipixia") call append(1,"#include <stdio.h>") call append(2,"#include <stdlib.h>") call append(3,"#include <string.h>") call append(4,"#include <pthread.h>") call append(5,"#include <unistd.h>") endfunction
只需将此代码粘贴至vimrc文件中即可。
下次再vim xxx.c命令时,自动添加你需要的头文件,是不是很方便?!!!!
如下为最终效果: