天天看點

VIM配置模版

<code><code><code> set nocompatible            " 關閉 vi 相容模式 syntax on                   " 自動文法高亮 set number                  " 顯示行号 set ruler                   " 打開狀态欄标尺 set shiftwidth=4            " 設定 &lt;&lt; 和 &gt;&gt; 指令移動時的寬度為 4 set textwidth=80            " 設定每行80個字元自動換行 set fo+=mm                  " 中文40個字換行 set autoread                " 當檔案被外部編輯器更改後,自動載入 set autoindent              " 繼承前一行的縮進方式,特别适用于多行注釋 set softtabstop=4           " 使得按倒退鍵時可以一次删掉 4 個空格 set tabstop=4               " 設定 tab 長度為 4 set nobackup                " 覆寫檔案時不備份 set autochdir               " 自動切換目前目錄為目前檔案所在的目錄 filetype plugin indent on   " 開啟插件 set backupcopy=yes          " 設定備份時的行為為覆寫 set ignorecase smartcase    " 搜尋時忽略大小寫,但在有一個或以上大寫字母時仍保持對大小寫敏感 set nowrapscan              " 禁止在搜尋到檔案兩端時重新搜尋 set incsearch               " 輸入搜尋内容時就顯示搜尋結果 set hlsearch                " 搜尋時高亮顯示被找到的文本 set noerrorbells            " 關閉錯誤資訊響鈴 set history=80              " 記錄曆史指令行數 set iskeyword+=_,$,@,%,#,-  " 帶有_,$,@,%,#,-這些字元的串,不被換行分割 set mouse=a                 " 設定滑鼠一直可用 set shortmess=ati           " 啟動的時候不顯示那個援助索馬裡兒童的提示 set novisualbell            " 關閉使用可視響鈴代替呼叫 set t_vb=                   " 置空錯誤鈴聲的終端代碼 set noswapfile              " 禁用swap檔案 " set showmatch             " 插入括号時,短暫地跳轉到比對的對應括号 " set matchtime=2           " 短暫跳轉到比對括号的時間 set magic                   " 設定魔術 set hidden                  " 允許在有未儲存的修改時切換緩沖區,此時的修改由 vim 負責儲存 set smartindent             " 開啟新行時使用智能自動縮進 set backspace=indent,eol,start                             " 不設定在插入狀态無法用倒退鍵和 delete 鍵删除回車符 set cmdheight=1             " 設定指令行的行數為 1 set laststatus=2            " 顯示狀态欄 (預設值為 1, 無法顯示狀态欄) set statusline=\ %&lt;%f[%1*%m%*%n%r%h]%=\ %y\ %0(%{&amp;fileformat}\ %{&amp;encoding}\ %c:%l/%l%)\                             " 設定在狀态行顯示的資訊 set foldenable              " 開始折疊 set foldmethod=syntax       " 設定文法折疊 set foldcolumn=0            " 設定折疊區域的寬度 setlocal foldlevel=1        " 設定折疊層數為 " set foldclose=all           " 設定為自動關閉折疊                            " nnoremap &lt;space&gt; @=((foldclosed(line(‘.‘)) &lt; 0) ? ‘zc‘ : ‘zo‘)&lt;cr&gt;                             " 用空格鍵來開關折疊 colorscheme desert          " 設定配色方案 if has("gui_running")     "au guienter * simalt ~x  " 視窗啟動時自動最大化     "set guioptions-=m      " 隐藏菜單欄     set guioptions-=t       " 隐藏工具欄     set guioptions-=l       " 隐藏左側滾動條     set guioptions-=r       " 隐藏右側滾動條     set guioptions-=b       " 隐藏底部滾動條     "set showtabline=0      " 隐藏tab欄     "set cursorline         " 突出顯示目前行     colorscheme default     " 設定配色方案     winpos 250 80           "視窗位置     set lines=30 columns=100    "視窗大小     set textwidth=80 endif   "傳回作業系統類型(windows, linux等) function! mysys()     if has("win16") || has("win32") || has("win64") || has("win95")         return "windows"     elseif has("unix")         return "linux"     endif endfunction   " 使用者目錄變量$vimfiles <b>if</b> mysys() == "windows"     let $vimfiles = $vim.‘/vimfiles‘ elseif mysys() == "linux"     let $vimfiles = $home.‘/.vim‘ endif   " 設定doc文檔目錄 let helptags=$vimfiles.‘/doc‘   "設定中文幫助文檔 <b>if</b> version &gt;= 603     set helplang=cn endif   " 設定字型 以及中文支援 if has("win32") || has("win64")     set guifont=courier_new:h10:cansi:b elseif has("unix")     set guifont=courier\ 10\ pitch\ 10 endif   " 配置多語言環境 <b>if</b> has("multi_byte")     " utf-8 編碼     set encoding=utf-8     set termencoding=utf-8     set formatoptions+=mm     set fencs=utf-8,gbk       if v:lang =~? ‘^\(zh\)\|\(ja\)\|\(ko\)‘         set ambiwidth=double     endif       if has("win32")         source $vimruntime/delmenu.vim         source $vimruntime/menu.vim         language messages zh_cn.utf-8     endif else     echoerr "sorry, this version of (g)vim was not compiled with +multi_byte" endif   " buffers操作快捷方式! nnoremap &lt;c-return&gt; :bnext&lt;cr&gt; nnoremap &lt;c-s-return&gt; :bprevious&lt;cr&gt;   " tab操作快捷方式! nnoremap &lt;c-tab&gt; :tabnext&lt;cr&gt; nnoremap &lt;c-s-tab&gt; :tabprev&lt;cr&gt;   "視窗分割時,進行切換的按鍵熱鍵需要連接配接兩次,比如從下方視窗移動 "光标到上方視窗,需要&lt;c-w&gt;&lt;c-w&gt;k,非常麻煩,現在重映射為&lt;c-k&gt;,切換的 "時候會變得非常友善. nnoremap &lt;c-h&gt; &lt;c-w&gt;h nnoremap &lt;c-j&gt; &lt;c-w&gt;j nnoremap &lt;c-k&gt; &lt;c-w&gt;k nnoremap &lt;c-l&gt; &lt;c-w&gt;l   "一些不錯的映射轉換文法(如果在一個檔案中混合了不同語言時有用) nnoremap &lt;leader&gt;1 :set filetype=xhtml&lt;cr&gt; nnoremap &lt;leader&gt;2 :set filetype=css&lt;cr&gt; nnoremap &lt;leader&gt;3 :set filetype=javascript&lt;cr&gt; nnoremap &lt;leader&gt;4 :set filetype=php&lt;cr&gt;   set fileformats=unix,dos,mac " nmap &lt;leader&gt;fd :se fileformat=dos&lt;cr&gt; " nmap &lt;leader&gt;fu :se fileformat=unix&lt;cr&gt;   " use ctrl+[l|n|p|cc] to list|next|previous|jump to count the result " map &lt;c-x&gt;l &lt;esc&gt;:cl&lt;cr&gt; " map &lt;c-x&gt;n &lt;esc&gt;:cn&lt;cr&gt; " map &lt;c-x&gt;p &lt;esc&gt;:cp&lt;cr&gt; " map &lt;c-x&gt;c &lt;esc&gt;:cc&lt;cr&gt;     " 讓 tohtml 産生有 css 文法的 html " syntax/2html.vim,可以用:runtime! syntax/2html.vim let html_use_css=0   " python 檔案的一般設定,比如不要 tab 等 autocmd filetype python set tabstop=4 shiftwidth=4 expandtab autocmd filetype python map &lt;f12&gt; :!python %&lt;cr&gt;   " 選中狀态下 ctrl+c 複制 vmap &lt;c-c&gt; "+y   " 打開javascript折疊 let b:javascript_fold=1 " 打開javascript對dom、html和css的支援 let javascript_enable_domhtmlcss=1       "----------------------------------------------------------------- ""括号自動補全 "----------------------------------------------------------------- :inoremap " ""&lt;esc&gt;i :inoremap ( ()&lt;esc&gt;i :inoremap ) &lt;c-r&gt;=closepair(‘)‘)&lt;cr&gt; :inoremap { {}&lt;esc&gt;i :inoremap } &lt;c-r&gt;=closepair(‘}‘)&lt;cr&gt; :inoremap [ []&lt;esc&gt;i :inoremap ] &lt;c-r&gt;=closepair(‘]‘)&lt;cr&gt; ":inoremap &lt; &lt;&gt;&lt;esc&gt;i ":inoremap &gt; &lt;c-r&gt;=closepair(‘&gt;‘)&lt;cr&gt;   function closepair(char) <b>if</b> getline(‘.‘)[col(‘.‘) - 1] == a:char return "\&lt;right&gt;" <b>else</b> return a:char endif endf     "----------------------------------------------------------------- " plugin – checksyntax.vim    javascript常見文法錯誤檢查 " 預設快捷方式為 f5 "----------------------------------------------------------------- let g:checksyntax_auto = 0 " 不自動檢查   "----------------------------------------------------------------- "plugin - bashsupport "----------------------------------------------------------------- let g:bash_author = ‘wlxxsj‘ let g:bash_email = ‘[email protected]‘ let g:bash_organization = ‘open source corporation‘     "----------------------------------------------------------------- " plugin - nerd_tree.vim 以樹狀方式浏覽系統中的檔案和目錄 " :erdtree 打開nerd_tree         :nerdtreeclose    關閉nerd_tree " o 打開關閉檔案或者目錄         t 在标簽頁中打開 " t 在背景标簽頁中打開           ! 執行此檔案 " p 到上層目錄                   p 到根目錄 " k 到第一個節點                 j 到最後一個節點 " u 打開上層目錄                 m 顯示檔案系統菜單(添加、删除、移動操作) " r 遞歸重新整理目前目錄             r 遞歸重新整理目前根目錄 "----------------------------------------------------------------- " f3 nerdtree 切換 map &lt;f3&gt; :nerdtreetoggle&lt;cr&gt; imap &lt;f3&gt; &lt;esc&gt;:nerdtreetoggle&lt;cr&gt;     " enable omni completion. autocmd filetype css setlocal omnifunc=csscomplete#completecss autocmd filetype html,markdown setlocal omnifunc=htmlcomplete#completetags autocmd filetype javascript setlocal omnifunc=javascriptcomplete#completejs autocmd filetype python setlocal omnifunc=pythoncomplete#complete autocmd filetype xml setlocal omnifunc=xmlcomplete#completetags autocmd filetype java setlocal omnifunc=javacomplete#complete autocmd filetype ruby setlocal omnifunc=rubycomplete#complete     " ======= 編譯 &amp;&amp; 運作 ======= " " 編譯c源檔案 func! compilegcc()     exec "w"     let compilecmd="!gcc -wall -pedantic -std=c99 "     let compileflag="-o %&lt;"     exec compilecmd." % ".compileflag endfunc " 編譯c++源檔案 func! compilecpp()     exec "w"     let compilecmd="!g++ -wall -pedantic -std=c++98 "     let compileflag="-o %&lt;"     exec compilecmd." % ".compileflag endfunc " 編譯java源檔案 func! compilejava()     exec "w"     exec "!javac %" endfunc " 根據檔案類型自動選擇相應的編譯函數 func! compilecode()         exec "w"         <b>if</b> &amp;filetype == "c"             exec "call compilegcc()"         elseif &amp;filetype == "cpp"             exec "call compilecpp()"         elseif &amp;filetype == "java"             exec "call compilejava()"         elseif &amp;filetype == "lua"             exec "!lua %&lt;.lua"         elseif &amp;filetype == "perl"             exec "!perl %&lt;.pl"         elseif &amp;filetype == "python"             exec "!python %&lt;.py"         elseif &amp;filetype == "ruby"             exec "!ruby %&lt;.rb"         endif endfunc " 運作可執行檔案 func! runresult()         exec "w"         if &amp;filetype == "c"             exec "! %&lt;"         elseif &amp;filetype == "cpp"             exec "! %&lt;"         elseif &amp;filetype == "java"             exec "!java %&lt;"         elseif &amp;filetype == "lua"             exec "!lua %&lt;.lua"         elseif &amp;filetype == "perl"             exec "!perl %&lt;.pl"         elseif &amp;filetype == "python"             exec "!python %&lt;.py"         elseif &amp;filetype == "ruby"             exec "!ruby %&lt;.rb"         endif endfunc </code></code></code>

VIM配置模版