您的位置:首页 > 其它

Vim的一些基本配置(比较全面些,可以少找其他资料)

2012-12-09 13:29 513 查看
"以下是一些基本配置
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

"关闭toolbar
set guioptions-=T
"打开自动备份
set backup
"自动格式化
set formatoptions=tcrqn
"在行和段开始处使用制表符
set smarttab
"在normal模式下使用系统剪贴板
set clipboard+=unnamed
set cindent "设置C语法高亮
set showmode  "显示状态行 列;
set showcmd
set ruler     "显示行号
syn on
set showmatch
set smartindent
set shiftwidth=4
set autoindent
set ai!
filetype plugin indent on
set completeopt=longest,menu
set number
set cursorline
set tabstop=4
set backspace=2
set nocompatible  "不实用vi的键盘模式
set confirm " 在处理未保存或只读文件的时候,弹出确认
" 与windows共享剪贴板
set clipboard+=unnamed
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" 高亮字符,让其不受100列限制
:highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
:match OverLength '\%101v.*'
" 在状态行上显示光标所在位置的行号和列号
set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 启动的时候不显示那个援助索马里儿童的提示
set shortmess=atI
" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0
" 不让vim发出讨厌的滴滴声
set noerrorbells
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\
" 高亮显示匹配的括号
set showmatch
" 在搜索的时候忽略大小写
set ignorecase
" 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
set incsearch
" 只在下列文件类型被侦测到的时候显示行号,普通文本文件不显示
set guifont=Courier_New:h11
set lines=36 columns=81 "设置窗口大小
colorscheme DarkZ

"ctags的设置
let Tlist_Show_One_File=1
let Tlist_Use_Right_Windows=1 "右侧显示taglist窗口
nmap <F10> :!ctags -R E:\work\erlang\*<CR>

"set new file extension jsm as javascript file.
au BufNewFile,BufRead *.jsm set filetype=javascript

"taglist设置
" 不同时显示多个文件的 tag ,只显示当前文件的
let Tlist_Show_One_File=1
" 如果 taglist 窗口是最后一个窗口,则退出 vim
let Tlist_Exit_OnlyWindow=1
"让当前不被编辑的文件的方法列表自动折叠起来
"let Tlist_File_Fold_Auto_Close=1
"把taglist窗口放在屏幕的右侧,缺省在左侧
let Tlist_Use_Left_Window=1
"显示taglist菜单
let Tlist_Show_Menu=1
"启动vim自动打开taglist
let Tlist_Auto_Open=1
"设置高宽
"Tlist_WinHeight=35
"Tlist_WinWidth=10
"tl作为快捷键
map <silent> <leader>tl :TlistToggle<CR>

"winmanager设置
let g:winManagerWindowLayout = "TagList|FileExplorer,BufExplorer"
"设置winmanager的宽度,默认为25
let g:winManagerWidth = 10
"定义打开关闭winmanager按键
wincmd R "设置左边
"在进入vim时自动打开winmanager
let g:AutoOpenWinManager = 1

if has("autocmd")
autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number
autocmd FileType xml,html vmap <C-o> <ESC>'<i<!--<ESC>o<ESC>'>o-->
autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o
autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
autocmd Filetype html,xml,xsl source $VIMRUNTIME/plugin/closetag.vim
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe " normal g`\"" |
\ endif
endif "has("autocmd")

" F5编译和运行C程序,F6编译和运行C++程序
" 请注意,下述代码在windows下使用会报错
" 需要去掉./这两个字符

" C的编译和运行,这里在windows很难用!
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
exec "!gcc % -o %<"
exec "! %<"
endfunc

" C++的编译和运行
map <F6> :call CompileRunGpp()<CR>
func! CompileRunGpp()
exec "w"
exec "!g++ % -o %<"
exec "! %<"
endfunction

" 用空格键来开关折叠
set foldenable
set foldmethod=manual
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc':'zo')<CR>

set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction

"以下自动补全括号等
noremap ( ()<Esc>i
inoremap [ []<Esc>i
inoremap { {<CR>}<Esc>O
autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR>
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=CloseBracket()<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR>

function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf

function CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\<CR>}"
else
return "\<Esc>j0f}a"
endif
endf

function QuoteDelim(char)
let line = getline('.')
let col = col('.')
if line[col - 2] == "\\"
"Inserting a quoted quotation mark into the string
return a:char
elseif line[col - 1] == a:char
"Escaping out of the string
return "\<Right>"
else
"Starting a string
return a:char.a:char."\<Esc>i"
endif
endf

function! RemovePairs()
let s:line = getline(".")
let s:previous_char = s:line[col(".")-1] " 取得当前光标前一个字符

if index(["(", "[", "{"], s:previous_char) != -1
execute "normal! v%xi"
else
execute "normal! a\<BS>"
end

function! RemovePairs()
let l:line = getline(".")
let l:previous_char = l:line[col(".")-1] " 取得当前光标前一个字符

if index(["(", "[", "{"], l:previous_char) != -1
let l:original_pos = getpos(".")
execute "normal %"
let l:new_pos = getpos(".")

" 如果没有匹配的右括号
if l:original_pos == l:new_pos
execute "normal! a\<BS>"
return
end

let l:line2 = getline(".")
if len(l:line2) == col(".")
" 如果右括号是当前行最后一个字符
execute "normal! v%xa"
else
" 如果右括号不是当前行最后一个字符
execute "normal! v%xi"
end

else
execute "normal! a\<BS>"
end
endfunction

" 用退格键删除一个左括号时同时删除对应的右括号
inoremap <BS> <ESC>:call RemovePairs()<CR>a

function! RemoveNextDoubleChar(char)
let l:line = getline(".")
let l:next_char = l:line[col(".")] " 取得当前光标后一个字符

if a:char == l:next_char
execute "normal! l"
else
execute "normal! i" . a:char . ""
end
endfunction

inoremap ) <ESC>:call RemoveNextDoubleChar(')')<CR>a
inoremap ] <ESC>:call RemoveNextDoubleChar(']')<CR>a
inoremap } <ESC>:call RemoveNextDoubleCha
endfunction

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: