vimrc of ubuntu

" ================================= FUNCTIONS =================================
function MaximizeWindow()  " Used in GNOME
   silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
endfunction
function ShortTabLabel() " Only show filename on tabs
    let bufnrlist = tabpagebuflist (v:lnum)
    let label = bufname (bufnrlist[tabpagewinnr (v:lnum) -1])
    let filename = fnamemodify (label, ':t')
    return filename
endfunction
function WasCommented(str)  " Judge is this line a comment (by //)
    let str_len = strlen(a:str) | let i = 0
    while i < str_len
        if a:str[i] != ' ' && a:str[i] != "\t" | break | endif | let i += 1
    endwhile
    if i < str_len - 1 && a:str[i] == a:str[i+1] && a:str[i] == "/" | return 1 | else | return 0 | endif
endfunction
function ToggleCommentLine()  " Toggle line with //
    let nr = line('.') | let str_line = getline(nr)
    if WasCommented(str_line) | let newstr = substitute(str_line, '//', '', '')
    else | let newstr = substitute(str_line, '^', '//', '') | endif
    call setline(nr, newstr)
endfunction
function WhichOpened()  " Judge if Tagbar or NERDTree opened. 0 both are not, 1 only Tagbar, 2 only NERDTree, 3 both were opened.
    let retv = 0
    if bufwinnr('__Tagbar__') != -1 | let retv += 1 | endif
    if bufwinnr('NERD_tree_1') != -1 | let retv += 2 | endif
    return retv
endfunction
func ToggleTagbar()
    let wo = WhichOpened()
    if (wo == 1 || wo == 3) | exec "TagbarClose"
    else | exec "TagbarOpen" | endif
endf
func ToggleNERDTree()
    let wo = WhichOpened() | exec "NERDTreeClose"
    if (wo != 2 && wo != 3) | exec "NERDTreeToggle" | exec "normal! \<c-w>h" | endif
endf
function ToggleFull()  " Open or close Tagbar and NERDTree at the same time.
    let wo = WhichOpened() | exec "NERDTreeClose"
    if (wo == 0) | exec "NERDTreeToggle" | exec "normal! \<c-w>h" | exec "TagbarOpen"
    else | exec "TagbarClose" | endif
endfunction
function FindFilePath()  " Let NERDTree unfold to current file.
    exec 'NERDTreeFind' | exec "normal! \<c-w>h"
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
    :lopen | :exec "normal! \<c-w>J"
endfunction
function ToggleWrap()
    if getwinvar(0, '&wrap') == 1 | exe "set nowrap"
    else | exe "set wrap" | endif
endfunction
function ShowCurrentTag()  " about Tagbar
    let str = tagbar#currenttag('%s', '', 's') | echo str
endfunction
function MyChangeDir()
    let newdir = input("cd: ", strpart(execute('pwd'), 1), "dir")
    exe 'cd ' . newdir
endfunction
function CloseWindow()
    if len(getwininfo()) >= 2 | :q
    else | exec "echo \'This is the last window!\'" | endif
endfunction
function DeleteCurBuf() " Delete the buffer and don't close the window
    let l:cBuf = bufnr("%")
    if 0 == buflisted(l:cBuf) | exec "echo \'This buffer can not be deleted.\'" | 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 " unmodifiable window
    for winInfo in allWndInfo
        if winInfo.winnr == currentWndInfo.winnr | continue | endif
        if getbufvar(winInfo.bufnr, '&modifiable') == 1 | :q | return | endif
    endfor
    call DeleteCurBuf()
endfunction
" about Ack.vim
function BuildIgnore()
    let dir_list = split(g:ack_ignore_dir, ',')
    let result = ' '
    for dirname in dir_list
        let result = result . '--ignore ' . dirname . ' '
    endfor
    return result
endfunction
let g:ack_root = ' '
function AckWithOptions(...)
    let ignores = BuildIgnore()
    if a:0 > 0 | exec 'Ack! -U' . ignores . a:1 . ' ' . g:ack_root
    else | exec 'Ack! -U' . ignores . expand('<cword>'). ' ' . g:ack_root | endif
