不是最強大的vimrc

一直都是使用vim做爲個人主要編輯器,它大大提升了個人代碼編輯效率。vim的配置高度靈活、插件豐富,恐怕100我的就有99種配置方法,網上關於vim配置的所謂「最強大的vimrc」之類的文章很多,博人眼球,無可厚非,不過我相信,永遠沒有最強大的配置,只有更合理的配置。畢竟vim的學習曲線仍是比較陡的,複雜的配置並不必定適合於新手的學習,另外,每一個人對編輯器的功能需求是不同的,使用vim的目的也因人而異,某些插件和功能對一我的頗有用,對另外一我的可能就毫無用處。審美需求和習慣也是多樣化的,最典型的就是配色問題,沒有哪種配色方案能夠知足全部人的口味。因此, 別人的配置只可借鑑,不宜照搬,取長去短,按本身的喜愛和習慣慢慢地打造一個適合本身的個性vim,我以爲這纔是樂趣所在。php

先來看圖:shell

vim效果圖.png

如下是我的的配置方式(也是根據他人配置修改而來):vim

1.終端配色方案:molokai

2.設置終端顯示模式爲256色

方法1:
新建文件~/.gnome-terminal-wrapper
在其中添加如下內容:
export TERM=xterm-256color
exec $SHELLwindows

方法2:在vimrc中加入:
set t_Co=256session

3.個人vimrc配置

」 Modeline and Notes {
」 vim: ts=8 sts=2 fdm=marker nowrap
」 vim: set foldmarker={,} foldlevel=0 :
」 }
 
」 Basics {
    」 配置改動時自動加載
    autocmd! bufwritepost vimrc source ~/.vimrc
    」 打開文件自動跳到上次編輯的位置
    au BufReadPost * if line(「‘\」") > 1 && line(「‘\」") <= line(「$」) | exe 「normal! g’\」" | endif
 
    set nocompatible 」 explicitly get out of vi-compatible mode
    set noexrc 」 don’t use local version of .(g)vimrc, .exrc
    set background=dark 」 we plan to use a dark background
    set cpoptions=aABceFsmq
    」             |||||||||
    」             ||||||||+– When joining lines, leave the cursor
    」             |||||||      between joined lines
    」             |||||||+– When a new match is created (showmatch)
    」             ||||||      pause for .5
    」             ||||||+– Set buffer options when entering the
    」             |||||      buffer
    」             |||||+– :write command updates current file name
    」             ||||+– Automatically add  to the last line
    」             |||      when using :@r
    」             |||+– Searching continues at the end of the match
    」             ||      at the cursor position
    」             ||+– A backslash has no special meaning in mappings
    」             |+– :write updates alternative file name
    」             +– :read updates alternative file name
    syntax on 」 syntax highlighting on
    set helplang=cn
」 }
 
