大神,请问该怎么设置vim,使得创建一个.cc的c++文件?

1 #include <iostream>
2 #include <string>
3
4 using namespace std;
5
6 int main(int argc,char **argv)
7 {
8 return 0;
9 }
~
~

慕娘9325324
浏览 198回答 3
3回答

小怪兽爱吃肉

set nobackupsyntax onset cursorlineset autochdirset syntax=cppset nocompatibleset tabstop=4set expandtabset softtabstop=4set shiftwidth=4set cindentset nuset guifont=Consolas:h10syntax enableif has('gui_running')set background=darkelseset background=darkendifcolorscheme solarizedsource $VIMRUNTIME/vimrc_example.vimsource $VIMRUNTIME/mswin.vimbehave mswinset diffexpr=MyDiff()function MyDiff()let opt = '-a --binary 'if &diffopt =~ 'icase' | let opt = opt . '-i ' | endifif &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endiflet arg1 = v:fname_inif arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endiflet arg2 = v:fname_newif arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endiflet arg3 = v:fname_outif arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endiflet eq = ''if $VIMRUNTIME =~ ' 'if &sh =~ '\<cmd'let cmd = '""' . $VIMRUNTIME . '\diff"'let eq = '"'elselet cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'endifelselet cmd = $VIMRUNTIME . '\diff'endifsilent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eqendfunction" set the menu & the message to Englishset langmenu=en_USlet $LANG= 'en_US'source $VIMRUNTIME/delmenu.vimsource $VIMRUNTIME/menu.vim"Toggle Menu and Toolbarset guioptions-=mset guioptions-=Tmap <silent> <F2> :if &guioptions =~# 'T' <Bar>\set guioptions-=T <Bar>\set guioptions-=m <bar>\else <Bar>\set guioptions+=T <Bar>\set guioptions+=m <Bar>\endif<CR>"turn off vim compatible checkset nocompatible"check file typefiletype on"histroy line countset history=1000"set backgroundset autoindentset smartindent"show match '(' and ')'set showmatch"left-down status lineset ruler"auto match targetsset incsearch"high light searchset hlsearch"auto backup file with filename+~"set backupset titleset foldenable"fold code by syntax 'cmd':"'zi' open/close all folds"'za' open/close current fold"'zM' close all folds"'zR' open all foldsset foldmethod=indent"set foldmethod=marker"set foldmethod=indentset foldcolumn=0set foldopen=all"set foldclose=all"colorscheme evening"set cinoptions+={2,0,p0,t0set cindentset syntax=cppset formatoptions=tcqrset nufunction MyTitle()call setline(1,"/**************************************")call append(line("."), "Author : Pegasus")call append(line(".")+1,"Time :".strftime("%c"))call append(line(".")+2,"FileName:".expand("%"))call append(line(".")+3,"Desc :")call append(line(".")+4,"*************************************/")endf"add headermap <F9> <Esc>:call MyTitle()<CR><Esc>:$<Esc>o<Esc>function CppFramework()call setline(8,"#include <iostream>")call setline(9,"#include <cstdio>")call setline(10,"#include <cmath>")call setline(11,"#include <algorithm>")call setline(12,"using namespace std;")call setline(13,"int main()")call setline(14,"{")call setline(15," return 0;")call setline(16,"}")endf"add cpp frameworkmap <F10> <Esc>:call CppFramework()<CR><Esc>:$<Esc>2kofunction AddComment()if &syntax=="cpp" || &syntax=="c"execute "normal \<Esc>\<S-$>a\<TAB>/* */\<Esc>2ha"elseif &syntax=="py"execute "normal \<Esc>\<S-$>a\<TAB>#\<Esc>2ha"elseif &syntax=="lua"execute "normal \<Esc>\<S-$>a\<TAB>--\<Esc>2ha"endifendf"add commentmap <F4> <Esc>:call AddComment()<CR>ifunction CommOneLine()let tmp=getline(".")call setline(line("."),"/*")call append(line("."),"".tmp." //by Pegasus ".strftime("%c"))call append(line(".")+1," */")endfmap <F5> <Esc>:call CommOneLine()<CR><ESC>"foramt code with K&R stylemap <F8> <Esc>:1,$g/^$/d<CR><Esc>gg=G<Esc>gglet $Tlist_Ctags_Cmd='/usr/bin/Ctags'map <F7> <Esc>:TlistToggle<CR>"big headermap <F11> <Esc>:call MyTitle()<CR><Esc>:$<Esc>o<Esc>function BigCppFramework()call setline(8,"#include <iostream>")call setline(9,"#include <cstdio>")call setline(10,"#include <string>")call setline(11,"#include <cstring>")call setline(12,"#include <vector>")call setline(13,"#include <list>")call setline(14,"#include <deque>")call setline(15,"#include <map>")call setline(16,"#include <set>")call setline(17,"#include <stack>")call setline(18,"#include <queue>")call setline(19,"#include <algorithm>")call setline(20,"#include <functional>")call setline(21,"#include <cmath>")call setline(22,"#include <cstdlib>")call setline(23,"#include <ctime>")call setline(24,"using namespace std;")call setline(25,"int main()")call setline(26,"{")call setline(27,"#ifndef ONLINE_JUDGE")call setline(28," freopen(\"in.txt\", \"r\", stdin);")call setline(29,"#endif")call setline(30," return 0;")call setline(31,"}")endf"add cpp frameworkmap <F12> <Esc>:call BigCppFramework()<CR><Esc>:$<Esc>2kofunction BigAddComment()if &syntax=="cpp" || &syntax=="c"execute "normal \<Esc>\<S-$>a\<TAB>/* */\<Esc>2ha"elseif &syntax=="py"execute "normal \<Esc>\<S-$>a\<TAB>#\<Esc>2ha"elseif &syntax=="lua"execute "normal \<Esc>\<S-$>a\<TAB>--\<Esc>2ha"endifendf上面是我的vimrc文件,你用一下这个专门对c++的,然后再命令模式下按ctrl +F9再ctrl+F10

交互式爱情

使用 vim 的 autocmd 命令可以实现,但是更简单的方式是在 shell 中用脚本语言重新定义 vim 命令,使文件名参数匹配 *.cc,并且是一个新文件时,先把固定模型写入新文件再开始编辑。

慕侠2389804

vim没这功能吧。你实现做一个template.cc文件,需要的时候:cp template.cc newfile.cc不就行了。
打开App,查看更多内容
随时随地看视频慕课网APP