endfunction
function AckSetSearchRoot()
    let newackroot = input("Enter a directory to set the root to: ", strpart(execute('pwd'), 1), "dir")
    if empty(newackroot) | return | endif
    let g:ack_root = newackroot
endfunction
command! -nargs=? MyAck call AckWithOptions(<f-args>)
command! -nargs=0 MyAckSetRoot call AckSetSearchRoot()

" ============================ basic settings ==================================
set encoding=utf-8 "设置编辑器默认使用的编码
if !has("win32") | language en_US.utf8| endif " 为了保证状态栏不变特别宽
set nocompatible   "不兼容vi

if has("gui_running")
    set guifont=Hurmit\ NF\ medium\ 13
    set guioptions-=T   "不显示工具栏
    set guioptions-=L   "不显示左边的滚动条
    set guioptions-=r   "不显示右边的滚动条
    set guioptions-=m   "不显示菜单栏
    set guitablabel=%{ShortTabLabel()}
    set vb t_vb=        "这两行是不允许响铃不闪屏提示
    au GuiEnter * set t_vb=
endif

set number              "显示行号
set hlsearch            "高亮搜索结果
set shiftwidth=4        "代码自动缩进的列数
set tabstop=4           "设置tab字符显示的列数
set expandtab           "用空格代替tab字符
set autoindent          "启动代码自动缩进功能
set hidden              "避免当前编辑文档未保存时,在新窗口打开新文档
set cursorline          "高亮光标所在行
set textwidth=0         "超过后自动拆行(0表示关闭此功能)
set colorcolumn=81,121  "高亮指定的列
set mouse=a             "支持鼠标
set completeopt=menu    "以弹出菜单的方式显示补全内容
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           "tag有多个匹配项时可以提供选择的机会
set scrolloff=0         "设置光标离屏幕顶底的距离
"set imdisable           "禁用输入法,--谨慎设置--

" ================================ hot keys ====================================
nnoremap <leader>b :ls<CR>
nnoremap <leader>c :call ToggleCommentLine()<cr>
nnoremap <leader>e :browse confirm e<CR>
nnoremap <leader>s :e ~/.vimrc<CR>
nnoremap <leader>w :update<CR>

nmap ;s <Plug>(easymotion-F)
nmap ;f <Plug>(easymotion-f)
nmap ;j <Plug>(easymotion-j)
nmap ;k <Plug>(easymotion-k)

nnoremap <s-Tab> :bn<CR>
vnoremap <s-Tab> <esc>:bn<CR>
inoremap <s-Tab> <esc>:bn<CR>
nnoremap <c-Tab> :b#<CR>
vnoremap <c-Tab> <esc>:b#<CR>
inoremap <c-Tab> <esc>:b#<CR>
nnoremap <c-s-tab> :bp<cr>
vnoremap <c-s-tab> <esc>:bp<cr>
inoremap <c-s-tab> <esc>:bp<cr>
inoremap <c-f> <pagedown>
inoremap <c-b> <pageup>

nnoremap <m-q> :call SmartCloseWindow()<cr>
nnoremap <m-e> :nohl<cr>
vnoremap <m-e> <c-c>:nohl<cr>
inoremap <m-e> <c-o>:nohl<cr>
nnoremap <c-right> 3zl
nnoremap <c-s-right> zL
nnoremap <c-left> 3zh
nnoremap <c-s-left> zH
nnoremap <m-w> :call ToggleWrap()<cr>
inoremap <m-w> <c-o>:call ToggleWrap()<cr>
vnoremap <m-w> <c-c>:call ToggleWrap()<cr>
inoremap <c-h> <c-o><bs><del>
 
nmap <m-f3> :MyAck<cr>
imap <m-f3> <c-o>:MyAck<cr>
nmap <m-f> :MyAck 

