您的位置:首页 > 其它

vim 完全配置文件

2015-11-08 13:19 393 查看
set fenc=utf-8
syntax on
set number
set shiftwidth=4
set tabstop=4
set autoindent
set wrap
set cindent
set nocompatible
set pastetoggle=<F3>
imap [[ {<cr>}<c-o>O
map <F4> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
exec "!g++ % -o %<"
endfunc
map <F5> :call Run()<CR>
func! Run()
exec "! ./%<"
endfunc

map <F2> :!javac %<cr>
map <F3> :!java %<<cr>
map <F6> :call RunThisScript()<CR>
function RunThisScript()
let file_name = expand("%:p")
let file_ext = expand("%:e")
let file_cmd = ""

"python 直接调用
if file_ext == "py"
let file_cmd = '/usr/bin/python'
let file_args = ' ' . file_name
"c 需要提取第一行的编译参数
"如,当需要引入第三方库(以mysql为例)时,则在第一行添加: //-lmysqlclient -L/usr/local/mysql/include
"文件中则可直接 #include <mysql/mysql.h>
elseif file_ext == "c"
let file_first_line = getline(1)
let file_arg = ""
if strpart(file_first_line, 0, 2) == '//'
let file_arg = strpart(file_first_line, 2) "提取参数
endif
let file_output_file = strpart(file_name, 0, strridx(file_name, '.c'))
let file_args = ' -o '. file_output_file .' '.  file_name . ' '. file_arg .' && '. file_output_file "将参数附加到编译命令之后
let file_cmd = '/usr/bin/cc'
"php 直接调用
elseif file_ext == "php"
let file_cmd = "/usr/local/php/bin/php" "php执行路径
let file_args = ' -f '. file_name
"perl 直接调用
elseif file_ext == "perl" || file_ext == "pl"
let file_cmd = "/usr/bin/perl"
let file_args = " ". file_name
"erlang 默认调用 main 函数, 可以确保 escript 和 noshell/shell 执行时一致
elseif file_ext == "erl"
let file_output_file = strpart(expand("%"), 0, stridx(expand("%"), ".erl"))
let file_cmd = "/usr/bin/erlc"
let file_args = file_output_file .".". file_ext ." ; /usr/bin/erl -noshell -s ". file_output_file . " main  -s init stop"
"java 先调用 javac,再调用java
elseif file_ext == "java"
let file_output_file = strpart(expand("%"), 0, stridx(expand("%"), ".java"))
let file_cmd = 'javac'
let file_args = file_name ." && java ". file_output_file
else
echo "错误: 没有任何编译器匹配此文件类型, 请确认您的文件扩展名!"
endif

if file_cmd != ""
if ! executable(file_cmd)
echo file_cmd
echo "The executable file to compile ". file_ext . " type files."
else
let cmd = "! ". file_cmd . ' ' . file_args
"echo "执行命令: ". cmd
exec cmd
endif
endif
endfunction
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vim