vim經驗技巧 1. nginx配置文件語法高亮 #wget http://www.vim.org/scripts/download_script.php?src_id=19394 將nginx.vim置於~/.vim/syntax目錄下 增長配置到~/.vim/filetype.vim最後一行 => #au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/* if &ft == '' | setfiletype nginx | endif au BufRead,BufNewFile * if &ft == '' | setfiletype nginx | endif 2. 更改默認字體 修改配置文件~/.vimrc => :set guifont=Consolas:h12 3. Vim編碼設置 1)encoding(enc)是Vim內部的字符編碼方式。 爲了不windows下,菜單出現亂碼,應設置: :set encoding=UTF-8 :set langmenu=zh_CN.UTF-8 language message=zh_CN.UTF-8 2)termencoding是Vim用於顯示屏幕的編碼,便於輸出。 3)fileencoding(fenc)是從磁盤上讀取文件時,對文件的編碼。 4)fileencodings(fencs)是一個逗號分隔的列表,來實現編碼的自動識別。最好把寬鬆的編碼放在後面。 若是編碼錯了,打開的文件沒法識別,能夠指定編碼: :e ++enc=UTF-8 myfile 5)fencview是一個編碼自動識別插件: #wget http://www.vim.org/scripts/download_script.php?src_id=21657 將fencview放置於~/.vim/plugin目錄下 tools=>encoding=>Auto Detect或:FencView調用命令 4. Vim中的複製 打開鼠標模式: :set mouse=a 在普通模式下能夠直接使用鼠標選取文本,若是想要複製到剪切板: 設置爲paste模式 :set paste 5. Vim縮進及行號控制 set nu set shiftwidth=2 set nobackup set autoindent set tabstop=2 set softtabstop=2 set expandtab 6. 安裝樹形目錄插件BERDTree #wget http://www.vim.org/scripts/download_script.php?src_id=17123 解壓到vim目錄下,把NERD_tree.vim放置於vim/plugin目錄下,把NERD_tree.txt放置於vim/doc目錄下。 :NERDTree 可使用該插件 vimrc添加以下自定義設置 => let NERDChristmasTree=1 let NERDTreeAutoCenter=1 let NERDTreeBookmarksFile=$VIM.'\Data\NerdBookmarks.txt' let NERDTreeMouseMode=2 let NERDTreeShowBookmarks=1 let NERDTreeShowFiles=1 let NERDTreeShowHidden=1 let NERDTreeShowLineNumbers=1 let NERDTreeWinPos='left' let NERDTreeWinSize=31 nnoremap f :NERDTreeToggle map <F7> :NERDTree<CR> 7. 安裝txt.vim插件方便查詢普通文件 #wget http://www.vim.org/scripts/download_script.php?src_id=6580 解壓到vim/syntax目錄下,vimrc添加 => au BufRead,BufNewFile * setfiletype txt 8. 安裝taglist插件 #wget http://www.vim.org/scripts/download_script.php?src_id=19574 解壓包把doc,plugin下的文件分別放入vim/doc,vim/plugin目錄下 :helptags $VIM/vim/doc 生成幫助標籤,以後能夠查看taglist幫助 :help taglist.txt 9. 安裝json插件 #wget http://www.vim.org/scripts/download_script.php?src_id=10853 解壓到vim/syntax目錄下 vimrc添加以下自定義設置 => au! BufRead,BufNewFile *.json set filetype=json augroup json_autocmd autocmd! autocmd FileType json set autoindent autocmd FileType json set formatoptions=tcq2l autocmd FileType json set textwidth=78 shiftwidth=2 autocmd FileType json set softtabstop=2 tabstop=8 autocmd FileType json set expandtab autocmd FileType json set foldmethod=syntax augroup END