Vim Configuration
Vim Configuration
Vim is one of the most popular text editors on linux, and it is a very powerful editor.
Next, I take CentOS as an example to introduce the configuration of my vim.
Live Demo
Install Vundle
Vundle is short for Vim bundle and is a Vim plugin manager.
.
Vundle allows you to…
- keep track of and configure your plugins right in the .vimrc
- install configured plugins (a.k.a. scripts/bundle)
- update configured plugins
- search by name all available Vim scripts
- clean unused plugins up
- run the above actions in a single keypress with interactive mode
Vundle automatically…
- manages the runtime path of your installed scripts
- regenerates help tags after installing and updating
Install Git
If your Linux does not install git, install it using the following commands.Because the git clone
command is used during installation.
sudo yum install git
Set up Vundle
Install Vundle using the following commands
git clone https://github.com/VundleVim/Vundle.vim.git /.vim/bundle/Vundle.vim
Configure Plugins
Put this at the top of your .vimrc
to use Vundle. Remove plugins you don’t need, they are for illustration purposes.
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
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
Install Vim Plugins
With the :PluginInstall
command, Vundle automatically downloads and installs the Vim plugin from github.com
or vim-scripts.org
.
Configuration of .vimrc
Installation Plugins from github:
Plugin ‘user/plugin’
Installation Plugins from http://vim-script.org/vim/scripts.html:
Plugin ‘plugin_name’
Installation Plugins from another github repositories:
Plugin ‘git://git.another_repo.com/plugin’
Install Plugins
Launch vim
and run :PluginInstall
To install from command line:vim +PluginInstall +qall
Vundle commands
Install new plug-ins
The command PluginInstall
can install all the plug-ins listed in your .vimrc
. You could also install only one specific plug-in by passing its name.
:PluginInstall
:PluginInstall <plugin-name>
Clean up unused plug-ins
The command PluginClean
can clean up any plugins you have unused.
:PluginClean
Search plug-in
The search function is useful if you want to install a plugin from the list of plugins provided.
During the search, you can install, clean, research, or reload the same list on the interactive split screen. Install the plugin does not automatically load your plugin, if you want to automatically load the plugin and add the plugin to your .vimrc
, such as :PluginSearch taglist
, after completing the search, you can press ‘i’ to install.
:PluginSearch <text-list>
Vim Plugin recommendation
The VIM plug-in can greatly improve the efficiency of vim usage. Here I introduce several better VIM plug-ins and show my VIM configuration file.
VIM Plugin
- nerdtree
- vim-airline
- vim-airline-themes
- tagbar
- nerdcommenter
- auto-pairs
- DoxygenToolkit
- Pydiction
.vimrc
Here is the .vimrc
on my linux
" For full syntax highlighting
syntax on
" make backspaces nore powerfull
set nocompatible " be iMproved, required
set backspace=indent,eol,start
" 啓動時隱去援助提示
set shortmess=atI
" 不需要備份
set nobackup
" c文件自動縮進
set cindent
" Tab自動轉換成空格
set expandtab
" 一個tab縮進字符
set tabstop=4
" 編輯模式的時候按退格鍵退回縮進的長度
set softtabstop=4
" 每一級鎖進的長度
set shiftwidth=4
" 自動鎖進
set autoindent
" 智能縮進
set smartindent
" 高亮查找匹配
set hlsearch
" 顯示匹配
set showmatch
" 顯示標尺,就是在右下角光標位置
set ruler
" 啓動顯示狀態行
set laststatus=2
" 淺色顯示當前行
autocmd InsertLeave * se nocul
" 用淺色高亮當前行
"autocmd insertEnter * se cul
" 顯示輸入命令
set showcmd
"I don't like swap files
set noswapfile
"turn on numbering
set nu!
" Set the default file encoding to UTF-8:
set encoding=utf-8
" 設置雙字款顯示,否則無法顯示一個圖標
set ambiwidth=double
" 被分割窗口之間顯示空白
set fillchars=vert:/
set fillchars=stl:/
"set fillchars=stlnc:/
" 垂直分割線顏色
":highlight VertSplit term=reverse ctermbg=242 guibg=DarkGrey
":highlight VertSplit ctermfg=7 ctermbg=242 guifg=LightGrey guibg=DarkGrey
:highlight VertSplit cterm=bold ctermfg=15 ctermbg=242 gui=bold guifg=White guibg=Grey40
" 鼠標當前行顏色
":hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
":hi CursorLine cterm=NONE ctermfg=190 ctermbg=238
:hi CursorLine cterm=NONE ctermbg=239
" 鼠標當前列顏色
:hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
:nnoremap \<Leader\>c :set cursorline! cursorcolumn!\<CR\>
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'}
Bundle 'scrooloose/nerdtree'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Bundle 'majutsushi/tagbar'
Plugin 'scrooloose/nerdcommenter'
Plugin 'jiangmiao/auto-pairs'
Plugin 'vim-scripts/DoxygenToolkit.vim'
Plugin 'vim-scripts/Pydiction'
" All of your Plugins must be added before the following line
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
" NERDTree
" open a NERDTree automaticallyu when vim starts up
" autocmd vimenter * NERDTree
" close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" open NERDTree automatically when vim starts up on opening a directory
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]()) && !exists("s:std_in") | exe 'NERDTree' argv()[0]() | wincmd p | ene | endif
map \<C-n\> :NERDTreeToggle\<CR\>
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
" 窗口位置
let g:NERDTreeWinPos='left'
" 窗口尺寸
let g:NERDTreeSize=30
" 窗口是否顯示行號
let g:NERDTreeShowLineNumber=0
" 不顯示隱藏文件
let g:NERDTreeHidden=0
" vim-airline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:airline#extensions#tabline#formatter = 'default'
"let g:airline_theme='powerlineish'
set laststatus=2
set t_Co=256
"set fillchars+=stl:\ ,stlnc:\\
let g:airline_powerline_fonts = 1
"打開tabline功能,方便查看Buffer和切換,省去了minibufexpl插件
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
"設置切換Buffer快捷鍵"
nnoremap \<C-tab\> :bn\<CR\>
nnoremap \<C-s-tab\> :bp\<CR\>
" 關閉狀態顯示空白符號計數
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#whitespace#symbol = '!'
" 設置consolas字體"前面已經設置過
"set guifont=Consolas\ for\ Powerline\ FixedD:h11
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" old vim-powerline symbols
let g:airline_left_sep = '⮀'
let g:airline_left_alt_sep = '⮁'
let g:airline_right_sep = '⮂'
let g:airline_right_alt_sep = '⮃'
"let g:airline_symbols.branch = '⭠'
let g:airline_symbols.branch = '⎇ '
let g:airline_symbols.readonly = '⭤'
let g:airline_symbols.linenr = '¶'
let g:airline_detect_modified = 1
let g:airline_detect_paste = 1
" tagbar
" 設置tagbar使用ctags
" let g:tagbar_ctags_bin='/usr/bin/ctags'
" 快捷鍵
nmap \<F9\> :TagbarToggle\<CR\>
" 寬度
let g:tagbar_width=24
" 開啓自動預覽,隨着光標在標籤上的移動,頂部出現一個實時預覽窗口
let g:tagbar_autopreview=1
" 關閉排序,即按照標籤在文件中的位置排序
let g:bagbar_sort=0
" 設置窗口在右邊顯示
let g:tagbar_right=1
" 打開文件自動打開tagbar
"autocmd BufReadPost *,*.cpp,*.c,*.h,*.cc,*.cxx call tagbar#autoopen()
" nerdcommenter
" 將\修改映射爲,
nmap ,cc \<leader\>cc
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java = 1
" Add your own custom formats or override the defaults
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1
" Enable NERDCommenterToggle to check all selected lines is commented or not
let g:NERDToggleCheckAllLines = 1
" auto pairs
let g:AutoPairs = {'(':')', '[':']()', '{':'}',"'":"'",'"':'"'}
" 設置要自動配對的符號
" let g:AutoPairs['\<']()='\>'
" 添加要自動配對的符號\<\>
"let b:AutoPairs = g:AutoParis
" 設置要自動配對的符號,默認爲g:AutoPairs,可以通過自動命令來對不同文件類型設置不同自動匹配對符號。
let g:AutoPairsShortcutToggle = '\<M-p\>'
" 設置插件打開/關閉的快捷鍵,默認爲ALT+p。
let g:AutoPairsShortcutFastWrap = '\<M-e\>'
" 設置自動爲文本添加圓括號的快捷鍵,默認爲ALT+e。
let g:AutoPairsShortcutJump = '\<M-n\>'
" 設置調到下一層括號對的快捷鍵,默認爲ALT+n。
let g:AutoPairsShortcutBackInsert = '\<M-b\>'
" 設置撤銷飛行模式的快捷鍵,默認爲ALT+b。
let g:AutoPairsMapBS = 1
" 把BACKSPACE鍵映射爲刪除括號對和引號,默認爲1。
let g:AutoPairsMapCh = 1
" 把ctrl+h鍵映射爲刪除括號對和引號,默認爲1。
let g:AutoPairsMapCR = 1
" 把ENTER鍵映射爲換行並縮進,默認爲1。
let g:AutoPairsCenterLine = 1
" 當g:AutoPairsMapCR爲1時,且文本位於窗口底部時,自動移到窗口中間。
let g:AutoPairsMapSpace = 1
" 把SPACE鍵映射爲在括號兩側添加空格,默認爲1。
let g:AutoPairsFlyMode = 0
" 啓用飛行模式,默認爲0。
let g:AutoPairsMultilineClose = 1
" 啓用跳出多行括號對,默認爲1,爲0則只能跳出同一行的括號。
" Doxygen
imap cm \<esc\>:Dox\<CR\>
map cm :Dox\<CR\>
map fg : Dox\<cr\>
let g:DoxygenToolkit_briefTag_funcName = "yes"
let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"
let g:load_doxygen_syntax = 1
" 設置生成的文檔的 Lisence 是///
let g:DoxygenToolKit_startCommentBlock = "/// "
let g:DoxygenToolKit_interCommentBlock = "/// "
let g:DoxygenToolkit_briefTag_pre="@Synopsis "
let g:DoxygenToolkit_paramTag_pre="@Param "
let g:DoxygenToolkit_returnTag="@Returns "
" let g:DoxygenToolkit_blockHeader="--------------------------------------------------------------------------"
" let g:DoxygenToolkit_blockFooter="----------------------------------------------------------------------------"
let g:DoxygenToolkit_authorName="dugang, [email protected]"
"let g:DoxygenToolkit_licenseTag="My own license"
let s:licenseTag = "Unpublished copyright. All rights reserved. This material contains\<enter\>"
let s:licenseTag = s:licenseTag . "proprietary information that should be used or copied only within\<enter\>"
let s:licenseTag = s:licenseTag . "COMPANY, except with written permission of COMPANY.\<enter\>"
if !exists("g:DoxygenToolkit_briefTag_lic_pre")
let g:DoxygenToolkit_briefTag_lic_pre = "@brief: "
endif
if !exists("g:DoxygenToolkit_briefTag_pre")
let g:DoxygenToolkit_briefTag_pre = "@brief: "
endif
if !exists("g:DoxygenToolkit_fileTag")
let g:DoxygenToolkit_fileTag = "@file: "
endif
if !exists("g:DoxygenToolkit_authorTag")
let g:DoxygenToolkit_authorTag = "@author: "
endif
if !exists("g:DoxygenToolkit_dateTag")
let g:DoxygenToolkit_dateTag = "@date: "
endif
if !exists("g:DoxygenToolkit_versionTag")
let g:DoxygenToolkit_versionTag = "@version: "
endif
function! \<SID\>DoxygenLicenseFunc()
call s:InitializeParameters()
" Test authorName variable
if !exists("g:DoxygenToolkit_companyName")
let g:DoxygenToolkit_companyName = input("Enter name of your company: ")
endif
if !exists("g:DoxygenToolkit_authorName")
let g:DoxygenToolkit_authorName = input("Enter name of the author (generally yours...) : ")
endif
mark d
" Get file name
let l:fileName = expand('%:t')
let l:year = strftime("%Y")
let l:copyright = "Copyright (c) "
let l:copyright = l:copyright.l:year." ".g:DoxygenToolkit_companyName."."
let l:license = substitute( g:DoxygenToolkit_licenseTag, "\<enter\>", "\<enter\>".s:interCommentBlock, "g" )
let l:license = substitute( l:license, "COMPANY", g:DoxygenToolkit_companyName, "g" )
exec "normal O".s:startCommentBlock
exec "normal o".s:interCommentTag.l:copyright."\<enter\>".s:interCommentTag
exec "normal o".s:interCommentTag.l:license
exec "normal o".s:interCommentTag.g:DoxygenToolkit_fileTag.l:fileName
exec "normal o".s:interCommentTag.g:DoxygenToolkit_briefTag_lic_pre
mark d
exec "normal o".s:interCommentTag.g:DoxygenToolkit_authorTag.g:DoxygenToolkit_authorName
exec "normal o".s:interCommentTag.g:DoxygenToolkit_versionTag."1.0"
let l:date = strftime("%Y-%m-%d")
exec "normal o".s:interCommentTag.g:DoxygenToolkit_dateTag.l:date
if( s:endCommentBlock != "" )
exec "normal o".s:endCommentBlock
endif
exec "normal `d"
` call s:RestoreParameters()
startinsert!
endfunction
" pydiction
filetype plugin on
let g:pydiction_location = '/.vim/bundle/Pydiction/complete-dict'
let g:pydiction_menu_height = 8
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascrīpt set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete