当前位置:首页 » 编程软件 » 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