nnoremap <f1>      :call ToggleTagbar()<cr>
inoremap <f1> <c-o>:call ToggleTagbar()<cr>
vnoremap <f1> <c-c>:call ToggleTagbar()<cr>
nnoremap <f2>      :call ToggleNERDTree()<cr>
vnoremap <f2> <c-c>:call ToggleNERDTree()<cr>
inoremap <f2> <c-o>:call ToggleNERDTree()<cr>
vnoremap <F3>  <C-C><ESC>/<C-R>+<CR><ESC>N
nnoremap <F3> /<C-R>=expand("<cword>")<CR><CR>N
inoremap <F3> <c-o>/<C-R>=expand("<cword>")<CR><CR><c-o>N
nnoremap <f5> <esc>:call FindFilePath()<cr>
vnoremap <f5> <esc>:call FindFilePath()<cr>
inoremap <f5> <esc>:call FindFilePath()<cr>
"nmap <F6> <ESC>:CtrlPFunky<cr>
"vmap <F6> <ESC>:CtrlPFunky<cr>
"imap <F6> <ESC>:CtrlPFunky<cr>
nnoremap <F7> <ESC>:CtrlP<CR>
vnoremap <F7> <ESC>:CtrlP<CR>
inoremap <F7> <ESC>:CtrlP<CR>
nnoremap <F8> <ESC>:CtrlPMRU<CR>
vnoremap <F8> <ESC>:CtrlPMRU<CR>
inoremap <F8> <ESC>:CtrlPMRU<CR>
nnoremap <F9> <ESC>:call ToggleQuickfix()<CR>
vnoremap <F9> <ESC>:call ToggleQuickfix()<CR>
inoremap <F9> <ESC>:call ToggleQuickfix()<CR>
nnoremap <f10> <esc>:call ToggleLoclist()<cr>
vnoremap <f10> <esc>:call ToggleLoclist()<cr>
inoremap <f10> <esc>:call ToggleLoclist()<cr>
nnoremap <silent> <F11> <ESC>:<C-R>=line("'<")<CR>,<C-R>=line("'>")<CR>s/^/\/\/<CR>/^$x<CR>
vnoremap <silent> <F11> <ESC>:<C-R>=line("'<")<CR>,<C-R>=line("'>")<CR>s/^/\/\/<CR>/^$x<CR>
inoremap <silent> <F11> <ESC>:<C-R>=line("'<")<CR>,<C-R>=line("'>")<CR>s/^/\/\/<CR>/^$x<CR>
nnoremap <silent> <F12> <ESC>:<C-R>=line("'<")<CR>,<C-R>=line("'>")<CR>s/\/\//<CR>/^$x<CR>
vnoremap <silent> <F12> <ESC>:<C-R>=line("'<")<CR>,<C-R>=line("'>")<CR>s/\/\//<CR>/^$x<CR>
inoremap <silent> <F12> <ESC>:<C-R>=line("'<")<CR>,<C-R>=line("'>")<CR>s/\/\//<CR>/^$x<CR>

if !has("win32")   " Some hot keys like windows
    vnoremap <C-C> "+y
    map <C-V>		"+gP
    imap <C-V>      <c-o>"+gP
    cmap <C-V>		<C-R>+
    noremap <C-S>		:update<CR>
    vnoremap <C-S>		<C-C>:update<CR>
    inoremap <C-S>		<C-O>:update<CR>
    noremap <C-A> gggH<C-O>G
    inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
    cnoremap <C-A> <C-C>gggH<C-O>G
    onoremap <C-A> <C-C>gggH<C-O>G
    snoremap <C-A> <C-C>gggH<C-O>G
    xnoremap <C-A> <C-C>ggVG
endif

" =================================== plugin settings ==========================
filetype off            " required
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 'mileszs/ack.vim'
Plugin 'Yggdroot/LeaderF'    " 部分代替ctrlp
if has('gui_running')
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/nerdtree'
Plugin 'drmingdrmer/xptemplate'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'ap/vim-buftabline'        "文件列表标签
endif
call vundle#end()            " required
filetype plugin indent on    " required

" ack
let g:ackprg = 'ag --vimgrep'
let g:ack_ignore_dir='target,*.class,*.jar,tags,tags.files'

" LeaderF
"let g:Lf_ShortcutB = '<c-p>'
let g:Lf_WindowHeight = 0.35
nnoremap <leader>f :LeaderfFunction<cr>

