1、查看自己的vim版本
查看vim版本,+号表示支持的
vim --version
[root@work ~]# vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 31 2019 22:55:22)
Included patches: 1-1779
Compiled by root@work
Huge version without GUI. Features included (+) or not (-):
+acl -farsi -mouse_sysmouse -tag_any_white
+arabic +file_in_path +mouse_urxvt -tcl
+autocmd +find_in_path +mouse_xterm +termguicolors
+autochdir +float +multi_byte +terminal
-autoservername +folding +multi_lang +terminfo
-balloon_eval -footer -mzscheme +termresponse
+balloon_eval_term +fork() +netbeans_intg +textobjects
-browse +gettext +num64 +textprop
++builtin_terms -hangul_input +packages +timers
+byte_offset +iconv +path_extra +title
+channel +insert_expand -perl -toolbar
+cindent +job +persistent_undo +user_commands
-clientserver +jumplist +postscript +vartabs
-clipboard +keymap +printer +vertsplit
+cmdline_compl +lambda +profile +virtualedit
+cmdline_hist +langmap +python +visual
+cmdline_info +libcall -python3 +visualextra
+comments +linebreak +quickfix +viminfo
+conceal +lispindent +reltime +vreplace
+cryptv +listcmds +rightleft +wildignore
+cscope +localmap -ruby +wildmenu
+cursorbind -lua +scrollbind +windows
+cursorshape +menu +signs +writebackup
+dialog_con +mksession +smartindent -X11
+diff +modify_fname -sound -xfontset
+digraphs +mouse +spell -xim
-dnd -mouseshape +startuptime -xpm
-ebcdic +mouse_dec +statusline -xsmp
+emacs_tags -mouse_gpm -sun_workshop -xterm_clipboard
+eval -mouse_jsbterm +syntax -xterm_save
+ex_extra +mouse_netterm +tag_binary
+extra_search +mouse_sgr -tag_old_static
之前使用的是系统自带的vim7.4版本的,感觉有点问题,后来直接装了VIM8
2、安装vim8
sudo yum remove vim -y #卸载之前的vim
sudo yum install ncurses-devel python-devel -y #安装相关依赖
git clone https://github.com/vim/vim.git #下载vim包
cd vim/src
./configure --with-features=huge --enable-pythoninterp=yes --enable-cscope --enable-fontset --with python-config-dir=/usr/lib64/python2.7/config
#如果这里有提示错误,应该是确实某些依赖,直接yum install *** 这些包
make
修改环境变量,在里面添加
sudo nano /etc/profile
export PATH=$PATH:/usr/local/bin/vim
保存完了配置之后,使之生效
source /etc/profile
3、安装YouCompleteMe
有了这个插件可以使得vim带有补全代码的功能,哈哈哈
#下载安装包
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
#检测完整性
git submodule update --init --recursive
#这里可能会提示,有一个第三方golang的tool里面下载不到
#使用git的源替代
git clone https://github.com/golang/tools.git
cd /root/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x
cp -R /root/golang_tools/tools/ ./
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
4、配置vim插件
[root@work ~]# cat ~/.vimrc
set nocompatible " 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 'gmarik/Vundle.vim'
Plugin 'tmhedberg/SimpylFold'
Plugin 'vim-syntastic/syntastic'
Plugin 'nvie/vim-flake8'
Plugin 'jnurmine/Zenburn'
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
Plugin 'altercation/vim-colors-solarized'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'
Plugin 'jistr/vim-nerdtree-tabs'
"
" " add all your plugins here (note older versions of Vundle
" " used Bundle instead of Plugin)
"
" " ...
"
" " All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
set splitbelow
set splitright
"split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Enable folding
set foldmethod=indent
set foldlevel=99
" Enable folding with the spacebar
nnoremap <space> za
let g:SimpylFold_docstring_preview=1
let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
"Flagging Unnecessary Whitespace
highlight BadWhitespace ctermbg=red guibg=darkred
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
au BufNewFile,BufRead *.py
\ set tabstop=4 |
\ set softtabstop=4 |
\ set shiftwidth=4 |
\ set textwidth=79 |
\ set expandtab |
\ set autoindent |
\ set fileformat=unix
set encoding=utf-8
if has('gui_running')
set background=dark
colorscheme solarized
else
colorscheme zenburn
endif
let python_highlight_all=1
syntax on
call togglebg#map("<F5>")
set nu
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
放个成品图
https://realpython.com/vim-and-python-a-match-made-in-heaven/