日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

vim:一鍵編譯單個源文件

 herowuking 2014-04-10
 具體功能如下:
1.按F5編譯單個文件,支持C,C++,C#,也可以支持java。
2.獲取編譯器錯誤描述,在錯誤描述上回車,可以直接跳轉(zhuǎn)到錯誤行。
總之一句話,懶人的第一選擇。

準備工作:
1.安裝Vi/Vim/gVim,Windows、Linux環(huán)境皆可。
2.gcc、g++編譯器。針對這一點,Linux用戶一般比較清楚,用命令which gcc一查就知道是不是有g(shù)cc了。但是對于windows用戶,首先要安裝gcc編譯器,有幾個辦法,(1)安裝minGW,然后把minGW安裝目錄下的bin目錄放到系統(tǒng)path里。(2)安裝Dev-C++,然后把Dev-C++安裝目錄下的bin目錄放到系統(tǒng)path里,(3)安裝cygwin,并保證安裝了gcc、g++(默認都沒有安裝,需要選擇安裝),然后把cygwin安裝目錄下的bin目錄放到系統(tǒng)path里。以上三個方法都可以,可以任意選擇,cygwin安裝大概有點困難,不過也是學習的過程。

好了,代碼列在下面,需要把下面的代碼復制到vim的配置文件(Windows下:_vimrc,Linux下:.vimrc)。保存以后,用vim打開一個C/C++程序,然后F5進行編譯、差錯。
"單個文件編譯
if(has("win32") || has("win95") || has("win64") || has("win16"))
let g:iswindows=1
else
let g:iswindows=0
endif
"單個文件編譯
map <F5> :call Do_OneFileMake()<CR>
function Do_OneFileMake()
if expand("%:p:h")!=getcwd()
echohl WarningMsg | echo "Fail to make! This file is not in the current dir! Press <F7> to redirect to the dir of this file." | echohl None
return
endif
let sourcefileename=expand("%:t")
if (sourcefileename=="" || (&filetype!="cpp" && &filetype!="c"))
echohl WarningMsg | echo "Fail to make! Please select the right file!" | echohl None
return
endif
let deletedspacefilename=substitute(sourcefileename,' ','','g')
if strlen(deletedspacefilename)!=strlen(sourcefileename)
echohl WarningMsg | echo "Fail to make! Please delete the spaces in the filename!" | echohl None
return
endif
if &filetype=="c"
if g:iswindows==1
set makeprg=gcc\ -o\ %<.exe\ %
else
set makeprg=gcc\ -o\ %<\ %
endif
elseif &filetype=="cpp"
if g:iswindows==1
set makeprg=g++\ -o\ %<.exe\ %
else
set makeprg=g++\ -o\ %<\ %
endif
"elseif &filetype=="cs"
"set makeprg=csc\ \/nologo\ \/out:%<.exe\ %
endif
if(g:iswindows==1)
let outfilename=substitute(sourcefileename,'\(\.[^.]*\)$','.exe','g')
let toexename=outfilename
else
let outfilename=substitute(sourcefileename,'\(\.[^.]*\)$','','g')
let toexename=outfilename
endif

if filereadable(outfilename)
if(g:iswindows==1)
let outdeletedsuccess=delete(getcwd()."\\".outfilename)
else
let outdeletedsuccess=delete("./".outfilename)
endif
if(outdeletedsuccess!=0)
set makeprg=make
echohl WarningMsg | echo "Fail to make! I cannot delete the ".outfilename | echohl None
return
endif
endif
execute "silent make"
set makeprg=make

execute "normal :"
if filereadable(outfilename)
if(g:iswindows==1)
execute "!".toexename
else
execute "!./".toexename
endif
endif
execute "copen"

endfunction

"進行make的設置
map <F6> :call Do_make()<CR>
map <c-F6> :silent make clean<CR>
function Do_make()
set makeprg=make
execute "silent make"
execute "copen"
endfunction

以上直接參考至Vimer,感謝Dantezhu 

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多