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 .vimrcto 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 :PluginInstallcommand, 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, dugang_it@aliyun.com"
"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 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值