set nocp "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
"set nu
syntax on
set autoindent
set smartindent
set ts=4
set shiftwidth=4
set ruler
set showmatch "设置匹配模式,类似当输入一个左括号时会匹配相应的那个右括号
set incsearch "查询时非常方便 例如 : book b, bo, boo
set nomore
"------解决乱码,不知有效否?-------------------------
set fileencodings=utf-8,gb18030,gbk,gb2312
set termencoding=utf-8
"set encoding=utf-8,gb18030
"---------------------------------------------
"定义函数SetTitle,自动插入文件头
func SetTitle()
if &filetype == 'c'
call setline(1, "#include <stdio.h>")
call setline(2, "#include <string.h>")
call setline(3, "")
call setline(4, "int main() {")
elseif &filetype == 'cpp'
call setline(1, "#include <iostream>")
call setline(2, "#include <cstdio>")
call setline(3, "#include <cstring>")
call setline(4, "#include <string>")
call setline(5, "#include <algorithm>")
call setline(6, "")
call setline(7, "using namespace std;")
call setline(8, "")
call setline(9, "int main() {")
endif
endfunc
set completeopt=longest,menu
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.[ch],*.sh,*.cpp,*.java exec ":call SetTitle()"
"---------------------------------------------
"定义CompileRun函数,用来调用进行编译和运行
func! CompileRun()
exec "w"
"C程序
if &filetype == 'c'
exec "!gcc % -g -o %<.exe"
exec "! ./%<.exe"
elseif &filetype == 'cpp'
exec "!g++ % -g -o %<.exe"
exec "! ./%<.exe"
"Java程序
elseif &filetype == 'java'
exec "!javac %"
exec "!java %<"
endif
endfunc
"结束定义CompileRun
"-------------------------
" ======= 编译 && 运行 ======= "
" 编译源文件
func! CompileCode()
exec "w"
if &filetype == "c"
exec "!gcc -Wall -std=c99 %<.c -o %<"
elseif &filetype == "cpp"
exec "!g++ -Wall -std=c++98 %<.cpp -o %<"
elseif &filetype == "java"
exec "!javac %<.java"
endif
endfunc
" 运行可执行文件
func! RunCode()
exec "w"
if &filetype == "c" || &filetype == "cpp" || &filetype == "haskell"
exec "! ./%<"
elseif &filetype == "java"
exec "!java %<"
endif
endfunc
ubuntu 下 vim 的配置
最新推荐文章于 2024-08-13 21:47:53 发布