VIM默認情況下,函數名是不會高亮的,將下面這段代碼添加到/usr/share/vim/vim73/syntax/c.vim文件的末尾即可,需要說明的是/usr/share/vim/vim73/syntax/c.vim這個不是固定的:
"highlight Functions
syn match cFunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
syn match cFunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1
hi cFunctions gui=NONE cterm=bold ctermfg=blue
ctermfg表示函數名的顏色,可以自行更換。
接下來是關於c程序指針的相關高亮指示
"Hightlight Operator
"===========================
"--->C pointer operators
syn match cPointerOperator display"->\|\.\|\:\:"
syn match cPointerOperator display"*"
hi cPointerOperator gui=NONE cterm=bold ctermfg=Green
ctermfg顏色可以修改
增加對彙編語言的高亮支持
➜ syntax sudo mv masm.vim 1.vim
➜ syntax sudo mv asm.vim masm.vim
➜ syntax sudo mv 1.vim asm.vim
➜ syntax
-------------------2014-11-13 更新----------------
在vimrc文件中添加以下內容,實現一鍵編譯,一鍵運行
說明:1. 本配置實現的是F5編譯(同時保存,並且編譯後的可執行文件和源代碼文件同名),F6運行。
2.在Linux上可用,Mac OS x上也可用,因爲OS x把C語言編譯器連接到了gcc
如下:
func! CompileGcc()
exec "w"
let compilecmd="!gcc "
let compileflag="-o %< "
if search("mpi\.h") != 0
let compilecmd = "!mpicc "
endif
if search("glut\.h") != 0
let compileflag .= " -lglut -lGLU -lGL "
endif
if search("cv\.h") != 0
let compileflag .= " -lcv -lhighgui -lcvaux "
endif
if search("omp\.h") != 0
let compileflag .= " -fopenmp "
endif
if search("math\.h") != 0
let compileflag .= " -lm "
endif
exec compilecmd." % ".compileflag
endfunc
func! CompileGpp()
exec "w"
let compilecmd="!g++ "
let compileflag="-o %< "
if search("mpi\.h") != 0
let compilecmd = "!mpic++ "
endif
if search("glut\.h") != 0
let compileflag .= " -lglut -lGLU -lGL "
endif
if search("cv\.h") != 0
let compileflag .= " -lcv -lhighgui -lcvaux "
endif
if search("omp\.h") != 0
let compileflag .= " -fopenmp "
endif
if search("math\.h") != 0
let compileflag .= " -lm "
endif
exec compilecmd." % ".compileflag
endfunc
func! RunPython()
exec "!python %"
endfunc
func! CompileJava()
exec "!javac %"
endfunc
func! CompileCode()
exec "w"
if &filetype == "cpp"
exec "call CompileGpp()"
elseif &filetype == "c"
exec "call CompileGcc()"
elseif &filetype == "python"
exec "call RunPython()"
elseif &filetype == "java"
exec "call CompileJava()"
endif
endfunc
func! RunResult()
exec "w"
if search("mpi\.h") != 0
exec "!mpirun -np 4 ./%<"
elseif &filetype == "cpp"
exec "! ./%<"
elseif &filetype == "c"
exec "! ./%<"
elseif &filetype == "python"
exec "call RunPython"
elseif &filetype == "java"
exec "!java %<"
endif
endfunc
map <F5> :call CompileCode()<CR>
imap <F5> <ESC>:call CompileCode()<CR>
vmap <F5> <ESC>:call CompileCode()<CR>
map <F6> :call RunResult()<CR>