" ------------------------------------------
if has('gui_running')
" Tagbar
let g:tagbar_left=1         "显示在左边
let g:tagbar_width=30       "窗口宽度
let g:tagbar_compact = 1    "隐藏帮助信息

" NERDTree
let NERDTreeWinPos='right'      "显示在右边
let NERDTreeShowLineNumbers=0   "不显示行号
let NERDTreeWinSize=30          "窗口宽度
let NERDTreeMinimalUI=1         "隐藏帮助信息

" ctrlp
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd='CtrlPBuffer'
let g:ctrlp_by_filename = 1
let g:ctrlp_regexp = 1
let g:ctrlp_working_path_mode = 'rw'
let g:ctrlp_max_height = 30
let g:ctrlp_max_files = 100000
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_bufpath_mod = '' " 让Buffer mode不显示路径
let g:ctrlp_cache_dir = '~/.ctrlp'
let g:ctrlp_root_markers = ['pom.xml', '.project']
let g:ctrlp_custom_ignore = {
    \ 'dir': '\v[\/](build|bin|target)$',
    \ 'file': '\v\.(jar|class|MF|xlsx|files|proto|xsd|png|gif|svg|json|gz|less|scss|jpg|swf|ttf)$',
    \ 'link': 'SOME_BAD_SYMBOLIC_LINKS',}

" vim-airline
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'only_lastname'
let g:airline#extensions#whitespace#enabled = 0 " 关闭状态显示空白符号计数
let g:airline#extensions#whitespace#symbol = '!'
if has('win32')
    if !exists('g:airline_symbols') | let g:airline_symbols = {} | endif
    let g:airline_left_sep = '⮀'
    let g:airline_left_alt_sep = '⮁'
    let g:airline_right_sep = '⮂'
    let g:airline_right_alt_sep = '⮃'
    let g:airline_symbols.branch = '⭠'
    let g:airline_symbols.readonly = '⭤'
    let g:airline_symbols.linenr = '⭡'
endif
endif
" ------------------------------------------

" All about Eclim
nnoremap <c-leftmouse> <esc>:JavaSearchContext -t all -x implementors -s project -a edit<cr>
nnoremap <c-j> <esc>:JavaSearchContext -t all -x implementors -s project -a edit<cr>
nnoremap <m-leftmouse> <esc>:JavaSearchContext -t all -x declarations -s project -a edit<cr>
nnoremap <m-j> <esc>:JavaSearchContext -t all -x declarations -s project -a edit<cr>
let g:EclimDefaultFileOpenAction = 'edit'
nnoremap <silent> <buffer> <leader>i :JavaImport<cr>
nnoremap <silent> <buffer> <cr> :JavaSearchContext<cr>

" ywvim 
" http://www.vim.org/scripts/script.php?script_id=2662
set noimcmdline
let g:ywvim_ims=[ 
            \['wb', '五笔', 'wubi.ywvim'], 
            \['py', '拼音', 'pinyin.ywvim'], 
            \['cj', '仓颉', 'cangjie.ywvim'], 
            \['wb98', '五笔98', 'wubi98.ywvim'], 
            \['zm', '郑码', 'zhengma.ywvim'], 
            \['zy', '注音', 'zhuyin.ywvim'], 
            \['ar30', '行列', 'array30.ywvim'], 
            \] 
let g:ywvim_py = { 'helpim':'wb', 'gb':0 } 
let g:ywvim_zhpunc = 2    " 设置默认中文标点输入开关, 1 为开, 默认打开拼音输入, 2 为关
let g:ywvim_listmax = 5 
let g:ywvim_esc_autoff = 0 
let g:ywvim_autoinput = 2 
let g:ywvim_circlecandidates = 1 
let g:ywvim_helpim_on = 0 
let g:ywvim_matchexact = 0 
let g:ywvim_chinesecode = 1 
let g:ywvim_gb = 0 
let g:ywvim_preconv = 'g2b' 
let g:ywvim_conv = '' 
let g:ywvim_lockb = 1 
"let g:ywvim_theme = 'dark'

colorscheme molokai
set bg=dark

posted on 2017-10-27 20:30  哥斯达黎加  阅读(181)  评论(0编辑  收藏  举报

导航