我的vim linux下配置

來源:互聯網
上載者:User

"*******************************************
"全域條件
"*******************************************
"設定作業系統
if has("win32") || has("win64") || has("win32unix")
    let g:isWin = 1
    let $VIMFILES = $VIM.'/vimfiles'
else
    let g:isWin = 0
    let $VIMFILES = $HOME.'/.vim'
endif

"*******************************************
"常規
"*******************************************

"檔案編碼
"set encoding=utf-8
set fileencodings=ucs-bom,utf-8,gbk
set fileencoding=utf-8
"檔案類型識別,添加相互關聯類型的外掛程式和縮排指令碼
"filetype on
"filetype plugin on
filetype plugin indent on
"設定檔案格式
set fileformat=unix
set fileformats=unix
"設定shell
if g:isWin == 0
    set shell=bash
endif
"會話設定
set sessionoptions+=slash,unix 
"關閉相容模式
set nocompatible
"外部修改時自動讀取
set autoread
"設定滑鼠
set mouse=a
"設定曆史
set history=200
"文法高亮
syntax enable
"尋找結果高亮
set hlsearch
" 超過當前行長度的行會迴繞
set wrap

"行號設定
set nu
"智慧縮排,ts tabstop 轉換tab鍵為空白格來顯示,主要用於螢幕顯示和列印, 
"如果頁面全部用的tab,在tabstop=4和tabstop=8的地方頁面顯示的寬度是不同的
"sts softtabstop 在編輯的時候轉換tab為空白格的數量,需要和expandtab一起用
"et expandtab 在插入模式裡插入tab時使用合適數量的空格代替
"sw shiftwidth 自動縮排每一步時使用的空白數目
set ai ts=4 sts=4 et sw=4
"設定色彩方案
if has("gui_running")
    colorscheme desertEx
else
    colorscheme desert
endif

"改變vim掃描標籤的規則
"vim預設的補全順序是 ".,w,b,u,t,i",它意味著掃描:
"1. 當前緩衝區 . 
"2. 其它視窗的緩衝區 window??
"3. 其它載入的緩衝區 b ... 
set cpt=.,w,b

"自動儲存檔案 autowrite
set aw

"搜尋時忽略大小寫
set ignorecase
"set ic

"增強命令列補全, type :h and press <Tab> to look what happens
set wildmenu

" 允許在未儲存的情況下切換緩衝
set hid

" 報告行為發生後改變的行數
set report=0

" 當游標移動時顯示的最小數量的螢幕行數
set scrolloff=10 

" 設定響鈴和閃屏
set novisualbell t_vb=

" 設定錯誤響
set noerrorbells

"載入系統特定的指令碼
"source $VIMRUNTIME/vimrc_example.vim
if g:isWin == 1
    source $VIMRUNTIME/mswin.vim
    behave mswin
endif

" Use CTRL-Q to do what CTRL-V used to do
noremap <C-Q> <C-V>

set ambiwidth=double
set smarttab
set backspace=2
set textwidth=0

"解決補全下無法使用tab問題
map! <c-tab> <tab>

"設定不備份
set nobackup
"設定開啟檔案的編碼
"設定檔案開啟時的編碼猜測列表
"set fencs=utf-8,gb18030,utf-16,big5
"設定大於603版本時的協助語言
if version >= 603
    set helplang=cn
endif

" 重啟後撤銷曆史可用 persistent undo 
set undofile
set undodir=$VIMFILES/\_undodir
set undolevels=100 "maximum number of changes that can be undone

" Ctrl-C的複製
vmap <C-C> "+y
imap <C-C> "+y
map <C-C> "+y
vmap <C-Insert> "+y

" Ctrl-V的粘貼
" CTRL-X and SHIFT-Del are Cut
vnoremap <C-X> "+x
vnoremap <S-Del> "+x

" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y

" CTRL-V and SHIFT-Insert are Paste
map <C-V> "+gP
map <S-Insert> "+gP

cmap <C-V> <C-R>+
cmap <S-Insert> <C-R>+

" Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature.  They are pasted as if they
" were characterwise instead.
" Uses the paste.vim autoload script.

exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']

"nmap <C-v> "+gP
"vmap <C-v> d"+gP<cr>
"imap <C-v> <esc>"+gP
"map <C-v> "+gP
"map <C-V> "+gP
"map <S-Insert> "+gP
"cmap <C-V>  <C-R>+
"cmap <S-Insert> <C-R>+
"exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
"exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
"imap <S-Insert>  <C-V>
"vmap <S-Insert>  <C-V>

