通用的vim配置
function MaximizeWindow()
silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
endfunction
function ToggleQuickfix()
let winList = getwininfo()
for window in winList
if window.quickfix == 1
if window.loclist == 1 | continue | else | :ccl | return | endif
endif
endfor
:copen | :exec "normal! \<c-w>J"
endfunction
function ToggleLoclist()
let winList = getwininfo()
for window in winList
if window.quickfix == 1
if window.loclist != 1 | continue | else | :lcl | return | endif
endif
endfor
:silent! lopen | :exec "normal! \<c-w>J"
endfunction
function ToggleWrap()
if getwinvar(0, '&wrap') == 1 | exe "set nowrap" | else | exe "set wrap" | endif
endfunction
function DeleteCurBuf() " Delete current buffer and never close the window
let l:cBuf = bufnr("%")
if 0 == buflisted(l:cBuf) | exec "echo \'This buffer can not be delete.\'" | return | endif
if buflisted(bufnr("#")) | exec "b#" | else | exec "bp" | endif
let l:newBufNum = bufnr("%")
if l:cBuf == l:newBufNum | exec "echo \'This is the last opened file.\'" | return | endif
exec "bw " . l:cBuf
endfunction
function SmartCloseWindow()
let allWndInfo = getwininfo()
if len(allWndInfo) <= 1 | call DeleteCurBuf() | return | endif
let currentWndInfo = getwininfo(win_getid())[0]
if currentWndInfo.loclist == 1 || currentWndInfo.quickfix == 1 | :q | return | endif
if getbufvar(currentWndInfo.bufnr, '&modifiable') == 0 | :q | return | endif " close unmodifiable window directly
for winInfo in allWndInfo
if winInfo.winnr == currentWndInfo.winnr | continue | endif
if getbufvar(winInfo.bufnr. '&modifiable') == 1 | :q | return | endif
endfor
call DeleteCurBuf()
endfunction
" ============================= basic settings =============================
set encoding=utf-8 " 设置编辑器默认编码
set nocompatible " 关闭兼容模式
set number " 显示行号
set hlsearch " 高亮搜索结果
set incsearch " incsearch
set shiftwidth=4 " 代码自动缩进的列数
set tabstop=4 " TAB键的宽度
set expandtab " 使用空格代替TAB键
set autoindent " 开启自动缩进功能
set hidden " 为了允许未保存的文件隐藏在后台
set cursorline " 高亮光标所在行
"set textwidth=0 " 超过指定列后自动拆行
set colorcolumn=81,121 " 高亮指定的列
set mouse=a " 支持鼠标
set completeopt=menuone " 补全内容以弹出菜单显示,只有一条数据时也弹出菜单
set ffs=unix,dos " 识别指定类型的换行符
set laststatus=2 " 总是显示状态栏
set nobackup " 不生成备份文件
set noundofile " 不以文件方式记录undo list
set noswapfile " 不生成swap文件
set nowrap " 不自动拆行
set sidescroll=5 " 横向滚动时的单位列数
"set foldmethod=indent " 代码折叠方式
set nofoldenable " 关闭代码折叠
"set cscopetag " 使用以cscope数据库中的tag
"set scrolloff=0 " 翻页时光标离屏幕上下的行数
“set imdisable " 禁用输入法
set clipboard=unnamed,unnamedplus " 让vim内部的复制粘贴内容直接在剪贴版中
" 防止响铃或者闪屏
set vb t_vb=
autocmd GuiEnter * set t_vb=
if has("win32")
autocmd GuiEnter * simalt ~x
endif
if has("gui_running")
"set guifont=Consolas\ for\ Powerline\ FixedD:h12 " windows下
set guifont=Consolas\ for\ Powerline\ FixedD\ 12 " 非windows
set guioptions-=m " 不显示菜单栏
set guioptions-=T " 不显示工具栏
set guioptions-=L " 不显示左边滚动条
set guioptions-=r " 不显示右边滚动条
endif
behave mswin
source $VIMRUNTIME/mswin.vim
" ================================= key mapping ============================
nmap ;f <Plug>(easymotion-s)
nmap <c-g> <Plug>(easymotion-s)
nmap ;j <Plug>(easymotion-j)
nmap ;k <Plug>(easymotion-k)
nmap <leader>e :browse confirm e<cr>
nmap <leader>s :e ~/.vimrc<cr>
nmap <s-tab> <esc>:bn<cr>
vmap <s-tab> <esc>:bn<cr>
imap <s-tab> <esc>:bn<cr>
nmap <c-s-tab> <esc>:bp<cr>
vmap <c-s-tab> <esc>:bp<cr>
imap <c-s-tab> <esc>:bp<cr>
nmap <c-tab> <esc>:b#<cr>
vmap <c-tab> <esc>:b#<cr>
imap <c-tab> <esc>:b#<cr>
nmap <c-right> 3zl
nmap <c-left> 3zh
nmap <c-s-left> zH
nmap <c-s-right> zL
nmap <m-e> <esc>:nohl<cr>
vmap <m-e> <c-c>:nohl<cr>
imap <m-e> <c-o>:nohl<cr>
nmap <m-w> <esc>:call ToggleWrap()<cr>
vmap <m-w> <c-c>:call ToggleWrap()<cr>
imap <m-w> <c-o>:call ToggleWrap()<cr>
nmap <m-q> :call SmartCloseWindow()<cr>
nmap <f1> <esc>:TagbarToggle<cr>
vmap <f1> <c-c>:TagbarToggle<cr>
imap <f1> <c-o>:TagbarToggle<cr>
nmap <f2> <esc>:NERDTreeToggle<cr>
vmap <f2> <c-c>:NERDTreeToggle<cr>
imap <f2> <c-o>:NERDTreeToggle<cr>
nmap <f3> /<c-r>=expand("<cword>")<cr><cr>N
vmap <f3> <c-c><esc>/<c-r>+<cr><esc>N
imap <f3> <c-o>/<c-r>=expand("<cword>")<cr><cr>N
imap <f4> <c-r>=strftime("%Y-%m-%d")<cr>
nmap <f5> <esc>:NERDTreeFind<cr>
vmap <f5> <c-c>:NERDTreeFind<cr>
imap <f5> <c-o>:NERDTreeFind<cr>
nmap <f9> <esc>:call ToggleQuickfix()<cr>
vmap <f9> <esc>:call ToggleQuickfix()<cr>
imap <f9> <esc>:call ToggleQuickfix()<cr>
nmap <f10> <esc>:call ToggleLoclist()<cr>
vmap <f10> <esc>:call ToggleLoclist()<cr>
imap <f10> <esc>:call ToggleLoclist()<cr>
nmap <silent><f11> <esc>:.s/^/\/\/<cr>/^$x<cr>
imap <silent><f11> <esc>:.s/^/\/\/<cr>/^$x<cr>
vmap <silent><f11> <esc>:<c-r>=line("'<")<cr>,<c-r>=line("'>")<cr>s/^/\/\/<cr>/^$x<cr>
nmap <silent><f12> <esc>:.s/\/\//<cr>/^$x<cr>
imap <silent><f12> <esc>:.s/\/\//<cr>/^$x<cr>
vmap <silent><f12> <esc>:<c-r>=line("'<")<cr>,<c-r>=line("'>")<cr>s/\/\//<cr>/^$x<cr>
" ============================== plugin settings ==============================
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin('~/.vim/bundle')
Plugin 'VundleVim/Vundle.vim'
Plugin 'easymotion/vim-easymotion'
Plugin 'altercation/vim-colors-solarized'
Plugin 'tomasr/molokai'
Plugin 'Yggdroot/LeaderF'
Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/nerdtree'
Plugin 'drmingdrmer/xptemplate'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'ap/vim-buftabline'
Plugin 'vimwiki/vimwiki'
"Plugin 'mileszs/ack.vim'
"Plugin 'mattn/calender-vim'
"Plugin 'idxuan/bx_vimim_dict'
"Plugin 'ctrlpvim/ctrlp.vim'
call vundle#end()
filetype plugin indent on
" LeaderF
nmap <leader>f :LeaderfFunction<cr>
let g:Lf_ShortcutB='<c-p>'
let g:Lf_ShortcutF='<m-p>'
let g:Lf_WildIgnore={'dir':['.svn','.git'], 'file':['*.exe','*.so']}
" Tagbar
let g:tagbar_left=1 " 显示在左边
let g:tagbar_width=30 " 窗口宽度
let g:tagbar_compact=1 " 隐藏帮助信息
" NERDTree
let NERDTreeWinPos='right' " 显示在右边
let NERDTreeWinSize=30 " 窗口宽度
let NERDTreeShowLineNumbers=0 " 不显示行号
let NERDTreeMinimalUI=1 " 隐藏帮助信息
" vim-airline
let g:airline_pwoerline_fonts=1
let g:airline#extensions#whitespace#enabled=0
let g:airline#extensions#whitespace#symbol='!'
" ywvim
”let g:ywvim_ims=[['wb', '五笔', 'wubi.ywvim']]
" Eclim
nmap <c-j> <esc>:JavaSearchContext -t all -x implementors -s project -a edit<cr>
nmap <m-j> <esc>:JavaSearchContext -t all -x declarations -s project -a edit<cr>
let g:EclimDefaultFileOpenAction='edit'
" // TODO
" vimwiki
nmap ;ww <Plug>VimwikiIndex
nmap ;ws <Plug>VimwikiUISelect
nmap ;wi <Plug>VimwikiDiaryIndex
nmap ;wgg :VimwikiGoto
nmap ;w;w <Plug>VimwikiMakeDiaryNote
nmap ;w;y <Plug>VimwikiMakeYesterdayDiaryNote
nmap ;w;m <Plug>VimwikiMakeTomorrowDiaryNote
nmap ;w;i <Plug>VimwikiDiaryGenerateLinks
let g:vimwiki_use_mouse = 1
let g:vimwiki_list_ignore_newline = 0
let g:vimwiki_text_ignore_newline = 0
let g:vimwiki_CJK_length = 1
let g:vimwiki_list = [{'path': '~/wiki/mdtest/', 'path_html': '~/wiki/mdtest_html/', 'syntax': 'markdown', 'ext': '.md' }]
" ===================== post settings =====================
colorscheme molokai
syntax enable
网友评论