」 General {
    filetype plugin indent on 」 load filetype plugins/indent settings
    set autochdir 」 always switch to the current file directory
    set backspace=indent,eol,start 」 make backspace a more flexible
    set nobackup 」 make backup files
」    set backupdir=~/.vim/backup 」 where to put backup files
    set clipboard+=unnamed 」 share windows clipboard
」    set directory=~/.vim/tmp 」 directory to place swap files in
    set fileformats=unix,dos,mac 」 support all three, in this order
    set hidden 」 you can change buffers without saving
    」 (XXX: #VIM/tpope warns the line below could break things)
    set iskeyword+=_,$,@,%,# 」 none of these are word dividers
    「set mouse=a 」 use mouse everywhere
    set mouse=
    set noerrorbells 」 don’t make noise
    set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize,slash,unix,resize
    set whichwrap=b,s,h,l,<,>,~,[,] 」 everything wraps
    」             | | | | | | | | |
    」             | | | | | | | | +– 「]」 Insert and Replace
    」             | | | | | | | +– 「[" Insert and Replace
    "             | | | | | | +-- "~" Normal
    "             | | | | | +--  Normal and Visual
    "             | | | | +--  Normal and Visual
    "             | | | +-- "l" Normal and Visual (not recommended)
    "             | | +-- "h" Normal and Visual (not recommended)
    "             | +--  Normal and Visual
    "             +--  Normal and Visual
    set wildmenu " turn on command line completion wild style
    " ignore these list file extensions
    set wildignore=*.dll,*.o,*.obj,*.bak,*.exe,*.pyc,
                    \*.jpg,*.gif,*.png
    set wildmode=list:longest " turn on wild mode huge list
    "設置鍵碼超時爲100ms,設置映射超時爲2000ms
    set timeout timeoutlen=2000 ttimeoutlen=100
    set tags+=./../tags,./../../tags,./../../../tags,./../../../../tags
" }
 
" Vim UI {
if has("autocmd")
  au InsertEnter * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
  au InsertLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block"
  au VimLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
endif
    colorscheme molokai
    set cursorcolumn " highlight the current column
    set cursorline " highlight current line
 
    set incsearch " BUT do highlight as you type you
                   " search phrase
    set laststatus=2 " always show the status line
    set lazyredraw " do not redraw while running macros
    set linespace=0 " don't insert any extra pixel lines
                     " betweens rows
    "set list " we do what to show tabs, to ensure we get them
             " out of my files
    "set listchars=tab:>-,trail:- " show tabs and trailing
    set matchtime=5 " how many tenths of a second to blink
                     " matching brackets for
    set nohlsearch " do not highlight searched for phrases
    set nostartofline " leave my cursor where it was
    set novisualbell " don't blink
    set number " turn on line numbers
    set numberwidth=5 " We are good up to 99999 lines
    set report=0 " tell us when anything is changed via :...
    set ruler " Always show current positions along the bottom
    set scrolloff=10 " Keep 10 lines (top/bottom) for scope
    set shortmess=aOstT " shortens messages to avoid
                         " 'press a key' prompt
    set showcmd " show the command being typed
    set showmatch " show matching brackets
    set sidescrolloff=10 " Keep 5 lines at the size
    "set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]
    set statusline=%F%m%r%h%w[%L][%{&ff}]%y[%p%%][%04l,%04v]
    」              | | | | |  |   |      |  |     |    |
    」              | | | | |  |   |      |  |     |    + current
    」              | | | | |  |   |      |  |     |       column
    」              | | | | |  |   |      |  |     +– current line
    」              | | | | |  |   |      |  +– current % into file
    」              | | | | |  |   |      +– current syntax in
    」              | | | | |  |   |          square brackets
    」              | | | | |  |   +– current fileformat
    」              | | | | |  +– number of lines
    」              | | | | +– preview flag in square brackets
    」              | | | +– help flag in square brackets
    」              | | +– readonly flag in square brackets
    」              | +– rodified flag in square brackets
    」              +– full path to file in the buffer
」 }
 
」 Text Formatting/Layout {
    set completeopt= 」 don’t use a pop up menu for completions
    set expandtab 」 no real tabs please!
    set formatoptions=rq 」 Automatically insert comment leader on return,
                          」 and let gq format comments
    set ignorecase 」 case insensitive by default
    set infercase 」 case inferred by default
    set nowrap 」 do not wrap line
    set shiftround 」 when at 3 spaces, and I hit > … go to 4, not 5
    set smartcase 」 if there are caps, go case-sensitive
    set shiftwidth=4 」 auto-indent amount when using cindent,
                      」 >>, << and stuff like that
    set softtabstop=4 」 when hitting tab or backspace, how many spaces
                       」should a tab be (see expandtab)
    set tabstop=8 」 real tabs should be 8, and they will show with
                   」 set list on
」 }
 
」 Folding {
    set foldenable 」 Turn on folding
    set foldmarker={,} 」 Fold C style code (only use this as default
                        」 if you use a high foldlevel)
    set foldmethod=marker 」 Fold on the marker
    set foldlevel=100 」 Don’t autofold anything (but I can still
                      」 fold manually)
    set foldopen=block,hor,mark,percent,quickfix,tag 」 what movements
                                                      」 open folds
    function! SimpleFoldText() 」 {
        return getline(v:foldstart).’ ‘
    endfunction 」 }
    set foldtext=SimpleFoldText() 」 Custom fold text function
                                   」 (cleaner than default)
」 }
 
」 Plugin Settings {
    」 TagList Settings {
        let Tlist_Auto_Open=0 」 let the tag list open automagically
        let Tlist_Compact_Format = 1 」 show small menu
        let Tlist_Ctags_Cmd = ‘ctags’ 」 location of ctags
        let Tlist_Enable_Fold_Column = 0 」 do show folding tree
        let Tlist_Show_One_File = 1            」不一樣時顯示多個文件的tag,只顯示當前文件的
        let Tlist_Exist_OnlyWindow = 1 」 if you are the last, kill
                                        」 yourself
        let Tlist_File_Fold_Auto_Close = 0 」 fold closed other trees
        let Tlist_Sort_Type = 「name」 」 order by
        let Tlist_Use_Right_Window = 1 」 split to the right side
                                        」 of the screen
        let Tlist_WinWidth = 30 」 40 cols wide, so i can (almost always)
                                 」 read my functions
        let Tlist_Auto_Highlight_Tag = 1
        「let Tlist_Auto_Update = 1
        let Tlist_Close_On_Select = 0
        let Tlist_Compact_Format = 0
        let Tlist_Display_Prototype = 0
        let Tlist_Display_Tag_Scope = 1
        let Tlist_Enable_Fold_Column = 0
        let Tlist_File_Fold_Auto_Close = 0
        let Tlist_GainFocus_On_ToggleOpen = 1
        let Tlist_Hightlight_Tag_On_BufEnter = 1
        let Tlist_Inc_Winwidth = 0
        let Tlist_Max_Submenu_Items = 1
        let Tlist_Max_Tag_Length = 30
        let Tlist_Process_File_Always = 0
        let Tlist_Show_Menu = 0
        let Tlist_Sort_Type = 「order」
        let Tlist_Use_Horiz_Window = 0
 
        」 Language Specifics {
            」 just functions and classes please
            let tlist_aspjscript_settings = ‘asp;f:function;c:class’
            」 just functions and subs please
            let tlist_aspvbs_settings = ‘asp;f:function;s:sub’
            」 don’t show variables in freaking php
            let tlist_php_settings = ‘php;c:class;d:constant;f:function’
            」 just functions and classes please
            let tlist_vb_settings = ‘asp;f:function;c:class’
            」 }
        」 }
    」 lookupfile setting {
        let g:LookupFile_MinPatLength = 2               「最少輸入2個字符纔開始查找
        let g:LookupFile_PreserveLastPattern = 0        」不保存上次查找的字符串
        let g:LookupFile_PreservePatternHistory = 1     「保存查找歷史
        let g:LookupFile_AlwaysAcceptFirst = 1          」回車打開第一個匹配項目
        let g:LookupFile_AllowNewFiles = 0              」不容許建立不存在的文件
        if filereadable(「./filenametags」)                」設置tag文件的名字
            let g:LookupFile_TagExpr = ‘」./filenametags」‘
        endif
        」 }
    」 Nerdtree settings {
    」 讓Tree把本身給裝飾得多姿多彩漂亮點
    let NERDChristmasTree=1
    」 控制當光標移動超過必定距離時,是否自動將焦點調整到屏中心
    let NERDTreeAutoCenter=1
    」 指定書籤文件
    let NERDTreeBookmarksFile=$VIMFILES.’\NERDTree_bookmarks’
    」 指定鼠標模式(1.雙擊打開 2.單目錄雙文件 3.單擊打開)
    let NERDTreeMouseMode=2
    」 是否默認顯示書籤列表
    let NERDTreeShowBookmarks=1
    」 是否默認顯示文件
    let NERDTreeShowFiles=1
    」 是否默認顯示隱藏文件
    let NERDTreeShowHidden=1
    」 是否默認顯示行號
    let NERDTreeShowLineNumbers=0
    」 窗口位置(’left’ or ‘right’)
    let NERDTreeWinPos=’left’
    」 窗口寬度
    let NERDTreeWinSize=31
」 }
」 }
 
」 Map settings {
    」 自定義的鍵映射 {
    let mapleader = 「,」
    let g:mapleader = 「,」
    nnoremap e :e ~/.vimrc
    」 }
 
    」 摺疊相關的快捷鍵 {
    「zR 打開全部的摺疊
    「za Open/Close (toggle) a folded group of lines.
    「zA Open a Closed fold or close and open fold recursively.
    「zi 所有 展開/關閉 摺疊
    「zo 打開 (open) 在光標下的摺疊
    「zc 關閉 (close) 在光標下的摺疊
    「zC 循環關閉 (Close) 在光標下的全部摺疊
    「zM 關閉全部可摺疊區域
    」 }
 
    」 實現了CTRL-C、CTRL-V複製粘貼,CTRL-S保存操做的映射 {
    vnoremap  「+y
    inoremap  」+pi
    imap  :w
」 }
 
    」 F12取消高亮 {
    map   :nohlsearch
    」 }
 
    」 使用CTRL+[hjkl]在窗口間導航 map  j {
    nnoremap  k
    nnoremap  h
    nnoremap  l
    nnoremap  j
」 }
 
    」 使用CTRL+[kj]在插入模式下的上下移動 map     {
    inoremap  
    inoremap  
    inoremap  
    inoremap  
」 }
 
    」 使用箭頭導航buffer {
    map  :bn
    map  :bp
」 }
 
    」 標籤頁的操做 {
    map tn :tabnew
    map te :tabedit
    map tc :tabclose
    map tm :tabmove
」 }
 
    」 括號匹配 {
    「vnoremap $1 `>a)`<i(
    「vnoremap $2 `>a]`<i[
    "vnoremap $3 `>a}`<i{
    "vnoremap $$ `>a"`<i"
    "vnoremap $q `>a'`<i'
    "vnoremap $e `>a"`<i"
    " 很是好用的括號匹配,實際是自動生成括號
    " 實現便利和兼容的折中
    "inoremap $1 ()i
    "inoremap $2 []i
    「inoremap $3 {}i
    「inoremap $4 {o}O
    「inoremap $q 」i
    「inoremap $e 「」i
    「inoremap $t <>i
」 }
 
    」 taglist plugin maps {
    nnoremap tl :TlistToggle
」 }
 
    」 lookup plugin maps {
    「映射LookupFile爲,lk
    nmap  lk :LUTags
    「映射LUBufs爲,ll
    nmap  ll :LUBufs
    「映射LUWalk爲,lw
    nmap  lw :LUWalk
」 nerdtree plugin maps
    nnoremap tt :NERDTree
」 }
 
    」 註釋映射 {
    nnoremap //   i/* [ jcli : =strftime("%Y-%m-%d %H:%M:%S") ]  */
」 }
 
    」 freepbx {
    nnoremap ,fr oecho 「\n[]「.__FILE__.」:」.__LINE__.」:\n」;
    nnoremap ,ftag :set tags=/usr/local/src/freepbx-2.9.0/tags
        」 }
 
    」 在當前目錄加載或卸載tags文件 {
    」 cta 加載tags
    」 ctd 卸載tags
    map cta :call Add_tags()
    map ctd :call Del_tags()
    function! Add_tags()
       let dir =expand(「%:p:h」)
       let curtags = dir.」/tags」
       let curtags=substitute(curtags,’\\’,'\’,'g’)
       if filereadable(curtags)
           exec 「set tags+=」.curtags
           echohl WarningMsg | echo 「Succ to add tags![".curtags."]」 | echohl None
       else
           echohl WarningMsg | echo 「Fail to add tags! No tags in this file’s path.[".curtags."]」 | echohl None
       endif
    endfunction
    function! Del_tags()
       let dir =expand(「%:p:h」)
       let curtags = dir.」/tags」
       let curtags=substitute(curtags,’\\’,'\’,'g’)
       exec 「set tags-=」.curtags
       if filereadable(curtags)
           echohl WarningMsg | echo 「Succ to del tags![".curtags."]」 | echohl None
       else
           echohl WarningMsg | echo 「Succ to del tags! But no tags in this file’s path.[".curtags."]」 | echohl None
       endif
    endfunction
    」 }
 
    」 根據狀態改變光標顏色 {
」    let color_normal = ‘HotPink’
」    let color_insert = ‘RoyalBlue1′
」    let color_exit = ‘green’
」    if &term =~ ‘xterm\|rxvt’
」      exe ‘silent !echo -ne 「\e]12;」‘ . shellescape(color_normal, 1) . ‘」\007″‘
」      let &t_SI=」\e]12;」 . color_insert . 「\007″
」      let &t_EI=」\e]12;」 . color_normal . 「\007″
」      exe ‘autocmd VimLeave * :silent !echo -ne 「\e]12;」‘ . shellescape(color_exit, 1) . ‘」\007″‘
」    elseif &term =~ 「screen」
」      if exists(‘$TMUX’)
」 if &ttymouse == ‘xterm’
」 set ttymouse=xterm2
」 endif
」 exe ‘silent !echo -ne 「\033Ptmux;\033\e]12;」‘ . shellescape(color_normal, 1) . ‘」\007\033\\」‘
」 let &t_SI=」\033Ptmux;\033\e]12;」 . color_insert . 「\007\033\\」
」 let &t_EI=」\033Ptmux;\033\e]12;」 . color_normal . 「\007\033\\」
」 exe ‘autocmd VimLeave * :silent !echo -ne 「\033Ptmux;\033\e]12;」‘ . shellescape(color_exit, 1) . ‘」\007\033\\」‘
」      elseif !exists(‘$SUDO_UID’) 」 or it may still be in tmux
」 exe ‘silent !echo -ne 「\033P\e]12;」‘ . shellescape(color_normal, 1) . ‘」\007\033\\」‘
」 let &t_SI=」\033P\e]12;」 . color_insert . 「\007\033\\」
」 let &t_EI=」\033P\e]12;」 . color_normal . 「\007\033\\」
」 exe ‘autocmd VimLeave * :silent !echo -ne 「\033P\e]12;」‘ . shellescape(color_exit, 1) . ‘」\007\033\\」‘
」      endif
」    endif
」    unlet color_normal
」    unlet color_insert
」    unlet color_exit
」   」 }
「
」 }
相關文章
相關標籤/搜索