" 內容全選快速鍵
map <C-a> gg0vG$<cr>

" 設定tags
set tags+=./tags

" 設定取消swapfile
set noswapfile

"*******************************
"設定Tlist
"*******************************
let Tlist_Ctags_Cmd='ctags' "因為我們放在環境變數裡,所以可以直接執行
let Tlist_Process_File_Always=0 "是否一直處理tags.1:處理;0:不處理。不是一直即時更新tags,因為沒有必要
let Tlist_Show_One_File=1
" 如果 taglist 視窗是最後一個視窗,則退出 vim
let Tlist_Exit_OnlyWindow=1
let Tlist_Show_Menu=1
let Tlist_WinHeight=25
let Tlist_Use_Right_Window=1
let Tlist_File_Fold_Auto_Close=1
"tasklist
"map T :TaskList<CR>
nmap <silent> <F4> :TlistToggle<CR>

"*******************************
" 設定Winmanager
"*******************************

"WinManager
"let g:winManagerWindowLayout='NERDTree|TagList'
"let g:winManagerWindowLayout = 'NERDTree'
""設定winmanager的寬度,預設為25
"let g:winManagerWidth = 30
"nmap <F8> :WMToggle<cr>
"let g:AutoOpenWinManager = 1 

"*******************************
"  設定MiniBufExplorer
"*******************************
"let g:miniBufExplMapWindowNavVim = 1 
"let g:miniBufExplMapWindowNavArrows = 1 
"let g:miniBufExplMapCTabSwitchBufs = 1 
"let g:miniBufExplModSelTarget = 1
"map! <c-tab> :bn<cr>
map! <c-s-tab> :bp<cr>
" miniBuf always show
"let g:miniBufExplorerMoreThanOne=0

"*****************************
" BufExplorer
"*****************************

"let g:bufExplorerDefaultHelp=0       " Do not show default help.
"let g:bufExplorerShowRelativePath=1  " Show relative paths.
"let g:bufExplorerSortBy='mru'        " Sort by most recently used.
"let g:bufExplorerSplitRight=0        " Split left.
"let g:bufExplorerSplitVertical=1     " Split vertically.
"let g:bufExplorerSplitVertSize = 30  " Split width
"let g:bufExplorerUseCurrentWindow=1  " Open in new window.
"autocmd BufWinEnter \[Buf\ List\] setl nonumber 

"*****************************
" set Grep
"*****************************
if g:isWin == 1
    let Grep_Path = 'D:/GnuWin32/bin/grep.exe'
    let FGrep_Path = 'D:/GnuWin32/bin/fgrep.exe'
    let EGrep_Path = 'D:/GnuWin32/bin/egrep.exe'
endif
    
nnoremap <silent> <F3> :Grep<cr>

" *******************
" NERDTree set
" *******************

" set NERDTree curent dir
if g:isWin == 1
   cd d:\
else
   cd /home/zhaoyong
endif

" 切換到目前的目錄
"map <leader>cd :cd %:p:h<cr>

let g:NERDTree_title = "[NERD Tree]"
let NERDTreeShowBookmarks=1 "一直顯示書籤
let NERDTreeChDirMode=2 "開啟書籤時,自動將Vim的pwd設為開啟的目錄,如果你的項目有tags檔案,你會發現這個命令很有協助

function! NERDTree_Start()
    exe 'NERDTree'
endfunction

function! NERDTree_IsValid()
    return 1
endfunction 

nmap <silent> <F2> :NERDTreeToggle<CR>

"nmap <F4> :NERDTree  <CR>

" *******************
" FuzzyFinder
" *******************
let g:fuf_modesDisable = []
let g:fuf_mrufile_maxItem = 400
let g:fuf_mrucmd_maxItem = 400
let g:fuf_keyOpen = '<CR>'
let g:fuf_keyOpenSplit = '<C-j>'
let g:fuf_keyOpenTabpage = '<C-l>'
let g:fuf_dataDir = $VIMFILES . "/fuf_data"

"Key map for FuzzyFinder                                                       
let mapleader=","
map <leader>ff :FufFile<cr>
map <leader>fb :FufBuffer<cr>

" *******************
" php languange set "
" *******************

" set php document
fun! SetPhp()
    if &filetype=="php"
        if g:isWin == 1
            set runtimepath+=d:\program\ Files\Vim\php_doc
        else
            set runtimepath+=/home/zhaoyong/.vim/php_doc
        endif
    endif
    autocmd BufWritePost *.php :!php -l %<CR>
