當前位置:首頁 » 編程軟體 » vim編譯選項

vim編譯選項

發布時間: 2025-07-25 23:33:01

A. linux中如何用gcc編譯用vi寫的c文件

方法/步驟

1、進入linux系統,創建C文件「vim test.c」同時進入vim編輯界面也可以利用指令「touch test.c」創建後,然後「vim test.c」進入vim編輯界面。

B. Ubuntu 10.10 Vim 如何配置快捷鍵如編譯C++ 源代碼 ,按下一個鍵就可以保存退出等等

可以用映射來做,把映射寫在~/.vimrc裡面,比如把map <F3> :w<CR>加入到~/.vim中之後,在每次編輯好後,按下F3就能保存下來。對於編譯c++程序,你可以加入這個映射:
map <F6> :call CompileCpp()<CR>
func! CompileCpp()
exec "w"
exec "!g++ % -o %<"
endfunc
重啟vim或在normal模式下運行命令:source ~/.vimrc 後就能通過按鍵F6編譯C++程序了。
想知道更多,你可以在google中搜索 vim的映射,資源很多的。

C. 怎麼在linux下用vim編寫一個C程序

一樓的回答很好,在編譯的時候,其實可以不用退出VIM的,按ESC退出插入模式,在正常模式下輸入:w保存,然後輸入:!gcc /path/to/your/file.c就可以編譯文件了,如果有錯誤,直接就在VIM中修改,要不然為什麼VIM會被稱為神器級的編輯器呢!

D. 我想在vim中直接編譯C語言請問怎樣配置vimrc啊

