通过vimrc文件以及Vundle安装插件来配置高效的Vim编辑环境。
1、我的vimrc适用于CentOS(6.6)以及Ubuntu(16.04),并且实际测试验证过,下面贴出
set nocompatible
set number
set guioptions-=r
set guioptions-=L
set guioptions-=b
set showtabline=0
set guifont=Monaco:h13
syntax on "开启语法高亮"
let g:solarized_termcolors=256 "solarized主题设置在终端下的设置"
set background=dark "设置背景色"
set nowrap "设置不折行"
set fileformat=unix "设置以unix的格式保存文件"
set cindent "设置C样式的缩进格式"
set tabstop=4 "设置table长度"
set shiftwidth=4 "同上"
set showmatch "显示匹配的括号"
set scrolloff=5 "距离顶部和底部5行"
set laststatus=2 "命令行为两行"
set fenc=utf-8 "文件编码"
set backspace=2
set mouse=a "启用鼠标"
set selection=exclusive
set selectmode=mouse,key
set matchtime=5
set ignorecase "忽略大小写"
set incsearch
set hlsearch "高亮搜索项"
set noexpandtab "不允许扩展table"
set whichwrap+=<,>,h,l
set autoread
set cursorline "突出显示当前行"
set cursorcolumn "突出显示当前列"
map <F5> :Autopep8<CR> :w<CR> :call RunPython()<CR>
function RunPython()
let mp = &makeprg
let ef = &errorformat
let exeFile = expand("%:t")
setlocal makeprg=python\ -u
set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\]%\\@=%m
silent make %
copen
let &makeprg = mp
let &errorformat = ef
endfunction
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'Lokaltog/vim-powerline'
Plugin 'scrooloose/nerdtree'
Plugin 'Yggdroot/indentLine'
Plugin 'jiangmiao/auto-pairs'
Plugin 'tell-k/vim-autopep8'
Plugin 'scrooloose/nerdcommenter'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'tmhedberg/SimpylFold'
Bundle 'Valloric/YouCompleteMe'
call vundle#end()
filetype plugin indent on
map <F2> :NERDTreeToggle<CR>
let NERDTreeChDirMode=1
let NERDTreeShowBookmarks=1
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
let NERDTreeWinSize=25
let g:indentLine_char='┆'
let g:indentLine_enabled = 1
let g:autopep8_disable_show_diff=1
let mapleader=','
map <F4> <leader>ci <CR>
au BufNewFile,BufRead *.py
\ set tabstop=4 |
\ set softtabstop=4 |
\ set shiftwidth=4 |
\ set textwidth=79 |
\ set expandtab |
\ set autoindent |
\ set fileformat=unix |
au BufNewFile,BufRead *.js, *.html, *.css
\ set tabstop=2 |
\ set softtabstop=2 |
\ set shiftwidth=2 |
set foldmethod=indent
set foldlevel=99
nnoremap <space> za
let g:SimpylFold_docstring_preview=1
set encoding=utf-8
let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
2、上述vimrc配置文件放置root家目录即可,接着就是安装Vundle,并执行插件安装操作;但有个问题是默认的CentOS6.6默认Vim版本低,现最新版本为8.0,且Ubuntu默认是没有Vim的,提前是需要升级或者安装
2.1 安装/升级vim
./configure --with-features=huge --enable-pythoninterp=yes --enable-cscope --enable-fontset --enable-perlinterp --enable-rubyinterp --with-python-config-dir=/usr/local/lib/python2.7/config --prefix=/usr/local/vim
make && make install
echo "alias vim='/usr/local/vim/bin/vim'" >>~/.bash_profile
vim --version #测试是否安装/升级成功
2.2安装vundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +PluginInstall +qall或者打开vimrc,然后命令行模式"PluginInstall"即可
配置过程中问题1:
YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+) support
解决思路:
YouCompleteMe是自动补全功能,这里需要支持Python,vim --version可得知是否支持Python2或者Python3
至此,所有配置以及安装完毕,接下来就使劲的用吧。