vimc編譯
linux平台的C開發環境一般有Eclipse CDT,Source Insight或者VIM,都各有特點。
1.首先,在vmware里設置網卡模式為NAT
先ifconfig -a查看那有幾塊網卡,一般可以看到lo和eth0,我這里是eth1
然後用vi /etc/network/interfaces編輯該文件,再最後面加一句iface eth0 inet dhcp
重啟虛擬機或者/etc/init.d/networking restart就行了
再次ifconfig就可以看到已分配到了IP,然後ping一下外網地址驗證一下。
譯和調試環境安裝好了,該裝編輯器VIM了。
2.裝好後為了編輯方便,先啟用語法高亮顯示,自動縮進,顯示行號等,用VIM編輯VIM的配置文件vim /etc/vim/vimrc,在末尾加上如下設置
syntax on
set autoindent
set cindent
set nu
3.先簡單設置這些,以後再設置配色方案,自動提示,文件列表等功能,VI的使用,可以看看VI的中文手冊,和後面的參考鏈接。
B. vim編寫C程序問題
GCC的-O選項代表目的文件,它可以是一個文件名,也可以是一個帶路徑的文件名。你可以把命令改成:
gcc -Wall -o ~/sources/helloworld ~/sources/helloworld.c
這樣目標文件和源文件都在sources目錄下了。
C. 在VIM裡面是怎樣編譯C語言的文件
IDE包括了編輯器,自動為你做了很多事情。就像你如果在WIN下用editplus等編輯器寫代碼,也要你保存之後再用編譯器編譯文件。
linux下也有很多IDE。。。vim也可以通過配置打造成IDE
D. 怎麼在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
E. vim C語言條件編譯的顏色配置問題
這是相當於注釋的,vim的默認主題就是這種顏色配置,你把 #ifdef AAA 換成 #if 0 就可以看到了。如果你vim配置了顏色的話,如果沒有配置就在任意目錄下輸入 vim ~/.vimrc在其中加入set background=dark "設置背景色
F. 我想在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文件的最後就可以
G. 如何用vim編譯C++
1、vim abc.c
2、在abc.c裡面寫好想要的程序
3、在終端裡面跳到該abc.c的目錄下
4、用命令gcc -o t abc.c
5、./t 即可
PS:要先確定安裝了GCC,可在終端下用命令gcc -v來確認~
希望能解決您的問題。
H. vim能編譯C語言的文件嗎
這個東西在linux下用得比較多吧,它就像是一個類似於txt的文本編輯工具,似乎不能實現編譯的功能……我剛剛學C的時候記得有一個叫win-TC的工具,比較小,而且支持滑鼠操作,對初學者比較方便,不過對C的語法要求比較高。
I. 打開vim後怎樣編寫c/c++/java文件即編譯運行 編寫完後如何保存 保存路徑在哪 路徑是否可更改
1、用vim編寫文件代碼,一般需要按i、a、o、O、A、I這六個字母鍵進入插入模式,輸入完成後,按ESC鍵退出插入模式。
2、可以直接在vim中執行,vim通過"!"來執行外部命令。下圖是在vim中通過」!「號執行gcc編譯hello.c的文件,生成可執行文件hello後,同時執行當前文件目錄下的hello。g++、java操作類似。