endfun
autocmd BufRead,BufNewFILe *.php,*.phtml call SetPhp()
 

" *******************
" python language set 
" *******************
fun! SetPython()
    if g:isWin==1
        " set python document
        let g:pyref_python = 'D:\program files\Vim\python-html'
        "Pydiction
        let g:pydiction_location='D:\Program Files\Vim\vim73\ftplugin\pydiction\complete-dict'
    else
        let g:pyref_python = '/home/zhaoyong/.vim/python-html'
        let g:pydiction_location='/home/zhaoyong/.vim/pydiction/complete-dict'
    endif
    if &filetype=="python" 
        " exec python
        map <F6> :!python %

        " pythoncomplete c-x c-o

    endif
endfun
autocmd BufRead,BufNewFILe *.py call SetPython()

" *******************
" c/c++ language set 
" *******************
fun! SetCLang()
    if &filetype=="c" || &filetype=="cpp"
        set tags+=$VIMFILES/libstdc++/tags

        " omnicomplete plugin
        let OmniCpp_NamespaceSearch = 1
        let OmniCpp_GlobalScopeSearch = 1
        let OmniCpp_ShowAccess = 1
        let OmniCpp_ShowPrototypeInAbbr = 1 " 顯示函數參數列表
        let OmniCpp_MayCompleteDot = 1   " 輸入 .  後自動補全
        let OmniCpp_MayCompleteArrow = 1 " 輸入 -> 後自動補全
        let OmniCpp_MayCompleteScope = 1 " 輸入 :: 後自動補全
        let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
        " 自動關閉補全視窗
        au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
        set completeopt=menuone,menu,longest"
    endif
    if &filetype == 'c' || &filetype == 'cpp'
        inoremap [ []<esc>:let leavechar="]"<cr>i
        inoremap { {<esc>o}<esc>:let leavechar="}"<cr>O
        inoremap { {}<esc>:let leavechar="}"<cr>i
        inoremap ( ()<esc>:let leavechar=")"<cr>i
        inoremap ' ''<esc>:let leavechar="'"<cr>i
        inoremap " ""<esc>:let leavechar='"'<cr>i
        "au BufNewFile,BufRead *.\(vim\)\@! inoremap " ""<esc>:let leavechar='"'<cr>i
        "au BufNewFile,BufRead *.\(txt\)\@! inoremap ' ''<esc>:let leavechar="'"<cr>i
        "imap <m-l> <esc>:exec "normal f" . leavechar<cr>a
        "imap <d-l> <esc>:exec "normal f" . leavechar<cr>
    endif
endfun
autocmd BufRead,BufNewFILe *.c,*.h,*.cpp call SetCLang()

" *******************
" plugin gdb 
" *******************
run macros/gdb_mappings.vim

" *******************
" plugin MRU
" manage recently used files
" *******************
if g:isWin == 1
    let MRU_File = 'd:\myhome\_vim_mru_files'
else
    let MRU_File = '/home/zhaoyong/.vim/mru_files'
endif

" *******************
" SVN set
" *******************
"更新目前的目錄的代碼
"map <F6>    :!svn up <cr>
"提交SVN(目前的目錄)
"map <F7>    :!svn ci -m "" 
"提交SVN(當前檔案)
"map <F8>    :!svn ci -m "" %

" *******************
" supertab set
" *******************
"let g:SuperTabRetainCompletionType=2
"let g:SuperTabDefaultCompletionType="<C-X><C-O>"

" syntax highlight function
function! ToggleSyntax()
    if exists("g:syntax_on")
        syntax off
    else
        syntax enable
    endif
endfunction

" 快速編輯vimrc檔案的快速鍵
if g:isWin == 1
    map <silent> <leader>e :e d:\program files\vim\_vimrc<cr>
    " 當vimrc已經儲存後重載vimrc
    autocmd! bufwritepost *.vimrc source d:\program files\vim\_vimrc
else
    map <silent> <leader>e :e ~/.vimrc<cr>
    " 當vimrc已經儲存後重載vimrc
    autocmd! bufwritepost *.vimrc source ~/.vimrc
endif

" 設定當前工作目錄為buf檔案的目錄
autocmd BufEnter * lcd %:p:h

" 在vim退出前自動儲存session
"if g:isWin == 0
    "let s:path='/home/zhaoyong/.vim/Session.vim'
"else
    "let s:path='d:\program files\vim\Session.vim'
"endif

if g:isWin == 0 && has("gui_running")
    " 當退出vim時候關閉minibuf,NERDTree,Tlist
    "autocmd VimLeave * \mbt
    autocmd VimLeave * NERDTreeClose
    autocmd VimLeave * TlistClose
    " 儲存會話
    "autocmd VimLeave * exe "mksession! " . s:path
"    " 啟動自動載入會話
    "autocmd VimEnter * exe "source " . s:path
endif

" show the correct man help info
if has("gui_running")
    runtime ftplugin/man.vim
    nmap K :Man <cword><cr>
endif

" 使用CTRL+w 關閉當前緩衝
"map <silent> <C-W> <C-k> d <cr> <C-j>
" 建立一個標籤
map <silent> <C-N> :enew<cr>

" 建立一個tab頁
map <silent> <C-t> :tabnew<cr>

map <silent> <C-s> :w<cr>
imap <silent> <C-s> <esc>:w<cr>

" 啟動時已最大化的視窗
"au GUIEnter * simalt ~x
autocmd GUIEnter * winpos 0 0 | set lines=999 columns=9999

" 關閉當前的buf
map <silent> qq :bd<cr>

" 清理搜尋高亮
map <silent> nhl /axkexiej<cr>

" 注釋的映射鍵
let mapleader=","
map <silent> <leader>l :call NERDComment(0, "toggle")<cr> 
map <silent> <leader>k :call NERDComment(0, "sexy")<cr> 

" 映射 第一行和最後一行
map <silent> <leader>1 1G
map <silent> <leader>g GG

" 括弧自動補全
" map auto complete
"inoremap ( ()<esc>:let leavechar=")"<cr>i

" 設定狀態行
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v]\ [%p%%]
set laststatus=2

" 高亮顯示光線標所在行
"set cursorline
set nocul

" toggle菜單和工具條
map <silent> <C-F2> :if &guioptions =~# 'T' <Bar>
                        \set guioptions-=T <Bar>
                        \set guioptions-=m <Bar>
                    \else <Bar>
                        \set guioptions+=T <Bar>
                        \set guioptions+=m <Bar>
                    \endif<CR>
                
" 設定tab短標籤名
function! ShortTabLabel()
    let bufnrlist = tabpagebuflist(v:lnum)
    " show only the first 6 letters of the name + ..
    let label = bufname(bufnrlist[tabpagewinnr(v:lnum) – 1])
    let filename = fnamemodify(label,':h')
    " only add .. if string is more than 8 letters
    if strlen(filename) >=8
        let ret=filename[0:5].'..'
    else
        let ret = filename
    endif
    return ret
endfunction

" 簡單實現滑鼠提示功能
function! SimpleBallon()
    return 'Cursor is at line/column: ' . v:beval_lnum . 
        \'/' . v:beval_col .
        \ ' in file ' . bufname(v:beval_bufnr) .
        \ '. word under cursor is: "' . v:beval_text . '"'
endfunction
"set balloonexpr=SimpleBallon()
"set ballooneval

" cscope
map <F12> :call Do_CsTag()<CR>
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
function! Do_CsTag()
    let dir = getcwd()
    if filereadable("tags")
        if(g:isWin==1)
            let tagsdeleted=delete(dir."\\"."tags")
        else
            let tagsdeleted=delete("./"."tags")
        endif
        if(tagsdeleted!=0)
            echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
            return
        endif
    endif
    if has("cscope")
        silent! execute "cs kill -1"
    endif
    if filereadable("cscope.files")
        if(g:isWin==1)
            let csfilesdeleted=delete(dir."\\"."cscope.files")
        else
            let csfilesdeleted=delete("./"."cscope.files")
        endif
        if(csfilesdeleted!=0)
            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
            return
        endif
    endif
    if filereadable("cscope.out")
        if(g:isWin==1)
            let csoutdeleted=delete(dir."\\"."cscope.out")
        else
            let csoutdeleted=delete("./"."cscope.out")
        endif
        if(csoutdeleted!=0)
            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
            return
        endif
    endif
    if(executable('ctags'))
        "silent! execute "!ctags -R --c-types=+p --fields=+S *"
        silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
    endif
    if(executable('cscope') && has("cscope") )
        if(g:isWin!=1)
            silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
        else
            silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
        endif
        silent! execute "!cscope -b"
        execute "normal :"
        if filereadable("cscope.out")
            execute "cs add cscope.out"
        endif
    endif
endfunction

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.