《LINUX教學(xué):Vim配置詳解》要點(diǎn):
本文介紹了LINUX教學(xué):Vim配置詳解,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
Linux下的編輯器以vim和emacs為主流,一個(gè)編輯器之神,一個(gè)是神的編輯器.本文以主要介紹如安在linux下以vim為基礎(chǔ)搭建一個(gè)比較順手的代碼編輯器.
自動(dòng)安裝
手動(dòng)安裝
這種是辦法是比較省事的辦法,只要一個(gè).vimrc配置文件就可以搞定所有的事情,一次配好即可.以后只要有這個(gè)配置文件,就可以走遍天下.
這種方式需要使用一個(gè)VIM插件管理工具來(lái)自動(dòng)管理VIM插件的安裝與卸載,筆者使用的Vundle來(lái)管理VIM插件,Vundle的全稱(chēng)是Vim Bundle,它是一款Vim插件管理工具.Vundle讓你可以非常輕松地安裝、更新、搜索和清理Vim插件.它還能管理你的運(yùn)行時(shí)環(huán)境,并幫助標(biāo)記.
下載完成后,解壓到用戶(hù)根目次的.vim目次下即可
clone完成后, 會(huì)在用戶(hù)根目錄下多出來(lái)一個(gè)bundle目錄,此時(shí)Vundle已經(jīng)安裝完成.安裝好Vundle以后,就可以根據(jù)本身的需要安裝插件了.Vundle提供了幾種不同的插件安裝方式,一般我們用到的插件在github都可以找到,因此最常用的一般就是直接找github上插件對(duì)應(yīng)的倉(cāng)名,添加到.vimrc中即可.然后打開(kāi)vim,執(zhí)行:PluginInstall命令,即可自動(dòng)安裝,等待Vundle執(zhí)行完下載安裝操作后,就可以開(kāi)始享受VIM了.
筆者的.vimrc文件配置如下:
"===============================================================================================
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
" Git plugin not hosted on GitHub
"Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
"Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
"============================ my plugins start =============================
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'majutsushi/tagbar'
Plugin 'tacahiroy/ctrlp-funky'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'easymotion/vim-easymotion'
Plugin 'haya14busa/incsearch.vim'
Plugin 'dkprice/vim-easygrep'
Plugin 'dyng/ctrlsf.vim'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'hfts/Porsche'
Plugin 'vim-scripts/OmniCppComplete'
Plugin 'vim-scripts/AutoComplPop'
Plugin 'scrooloose/nerdcommenter'
"============================ my plugins end ===============================
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
"========== for vim ==============
syntax enable " 開(kāi)啟語(yǔ)法高亮
set t_Co=256 " 開(kāi)啟256色顯示
set scrolloff=3 " 滾動(dòng)時(shí)堅(jiān)持邊距5行
set number " 開(kāi)啟行號(hào)顯示
set mouse=a " 開(kāi)啟鼠標(biāo)
set cmdheight=1
set nocompatible
set confirm " 在處理未保存或只讀文件的時(shí)候,彈出確認(rèn)
set autoindent? ? " 自動(dòng)縮進(jìn)
set tabstop=4? ? " Tab鍵的寬度
set expandtab " 展開(kāi)tab為空格
set softtabstop=4? ? " 統(tǒng)一縮進(jìn)為4
set shiftwidth=4
filetype plugin indent on "打開(kāi)文件類(lèi)型檢測(cè), 加了這句才可以用智能補(bǔ)全
set completeopt=longest,menu
set hlsearch " 高亮搜索
set laststatus=1 " 始終顯示狀態(tài)欄
set encoding=utf-8 "
set ignorecase " 搜索忽略大小寫(xiě)
set nopaste " 切換到正常模式
set list lcs=tab:\|\ " 顯示對(duì)齊線(xiàn) | | ┆ │
colorscheme Porsche
set cursorline
"hi cursorline cterm=none term=none
"autocmd WinEnter * setlocal cursorline
"autocmd WinLeave * setlocal nocursorline
"highlight CursorLine guibg=#30F010 ctermbg=189
"自動(dòng)補(bǔ)全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction"
"========== for quick key =======
" F11默認(rèn)時(shí)全屏
nmap <F2> :NERDTreeToggle<cr>
nmap <F3> :TagbarToggle<CR>
nmap <F4> :ToggleBufExplorer<cr>
nmap <F5> :CtrlPFunky<cr>
nmap <F10> :set paste<cr> " 切換到粘貼模式
nmap <F12> :source ~/.vimrc<cr>
nmap <silent> <leader>ll :colorscheme Porsche<cr>
nmap <silent> <leader>jj :colorscheme space-vim-dark<cr>
nmap <silent> <leader>nm :set nonumber<cr>
nmap <silent> <leader>mn :set number<cr>
nmap <silent> <leader>ag :Ag<cr>
nmap <silent> <leader>ff ::shell<cr>
"========== for NERDTree ==============
"let g:NERDTree_title='NERD Tree'
"let g:winManagerWindowLayout='NERDTree|TagList,Tarbar'
autocmd vimenter * NERDTree
nmap wm :NERDTreeToggle<cr>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") ) | q | endif
function! NERDTree_Start()
exec 'NERDTree'
endfunction
function! NERDTree_IsValid()
return 1
endfunction
nmap <silent> mt :if IsWinManagerVisible() <BAR> WMToggle<CR> <BAR> else <BAR> WMToggle<CR>:q<CR> endif "<CR>
"========== for CtrlP ===================
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'r'
let g:ctrlp_match_window = 'bottom,order:ttb,min:1,max:15,results:100'
let g:ctrlp_tabpage_position = 'al'
let g:ctrlp_working_path_mode = 'r'
let g:ctrlp_reuse_window = 'netrw\|help\|quickfix'
let g:ctrlp_open_new_file = 't'
let g:ctrlp_open_multiple_files = 'tjr'
let g:ctrlp_arg_map = 1
let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript',
\ 'undo', 'line', 'changes', 'mixed', 'bookmarkdir']
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.png,*.jpg,*.jpeg,*.gif " MacOSX/Linux
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
if executable('ag')
" Use Ag over Grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files.
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" Ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
"========== for CtrlPFunky ==============
nnoremap <Leader>u :execute 'CtrlPFunky ' . expand('<cword>')<Cr>
let g:ctrlp_extensions = ['funky']
let g:ctrlp_funky_syntax_highlight = 1
let g:ctrlp_funky_matchtype = 'path'
let g:ctrlp_funky_nerdtree_include_files = 1
"========== for vim-airline ==============
let g:airline_theme="light" "light
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
"========== for EasyMotion ==============
" <Leader>f{char} to move to {char}
map <Leader>f <Plug>(easymotion-bd-f)
nmap <Leader>f <Plug>(easymotion-overwin-f)
" s{char}{char} to move to {char}{char}
nmap s <Plug>(easymotion-overwin-f2)
" Move to line
map <Leader>L <Plug>(easymotion-bd-jk)
nmap <Leader>L <Plug>(easymotion-overwin-line)
" Move to word
map <Leader>w <Plug>(easymotion-bd-w)
nmap <Leader>w <Plug>(easymotion-overwin-w)
"========== for insearch ==============
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
nnoremap <Esc><Esc> :<C-u>nohlsearch<CR>
"set incsearch
set hlsearch
let g:incsearch#auto_nohlsearch = 0
map n <Plug>(incsearch-nohl-n)
map N <Plug>(incsearch-nohl-N)
map * <Plug>(incsearch-nohl-*)
map # <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)
"=========== for NERDTREE-GIT-PLUGIN =====
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "?",
\ "Staged" : "?",
\ "Untracked" : "?",
\ "Renamed" : "?",
\ "Unmerged" : "═",
\ "Deleted" : "?",
\ "Dirty" : "?",
\ "Clean" : "??",
\ "Unknown" : "?"
\ }
"=========== cscope ===============
if has("cscope")
set csprg=/usr/local/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><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>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
"=========== omnicppcomplete ===============
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_NamespaceSearch = 2
let OmniCpp_DisplayMode = 1
let OmniCpp_ShowScopeInAbbr = 1
let OmniCpp_ShowPrototypeInAbbr = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_MayCompleteDot = 1
let OmniCpp_MayCompleteArrow = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_SelectFirstItem = 1
let OmniCpp_DefaultNamespace=["std"]
let OmniCpp_SelectFirstItem = 2
"===============NERD Commenter=========================
let g:NERDSpaceDelims = 1 " Add spaces after comment delimiters by default
let g:NERDCompactSexyComs = 1 " Use compact syntax for prettified multi-line comments
let g:NERDDefaultAlign = 'left' " Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDAltDelims_java = 1 " Set a language to use its alternate delimiters by default
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } } " Add your own custom formats or override the defaults
let g:NERDCommentEmptyLines = 1 " Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDTrimTrailingWhitespace = 1 " Enable trimming of trailing whitespace when uncommenting
"===============================================================================================
手動(dòng)安裝,當(dāng)然是要自己一個(gè)一個(gè)地安裝插件了.這種方式的特點(diǎn)是需要自己一個(gè)一下下載vim插件,然后手動(dòng)進(jìn)行安裝.雖然比較費(fèi)事,但如果之前有vim插件安裝包的備份文件,那就可以不依賴(lài)于網(wǎng)絡(luò).所以還是保舉在自己的本地留一份常用插件的安裝包備份.手動(dòng)安裝的過(guò)程比較簡(jiǎn)單,基本上就是“下載-解壓”,先從網(wǎng)卡下載好插件的壓縮包,一般來(lái)說(shuō)直接解壓到.vim目錄中即可.
筆者常用的幾個(gè)插件如下,一般都可以在github上找到,其實(shí)從上面的配置文件中就可以找到筆者使用了哪些vim插件.
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'majutsushi/tagbar'
Plugin 'tacahiroy/ctrlp-funky'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'easymotion/vim-easymotion'
Plugin 'haya14busa/incsearch.vim'
Plugin 'dkprice/vim-easygrep'
Plugin 'dyng/ctrlsf.vim'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'hfts/Porsche'
Plugin 'vim-scripts/OmniCppComplete'
Plugin 'vim-scripts/AutoComplPop'
Plugin 'scrooloose/nerdcommenter'
末了,附上筆者vim的兩張截圖:
Vim入門(mén)根基知識(shí)集錦?
Vim入門(mén)根基教程
把Vim打造成優(yōu)秀的C++ IDE?
Ubuntu 14.04進(jìn)級(jí)Vim7.4到8.0?
Vim安裝youcompleteme自動(dòng)補(bǔ)全插件?
Linux Vim編纂器使用簡(jiǎn)單講解?
Vim文本編纂器?
Vim安裝與設(shè)置裝備擺設(shè)進(jìn)階版
Vim編纂器使用教程?
Ubuntu 16.04 Vim YouCompleteMe自動(dòng)補(bǔ)全的安裝設(shè)置裝備擺設(shè)與使用?
Linux文本編纂器Vim基礎(chǔ)教程?
本文永遠(yuǎn)更新鏈接地址:?
學(xué)習(xí)更多LINUX教程,請(qǐng)查看站內(nèi)專(zhuān)欄,如果有LINUX疑問(wèn),可以加QQ交流咨詢(xún)。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/6672.html