VIM 的配置和神一般的外掛。
一. 基本的配置:
-
syn on "語法高亮
-
set helplang=cn "使用中文幫助文件
-
set backspace=2
-
set tabstop=4 "製表符的寬度
-
set softtabstop=4
-
set shiftwidth=4 "縮排的空格
-
set autoindent "自動縮排
-
set cindent "C 外掛
-
set number "設定行號
-
set ignorecase "忽略大小寫 (查詢字串時)
-
set nohlsearch "高亮顯示 (查詢字串是,找到後高亮顯示)
-
set mouse=a "使用滑鼠
-
set ruler "在右下角顯示游標位置
-
set showcmd "顯示未敲完的命令
-
set cmdheight=1 "設定命令列的行數為 1
-
set laststatus=2 "顯示狀態列 (預設值為 1, 無法顯示狀態列)
-
set incsearch "在輸入搜尋的字元串同時就開始搜尋已經輸入的部分
-
set nowrap "一行就一行,別弄到第二行去
-
set sidescroll=10 "螢幕放不下時,按一次螢幕移動一個字元
-
set whichwrap=b,s,<,>,[,] "跨行移動
-
set fileformats=unix,dos
-
set cursorline "突出顯示當前行
-
set showmatch "插入括號時,短暫地跳轉到匹配的對應括號
-
set matchtime=2 "短暫跳轉到匹配括號的時間
-
set smartindent "開啟新行時使用智慧自動縮排
-
filetype plugin indent on "自動識別檔案型別,用檔案型別plugin指令碼,使用縮排定義檔案
- "set autochdir
點選(此處)摺疊或開啟
-
"貼上複製的一些操作
-
vmap "+y "選中狀態下 Ctrl+c 複製
-
nmap "+yy "選中狀態下 Ctrl+c 複製
-
nmap "+p "正常模式下貼上
-
nmap ggvG "正常模式下全選
-
vmap <C-x> dd<Esc> "正常模式下DEL
-
nmap s :call SaveFile()
-
imap s :call SaveFile()
-
vmap s :call SaveFile()
-
func! SaveFile()
- exec "w
點選(此處)摺疊或開啟
-
"記憶上次開啟檔案的位置
-
if has("autocmd")
-
autocmd BufRead *.txt set tw=78
- autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"
-
autocmd BufWritePre * :%s/\s+\+$//e "自動去除行尾空格 這個在gerrit 檢查程式碼比較有用。
-
set fileencodings=ucs-bom,utf-8,GB18030,GBK,GB2312 "字元編碼支援中文
vim下有各種各樣的外掛,每次換機器,都要重新配置一遍,後來發現了外掛管理神奇 Vundle。
下載Vundle: git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
配置 vundle 。在vundle 中的外掛主要分三類:
1.vimrc-script 網站上的外掛 "Bundle 'minibufexpl.vim'
2.github 上的外掛。 "Bundle 'fholgado/minibufexpl.vim'
3.自定義git上的外掛。 "Bundle 'https://github.com/Lokaltog/powerline'
其實第二種也可以採用第三種方式管理,原理是一樣的,都是git管理。
在vimrc 配置完外掛以後,vundle 可以自動下載外掛,自動更新。
重啟vim,在vim執行命令::BundleInstall 自動安裝外掛。
在vimrc 中配置:map :!git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
連Vundle 也自動下載。
點選(此處)摺疊或開啟
-
"""""""""""""""""""""""""""""""""""VUNDLE setting"""""""""""""""""""""""""""""""""""""""""""
-
set nocompatible " be iMproved
-
filetype off "
-
set rtp+=~/.vim/bundle/vundle/
-
call vundle#rc()
-
" let Vundle manage Vundle
-
Bundle 'gmarik/vundle'
-
" vim-scripts repos
-
"Bundle 'minibufexpl.vim'
-
"Bundle 'bufexplorer.zip'
-
"Bundle 'taglist.vim'
-
"Bundle 'c.vim'
-
"Bundle 'winmanager'
-
"Bundle 'The-NERD-Commenter'
-
"Bundle 'snipMate'
-
"Bundle 'TxtBrowser'
-
"Bundle 'genutils'
-
"Bundle 'lookupfile'
-
"Bundle 'LeaderF'
-
Bundle 'The-NERD-tree'
-
"Bundle 'ctrlp.vim'
-
"Bundle 'cscope.vim'
-
"Bundle 'Tagbar'
-
"github repos.
-
"Bundle 'fholgado/minibufexpl.vim'
-
"Bundle 'bling/vim-airline'
-
"Bundle 'tpope/vim-fugitive'
-
"Bundle 'Shougo/neocomplcache.vim'
-
"Bundle 'ervandew/supertab'
-
"Bundle 'simplyzhao/cscope_maps.vim'
-
Bundle 'vim-scripts/EasyGrep'
-
Bundle 'kien/ctrlp.vim'
-
Bundle 'majutsushi/tagbar'
-
Bundle 'brookhong/cscope.vim'
-
Bundle 'scrooloose/nerdtree'
-
Plugin 'Valloric/YouCompleteMe'
-
"file repos or git repos
-
"Bundle 'git://git.wincent.com/command-t.git'
-
"Bundle 'https://github.com/Lokaltog/powerline'
-
filetype plugin indent on " required!
-
"
-
" Brief help
-
" :BundleList - list configured bundles
-
" :BundleInstall(!) - install(update) bundles
-
" :BundleSearch(!) foo - search(or refresh cache first) for foo
-
" :BundleClean(!) - confirm(or auto-approve) removal of unused bundles
-
"
-
" see :h vundle for more details or wiki for FAQ
-
" NOTE: comments after Bundle command are not allowed..
- """"""""""""""""""""""""END VUNDLE""""""""""""""""""""""""""
三。Tag Tagbar 外掛
在傳統的vim 配置中,瀏覽檔案中的變數,函式都是藉助tags 和Taglist 外掛。你out 了,vimer 們總有給人想不到的驚喜,Tagbar 橫空出世。
TagBar 比Taglist 有更清晰的顯示層次結構, 在色彩上也更豐富。對C++ 的支援更友好。git 地址:https://github.com/majutsushi/tagbar。Taglist 可以安然退休了。
在vimr 中對映:nnoremap :TagbarToggle
在TagBar 視窗按F1 彈出幫助:
四. 檔案查詢
檔案查詢傳統的外掛有fuzzyfind lookup等。Sublime的快捷鍵Ctrl P 深得程式猿的好評,vim 不能讓sublime 獨美,推出了CtrlP .傳統的查詢方式都是切換另外一個shell,find 。現在直接搞定。
ctrlp 的設計思想很先進,能夠根據.git 目錄自動確定根目錄位置,自動確定查詢範圍,支援路徑,檔名。
git 地址:https://github.com/kien/ctrlp.vim
這裡有一篇視訊講解:http://zuyunfei.com/2013/08/26/vim-plugin-ctrlp/
不過還像又有人有意見了:https://github.com/Yggdroot/LeaderF 號稱效能比crtlp 更快。
點選(此處)摺疊或開啟
-
"""""""""""""""""""""""""""ctrlp"""""""""""""""""""""""""""
-
let g:ctrlp_working_path_mode = 'ra'
-
let g:ctrlp_by_filename = 0
-
let g:ctrlp_open_multiple_files = 'v'
-
set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux
-
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe " Windows
-
let g:ctrlp_custom_ignore = {
-
\ 'dir': '\v[\/]\.(git|hg|svn)$',
-
\ 'file': '\v\.(exe|so|dll)$',
-
\ 'link': 'some_bad_symbolic_links',
-
\ }
- """""""""""""""""""""END ctrlp"""""""""""""""""""""""""""""
五. grep
vim自帶Grep 功能。EasyGrep 基於vim的grep 功能,不受作業系統限制,Windows下的vimer的幸福了。
EasyGrep uses Vim's leader key, which is by default '\'. For information on
this key, type ":help mapleader".
vv - Grep for the word under the cursor, match all occurences, like 'g*'. See ":help gstar".
vV - Grep for the word under the cursor, match whole word, like '*'. See ":help star".
va - Like vv, but add to existing list.
vA - Like vV, but add to existing list.
vr - Perform a global search on the word under the cursor and prompt for a pattern with which to replace it.
vR - Like vr, but match whole word.
vo 開啟設定,可以對EasyGrep進行一些設定。
vo - Open an options explorer to select the files to search in and set grep options.
可配置搜尋模式:
*EasyGrepMode* [default=0]
Specifies the mode in which to start.
0 - All files
1 - Open Buffers
2 - Track the current extension
3 - User mode -- Use a custom, on demand set of extensions
最好用的是2,根據檔案字尾匹配搜尋檔案,模式0一直用不出來,不知道是不是Winddows的原因。
6.NerdTree 外掛
vim自帶視窗瀏覽外掛,不過NerdTree功能更強大,更方便,更好用。
vim 中命令列輸入 :NERDTree 顯示如下。然後按? 可以顯示幫助,是不是很貼心。
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> 閱讀(4153) | 評論(2) | 轉發(8) | 給主人留下些什麼吧!~~
2015-01-27 14:51:46
博主,您好,能不能將你的完整的VIM的配置檔案給我一份。謝謝
([email protected])
2015-01-26 17:42:02
文明上網,理性發言...
回覆 | 舉報 評論熱議