python">"------------------------------------------------------------------------------
" < 編譯、連接、運行配置 >
"------------------------------------------------------------------------------
" F9 一鍵保存、編譯、連接存並運行
map <F9> :call Run()<CR>
imap <F9> <ESC>:call Run()<CR>
" Ctrl + F9 一鍵保存並編譯
map <c-F9> :call Compile()<CR>
imap <c-F9> <ESC>:call Compile()<CR>
" Ctrl + F10 一鍵保存並連接
map <c-F10> :call Link()<CR>
imap <c-F10> <ESC>:call Link()<CR>
let s:LastShellReturn_C = 0
let s:LastShellReturn_L = 0
let s:ShowWarning = 1
let s:Obj_Extension = '.o'
let s:Exe_Extension = '.exe'
let s:Sou_Error = 0
let s:windows_CFlags = 'gcc -fexec-charset=gbk -Wall -g -O0 -c % -o %<.o'
let s:linux_CFlags = 'gcc -Wall -g -O0 -c % -o %<.o'
let s:windows_CPPFlags = 'g++ -fexec-charset=gbk -Wall -g -O0 -c % -o %<.o'
let s:linux_CPPFlags = 'g++ -Wall -g -O0 -c % -o %<.o'
func! Compile()
exe ":ccl"
exe ":update"
if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"
let s:Sou_Error = 0
let s:LastShellReturn_C = 0
let Sou = expand("%:p")
let Obj = expand("%:p:r").s:Obj_Extension
let Obj_Name = expand("%:p:t:r").s:Obj_Extension
let v:statusmsg = ''
if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou)))
redraw!
if expand("%:e") == "c"
if g:iswindows
exe ":setlocal makeprg=".s:windows_CFlags
else
exe ":setlocal makeprg=".s:linux_CFlags
endif
echohl WarningMsg | echo " compiling..."
silent make
elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
if g:iswindows
exe ":setlocal makeprg=".s:windows_CPPFlags
else
exe ":setlocal makeprg=".s:linux_CPPFlags
endif
echohl WarningMsg | echo " compiling..."
silent make
endif
redraw!
if v:shell_error != 0
let s:LastShellReturn_C = v:shell_error
endif
if g:iswindows
if s:LastShellReturn_C != 0
exe ":bo cope"
echohl WarningMsg | echo " compilation failed"
else
if s:ShowWarning
exe ":bo cw"
endif
echohl WarningMsg | echo " compilation successful"
endif
else
if empty(v:statusmsg)
echohl WarningMsg | echo " compilation successful"
else
exe ":bo cope"
endif
endif
else
echohl WarningMsg | echo ""Obj_Name"is up to date"
endif
else
let s:Sou_Error = 1
echohl WarningMsg | echo " please choose the correct source file"
endif
exe ":setlocal makeprg=make"
endfunc
func! Link()
call Compile()
if s:Sou_Error || s:LastShellReturn_C != 0
return
endif
let s:LastShellReturn_L = 0
let Sou = expand("%:p")
let Obj = expand("%:p:r").s:Obj_Extension
if g:iswindows
let Exe = expand("%:p:r").s:Exe_Extension
let Exe_Name = expand("%:p:t:r").s:Exe_Extension
else
let Exe = expand("%:p:r")
let Exe_Name = expand("%:p:t:r")
endif
let v:statusmsg = ''
if filereadable(Obj) && (getftime(Obj) >= getftime(Sou))
redraw!
if !executable(Exe) || (executable(Exe) && getftime(Exe) < getftime(Obj))
if expand("%:e") == "c"
setlocal makeprg=gcc -o %< %<.o
echohl WarningMsg | echo " linking..."
silent make
elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
setlocal makeprg=g++ -o %< %<.o
echohl WarningMsg | echo " linking..."
silent make
endif
redraw!
if v:shell_error != 0
let s:LastShellReturn_L = v:shell_error
endif
if g:iswindows
if s:LastShellReturn_L != 0
exe ":bo cope"
echohl WarningMsg | echo " linking failed"
else
if s:ShowWarning
exe ":bo cw"
endif
echohl WarningMsg | echo " linking successful"
endif
else
if empty(v:statusmsg)
echohl WarningMsg | echo " linking successful"
else
exe ":bo cope"
endif
endif
else
echohl WarningMsg | echo ""Exe_Name"is up to date"
endif
endif
setlocal makeprg=make
endfunc
func! Run()
let s:ShowWarning = 0
call Link()
let s:ShowWarning = 1
if s:Sou_Error || s:LastShellReturn_C != 0 || s:LastShellReturn_L != 0
return
endif
let Sou = expand("%:p")
let Obj = expand("%:p:r").s:Obj_Extension
if g:iswindows
let Exe = expand("%:p:r").s:Exe_Extension
else
let Exe = expand("%:p:r")
endif
if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou)
redraw!
echohl WarningMsg | echo " running..."
if g:iswindows
exe ":!%<.exe"
else
if g:isGUI
exe ":!gnome-terminal -e ./%<"
else
exe ":!./%<"
endif
endif
redraw!
echohl WarningMsg | echo " running finish"
endif
endfunc

怎麼用有注釋,直接放到你vimrc文件的最後就可以

熱點內容
android單詞源碼 發布:2025-07-26 16:23:51 瀏覽:505
寫安卓系統用什麼語言 發布:2025-07-26 16:23:15 瀏覽:595
安卓東方財富的緩存數據在哪裡 發布:2025-07-26 16:23:10 瀏覽:826
編輯器linux 發布:2025-07-26 16:16:28 瀏覽:646
javalinux獲取路徑 發布:2025-07-26 16:13:55 瀏覽:883
團支書智慧團建密碼是多少 發布:2025-07-26 16:10:32 瀏覽:884
如何清除蘋果6s緩存 發布:2025-07-26 16:08:25 瀏覽:822
手機配置高玩不了單機游戲怎麼辦 發布:2025-07-26 15:53:05 瀏覽:258
手機設置開機手勢密碼後如何解鎖 發布:2025-07-26 15:39:14 瀏覽:39
迭代優化演算法 發布:2025-07-26 15:25:45 瀏覽:949