转载地址:http://blog.csdn.net/onepiecehuiyu/article/details/8934366
http://mawenhao19930620.blog.163.com/blog/static/12857536120112991818242/
Windows下gvim配置文件_vimrc
首先配置g++到环境变量(配置g++,具体是将devc++的g++.exe的路径比如说:c:/deVC++/bin..加入到环境变量path里面) , 然后将下面的代码复制并保存为_vimrc , 替换掉vim安装文件夹中的_vimrc文件(或者是打开Vim
的启动设定,然后复制下面的代码并保存即可)
1 "Version: 1.0 by momodi@whuacm 2 "Modified by ghostboyzone@gmail.com 3 4 source $VIMRUNTIME/mswin.vim 5 behave mswin 6 imap <c-d> <c-o>dd 7 imap <cr> <cr><left><right> 8 map o o<left><right> 9 imap <c-]> {<cr>}<c-o>O<left><right> 10 noremap <f6> =a{ 11 syn on 12 colo desert 13 filetype indent on 14 se ru nu ar sw=4 ts=4 noswf et sta nowrap ww=<,>,[,] gfn=Consolas:h12 15 autocmd BufEnter * lcd %:p:h 16 map <c-t> :tabnew<CR> 17 map <f9> :call CR()<CR><CR> 18 func CR() 19 exec 'update' 20 if filereadable(expand('%<').'.in') 21 exec '!start cmd /c _run %< < %<.in & pause' 22 else 23 exec '!start cmd /c _run %< & pause' 24 endif 25 endfunc 26 map <f2> :call SetTitle()<CR>Gkkk 27 func SetTitle() 28 let l = 0 29 let l = l + 1 | call setline(l, '/*') 30 let l = l + 1 | call setline(l, ' * Author: mybestwishes') 31 let l = l + 1 | call setline(l, ' * Created Time: '.strftime('%c')) 32 let l = l + 1 | call setline(l, ' * File Name: '.expand('%')) 33 let l = l + 1 | call setline(l, ' */') 34 let l = l + 1 | call setline(l, '#include <iostream>') 35 let l = l + 1 | call setline(l, '#include <cstdio>') 36 let l = l + 1 | call setline(l, '#include <cstdlib>') 37 let l = l + 1 | call setline(l, '#include <cstring>') 38 let l = l + 1 | call setline(l, '#include <cmath>') 39 let l = l + 1 | call setline(l, '#include <algorithm>') 40 let l = l + 1 | call setline(l, '#include <string>') 41 let l = l + 1 | call setline(l, '#include <vector>') 42 let l = l + 1 | call setline(l, '#include <stack>') 43 let l = l + 1 | call setline(l, '#include <queue>') 44 let l = l + 1 | call setline(l, '#include <set>') 45 let l = l + 1 | call setline(l, '#include <time.h>') 46 let l = l + 1 | call setline(l, 'using namespace std;') 47 let l = l + 1 | call setline(l, 'const int maxint = -1u>>1;') 48 let l = l + 1 | call setline(l, '') 49 let l = l + 1 | call setline(l, 'int main() {') 50 let l = l + 1 | call setline(l, ' return 0;') 51 let l = l + 1 | call setline(l, '}') 52 let l = l + 1 | call setline(l, '') 53 endfunc 54 55 map<f4> :call AddComment()<cr> 56 func AddComment() 57 if matchstr(getline('.'), '[^ ]') == '/' 58 normal ^xx 59 else 60 normal ^i// 61 endif 62 endfunc 63 64 set printoptions=syntax:n,number:y,portrait:y 65 66 67 "设置水平滚动条 68 set guioptions+=b 69 70 "set encoding=utf-8 71 "set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1 " 如果你要打开的文件编码不在此列,那就添加进去 72 "set termencoding=utf-8
---------------------------------------------------------------------------------------------------------------
然后将下面代码编译, 修改产生的exe文件名为_run.exe
1 #include <cstdio> 2 3 #include <cstdlib> 4 5 #include <ctime> 6 7 8 int main(int argc, char **argv) { 9 10 char compiler[50] = {}; 11 12 sprintf(compiler, "g++ %s.cpp -o %s.exe", argv[1], argv[1]); 13 14 char runcommand[50] = {}; 15 16 sprintf(runcommand, "%s.exe", argv[1]); 17 18 if (system(compiler) == 0) { 19 20 int t = clock(); 21 22 if (system(runcommand) == 0) { 23 24 printf("\nRun Time: %dms\n", clock() - t); 25 26 } 27 28 } 29 30 return 0; 31 32 }
将_run.exe放到和gvim.exe同一个目录下 。windows下的gvim即配置完毕 。
Linux下gvim配置文件_vimrc
打开Vim的启动设定,然后复制下面的代码并保存即可
1 "Vim for linux 2 3 source $VIMRUNTIME/mswin.vim 4 5 behave mswin 6 7 imap <c-d> <c-o>dd 8 9 imap <cr> <cr><left><right> 10 11 map o o<left><right> 12 13 imap <c-]> {<cr>}<c-o>O<left><right> 14 15 noremap <f6> =a{ 16 17 syn on 18 19 colo desert 20 21 "colo torte 22 23 filetype indent on 24 25 26 set gfn=Courier\ 10\ Pitch\ 12 27 28 set ru nu et sta nowrap ar acd ww=<,>,[,] sw=4 ts=4 cin noswf 29 30 31 "se ru nu ar sw=4 ts=4 noswf et sta nowrap ww=<,>,[,] gfn=Consolas:h12 32 33 autocmd BufEnter * lcd %:p:h 34 35 map <c-t> :tabnew<CR> 36 37 38 map <f9> :call CR()<CR><CR> 39 40 func CR() 41 42 exec "update" 43 44 exec "!xterm -fn 10*20 -e \"g++ %<.cpp -Wall -o %< && time ./%< < %<.in ; read -n 1\"" 45 46 endfunc 47 48 49 map <f10> :call CR2()<cr><space> 50 51 func CR2() 52 53 exec "update" 54 55 exec "!xterm -fn 10*20 -e \"g++ %<.cpp -Wall -o %< && time ./%< ; read -n 1\"" 56 57 endfunc 58 59 60 map <f2> :call SetTitle()<CR>Gkkk 61 62 func SetTitle() 63 64 let l = 0 65 66 let l = l + 1 | call setline(l, '/*') 67 68 let l = l + 1 | call setline(l, ' * Author: mybestwishes') 69 70 let l = l + 1 | call setline(l, ' * Created Time: '.strftime('%c')) 71 72 let l = l + 1 | call setline(l, ' * File Name: '.expand('%')) 73 74 let l = l + 1 | call setline(l, ' */') 75 76 let l = l + 1 | call setline(l, '#include <iostream>') 77 78 let l = l + 1 | call setline(l, '#include <cstdio>') 79 80 let l = l + 1 | call setline(l, '#include <cstdlib>') 81 82 let l = l + 1 | call setline(l, '#include <cstring>') 83 84 let l = l + 1 | call setline(l, '#include <cmath>') 85 86 let l = l + 1 | call setline(l, '#include <algorithm>') 87 88 let l = l + 1 | call setline(l, '#include <string>') 89 90 let l = l + 1 | call setline(l, '#include <vector>') 91 92 let l = l + 1 | call setline(l, '#include <stack>') 93 94 let l = l + 1 | call setline(l, '#include <queue>') 95 96 let l = l + 1 | call setline(l, '#include <set>') 97 98 let l = l + 1 | call setline(l, '#include <time.h>') 99 100 let l = l + 1 | call setline(l, 'using namespace std;') 101 102 let l = l + 1 | call setline(l, 'const int maxint = -1u>>1;') 103 104 let l = l + 1 | call setline(l, '') 105 106 let l = l + 1 | call setline(l, 'int main() {') 107 108 let l = l + 1 | call setline(l, ' return 0;') 109 110 let l = l + 1 | call setline(l, '}') 111 112 let l = l + 1 | call setline(l, '') 113 114 endfunc 115 116 117 map<f4> :call AddComment()<cr> 118 119 func AddComment() 120 121 if (getline('.')[0] == '/') 122 123 normal ^xx 124 125 else 126 127 normal 0i// 128 129 endif 130 131 endfunc 132 133 set printoptions=syntax:n,number:y,portrait:y 134 135 set guioptions+=b 136 137 138 set encoding=utf-8 139 140 set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1 141 142 set termencoding=utf-8
上面的_vimrc配置文件可以根据自己的需求添加和删除相应的内容。
在Windows平台上,是按[F9]编译并执行; 在Linux平台上,是按[F9]或[F10]执行,一个是带输入文件,一个是不带输入文件。
vimrc for windows and linux: 下载地址