❶ 在VIM裡面是怎樣編譯c語言的文件
VIM只是文本編輯,不能編譯,你需要調用外部命令來編譯,如果你的path里有gcc的話在vim里輸
:!gcc
-otest
你的c文件名
❷ 如何用vim編寫c語言
直接輸入,結束後保存為.c文件即可。vim的缺點是不支持漢字等UTF字元,用英語寫是沒有問題的。
❸ 如何在windows下用vim調試C程序
先在終端中輸入 vim test.c 回車進入vim編輯器,再按一下a鍵,進入編輯狀態,然後輸入如下C語言語句: #include int main() { printf("hello world!\n"); } 到此,按esc鍵退出編輯狀態,再輸入一個冒號(shift + 冒號分號那個鍵),緊跟著輸入 wq ...
❹ 怎麼在linux下用vim編寫一個C程序
一樓的回答很好,在編譯的時候,其實可以不用退出VIM的,按ESC退出插入模式,在正常模式下輸入:w保存,然後輸入:!gcc /path/to/your/file.c就可以編譯文件了,如果有錯誤,直接就在VIM中修改,要不然為什麼VIM會被稱為神器級的編輯器呢!
❺ 使用vim編輯一段c語言代碼並保存
可以,touch demo.cpp
vim demo.cpp
隨便寫點啥,比如著名的printf{"helo word!"};
然後,按鍵(忘是啥了),然後給wq!就保存並退出了
❻ 我想在vim中直接編譯C語言請問怎樣配置vimrc啊
你用linux編寫C語言的話,只要寫新建命令的時候把文件名的後綴也寫上就可以了(.c)
❼ 在VIM裡面是怎樣編譯C語言的文件
一、首先要會使用vim編寫一個c文件
1.在linux終端下輸入: vi test.c 表示生成了一個test.c的c語言文件
2.此時時命令模式,按"a"鍵或者"i"進入輸入模式,然後就是輸入C語言代碼
3.保存文件,再次回到命令模式,按"ESC「鍵,然後按":"鍵再輸入"wq」表示保存退出
二、然後在用gcc編譯test.c文件
直接輸入 gcc -o mytest test.c即可 表示直接生成mytest執行文件
❽ 怎麼在linux下用vim編寫一個C程序
先在終端中輸入
vim
test.c
回車進入vim編輯器,再按一下a鍵,進入編輯狀態,然後輸入如下C語言語句:
#include<stdio.h>
int
main()
{
printf("hello
world!\n");
}
到此,按esc鍵退出編輯狀態,再輸入一個冒號(shift
+
冒號分號那個鍵),緊跟著輸入
wq
,即
輸入
:wq
按回車,即推出vim編輯器回到終端命令窗口(類似xp的命令提示符),
之後輸入
gcc
test.c
,這步是編譯
./a.out
,
這是執行,將會輸出
hello
world!
到此結束,前提是你已經安裝gcc
❾ 我想在vim中直接編譯C語言請問怎樣配置vimrc啊
"------------------------------------------------------------------------------
" < 編譯、連接、運行配置 >
"------------------------------------------------------------------------------
" 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文件的最後就可以