Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1147487
  • 博文数量: 341
  • 博客积分: 12744
  • 博客等级: 上将
  • 技术积分: 4040
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-12 09:34
文章分类
文章存档

2014年(1)

2013年(10)

2012年(17)

2011年(63)

2010年(102)

2009年(107)

2008年(41)

分类: LINUX

2009-09-16 17:51:40



CompileRunGcc()
    exec "wa"
    exec "!gcc % -o %< -g"
    exec "! ./%<"
endfunc

 CompileRunGxx()
    exec "wa"
    exec "!g++ % -o %< -g"
    exec "! ./%<"
endfunc

if has("autocmd")

    ;自动补全( (如果文件为C或者C++)
    autocmd FileType c,cpp inoremap ( ()<esc>:let leavechar=")"<cr>

    ;自动补全{结构(如果文件为C或者C++)
    autocmd FileType c,cpp inoremap { {<esc>o}<esc>:let leavechar="}"<cr>O

    ;自动补全main函数结构(如果文件为C或者C++)
    autocmd FileType c,cpp inoremap main int main(int argc, char *argv[])<cr>{<cr>}<esc>O

    ;自动补全for结构(如果文件为C或者C++)
    autocmd FileType c,cpp inoremap for for (;;)<cr>{<cr><cr>}<esc>3kf;i

    ;自动补全while结构(如果文件为C或者C++)
    autocmd FileType c,cpp inoremap while while ()<cr>{<cr><cr>}<esc>3kf)i

    ;自动补全if、else、elseif结构(如果文件为C或者C++)
    autocmd FileType c,cpp inoremap if if ()<cr>{<cr><cr>}<esc>3kf)i

    autocmd FileType c,cpp inoremap else<cr> else<cr>{<cr>}<esc>O
    autocmd FileType c,cpp inoremap else\ if else if ()<cr>{<cr><cr>}<esc>3kf)i

    ;如果文件为C,则按f3加入#include
    autocmd FileType c nnoremap <F3> #include

    ;按f4编译单个C或者C++文件
    autocmd FileType c map <F4> :call CompileRunGcc()<CR><CR>
    autocmd FileType cpp map <F4> :call CompileRunGxx()<CR><CR>

    ;如果文件为C++,则按f3加入#include

    ;using namespace std;
    autocmd FileType cpp nnoremap <F3> #include using namespace std;

    ;补全printf结构
    autocmd FileType c,cpp inoremap printf printf("");<esc>2hi
endif

阅读(1710) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~