vim的卸载以及环境的配置小记

一、背景

由于之前配置错误,导致我的YouCompleteMe这个插件不能用了,一直提示:

ERROR:Required vim compiled with +python.
YouCompleteMe unavailable: Required vim compiled with Python2.7.1+ or 3.4+ support.

然而我通过vim --version(或者vim --version | grep python)查看到我是有python支持的啊,+python/dyn和+python3/dyn。但是就是提示python不可用,也尝试了echo has('python')echo has('python3'),但return的结果都是0,不是1。
最终通过一番查阅资料发现了问题关键,进入vim并输入:h python-2-and-3,回车结果如下:

意思就是说当使用全局符号时,会导致第二个版本的python崩溃,所有当使用全局符号时只能一根版本的python是有效的。
然后这里是debian系统维护者曾经写的一封解释信(Google到的),附上链接:(https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=10;att=0;bug=729924)

On Mon, Nov 18, 2013 at 05:59:02PM -0500, Barry Warsaw wrote:
> I'm not a vim user but I'm am very interested in porting the world to
> Python 3.  To that end, I see that the current version of upstream vim
> supports Python 3, but building that is not currently enabled in the
> Debian package.

This is due to two things.

First, the way Debian builds Python prevents loading both libpython2 and
libpython3 in the same process, since Debian's builds necessitate
passing RTLD_GLOBAL to dlopen().  This means that when Vim is built to
support both Python 2 & 3, one has to choose between using plugins that
target Python 2 or Python 3 instead of the user being able to use both.

At the time, this meant I had to choose one and I went with Python 2 due
to the much higher prevalence of plugins targeting it.  While Python 3
has gained a lot of ground since then and it's much more easy to write
code that works in both versions, my understanding is that the
RTLD_GLOBAL issue still exists.  This means I still need to choose one
version and, while it's more of a toss up now, I think Python 2 is still
the right call here.

Second, I'm not keen on the state of dependency tracking with software
that dynamically loads libraries instead of linking against them.  If
Vim dynamically loaded its own code that provides the language bindings,
and those were linked against the proper language libraries, then I
could easily provide vim-{lua,perl,python,ruby,tcl}-bindings packages
which expressed proper relationships on the corresponding language
libraries.

Since that isn't the case, we can then run into situations where bad
things happen during a library transition due to nothing telling the
transition trackers that Vim should actually be rebuilt or forcing the
users to upgrade Vim in sync with the library.  See #611573 for some
previous discussion about this related to Vim's Perl support.

Cheers,
-- 
James
GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <[email protected]>

This means that when Vim is built to support both Python 2 & 3, one has to choose between using plugins that target Python 2 or Python 3 instead of the user being able to use both.

意思就是说debian系统中python2和python3是运行在同一进程的,也就意味着你只能选择其中一个版本来使用,用python2就不能同时用python3。
综上来看,解决办法只能是重新编译vim啦,舍去其中一个python版本。

二、vim的卸载:

  • 1、使用apt-get的方式:
1、sudo apt-get autoremove vim vim-common vim-tiny vim-runtime
  • 2、然后dpkg -l | grep vim看一下是否还存在有vim,如果有,请到dpkg -l中可看到你所有安装的软件,若有vim,那么卸载的时候可以用这两种方式;如果没有,那就全部卸载完成:
    (PS:我的遇见了这种情况,apt-get autoremove 方式并没有把所有的vim环境给我删除掉,当时郁闷了好久。)
1、sudo dpkg --purge vim vim-common vim-addon-manager      # 此种方式使用--purge参数,可将配置文件与安装文件一同删除
2、sudo dpkg -r vim vim-common vim-addon-manager      # 此种方式只删除安装文件、不能删除配置文件

三、重新安装vim以及配置

1. vim安装:
以我的为例,全程在root环境下:

step1: mkdir /opt/vim
step2: git clone https://github.com/vim/vim.git
step3: unzip vim-master.zip
step4: cd vim-master/
step5: make clean      make distclean
step6: 安装依赖库:apt-get install libncurses5-dev python-dev python3-dev libgtk3.0-dev libatk1.0-dev libbonoboui2-dev libcairo2-dev libx11-dev libxpm-dev libxt-dev
step7: ./configure --with-features=huge --enable-multibyte --enable-rubyinterp --enable-python3interp --enable-luainterp --enable-cscope --enable-gui=gtk3 --enable-perlinterp --with-python3-config-dir=/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/ --prefix=/usr/local/vim
step8: make
step9: make install

在上面step7中,我选择了使用python3,如果使用python2的,请对应更改:--enable-python3interp为--enable-pythoninterp,--with-python3-config-dir=/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/为--with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu/
相关参数说明

--with-features=huge:支持最大特性
--enable-rubyinterp:打开对 ruby 编写的插件的支持
--enable-pythoninterp:打开对 python 编写的插件的支持
--enable-python3interp:打开对 python3 编写的插件的支持
--enable-luainterp:打开对 lua 编写的插件的支持
--enable-perlinterp:打开对 perl 编写的插件的支持
--enable-multibyte:打开多字节支持,可以在 Vim 中输入中文
--enable-cscope:打开对cscope的支持
--enable-gui=gtk3 表示生成采用 GNOME3 风格的 gvim
--with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu/ 指定 python 路径
--with-python3-config-dir=/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/ 指定 python3路径
--prefix=/usr/local/vim:指定将要安装到的路径

2. vim配置
- 安装 vim 的插件管理器 vundle,退出root环境,为普通用户:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
- vim ~/.vimrc,配置如下:
" vundle 环境设置
set nocompatible     " be IMproved, required
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
" vundle 管理的插件列表必须位于 vundle#begin() 和 vundle#end() 之间
call vundle#begin()
" Let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
......  " 你自己需要的Plugin插件放在这里,例如:Plugin "Valloric/YouCompleteMe"
" All of your plugins must be added before the following line!
call vundle#end()
filetype plugin indent on

配置完后,:wq保存退出,并重新进入~/.vimrc,执行PluginInstall。

相关配置如下,参考:

"开启真彩色支持
set termguicolors
"开启256色支持
set t_Co=256
 
" 定义快捷键前缀 <Leader>
let mapleader=";"
" 开启文件类型侦测
filetype on
" 根据不同文件类型加载不同插件
filetype plugin on
" 定义快捷键到行首和行尾
nmap LB 0
nmap LE $
" 设置快捷键将选中文本块复制至系统剪贴板
vnoremap <Leader>y "+y
" 设置快捷键将系统剪贴板内容粘贴至 vim
nmap <Leader>p "+p
" 定义快捷键关闭当前分割窗口
nmap <Leader>q :q<CR>
" 定义快捷键保存当前窗口内容
nmap <Leader>w :w<CR>
" 定义快捷键保存所有窗口内容并退出 vim
nmap <Leader>WQ :wa<CR>:q<CR>
" 不做任何保存,直接退出 vim
nmap <Leader>Q :qa!<CR>
" 依次遍历子窗口
nnoremap nw <C-W><C-W>
" 跳转至右方的窗口
nnoremap <Leader>lw <C-W>l
" 跳转至左方的窗口
nnoremap <Leader>hw <C-W>h
" 跳转至上方的子窗口
nnoremap <Leader>kw <C-W>k
" 跳转至下方的子窗口
nnoremap <Leader>jw <C-W>j
" 定义快捷键在结对符之间跳转
nmap <Leader>M %
 
" 开启实时搜索功能
set incsearch
" 搜索时大小写不敏感
set ignorecase
" 关闭兼容模式
set nocompatible
" vim 自身命令行模式智能补全
set wildmenu
 
" vundle 环境设置
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
" vundle 管理的插件列表必须位于 vundle#begin() 和 vundle#end() 之间
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'altercation/vim-colors-solarized'
Plugin 'tomasr/molokai'
Plugin 'vim-scripts/phd'
Plugin 'Lokaltog/vim-powerline'
Plugin 'octol/vim-cpp-enhanced-highlight'
Plugin 'nathanaelkane/vim-indent-guides'
Plugin 'derekwyatt/vim-fswitch'
Plugin 'kshenoy/vim-signature'
Plugin 'vim-scripts/BOOKMARKS--Mark-and-Highlight-Full-Lines'
Plugin 'majutsushi/tagbar'
Plugin 'vim-scripts/indexer.tar.gz'
Plugin 'vim-scripts/DfrankUtil'
Plugin 'vim-scripts/vimprj'
Plugin 'dyng/ctrlsf.vim'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'scrooloose/nerdcommenter'
Plugin 'vim-scripts/DrawIt'
Plugin 'SirVer/ultisnips'
Plugin 'davidhalter/jedi-vim'       " jedi-vim提供python语法、自动补全等支持
Plugin 'Valloric/YouCompleteMe'
Plugin 'derekwyatt/vim-protodef'
Plugin 'scrooloose/nerdtree'
Plugin 'fholgado/minibufexpl.vim'
Plugin 'gcmt/wildfire.vim'
Plugin 'sjl/gundo.vim'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'suan/vim-instant-markdown'
Plugin 'lilydjwg/fcitx.vim'
Plugin 'iCyMind/NeoSolarized'
" 插件列表结束
call vundle#end()
filetype plugin indent on
" 配色方案
set background=dark
colorscheme NeoSolarized
 
" 总是显示状态栏
set laststatus=2
" 显示光标当前位置
set ruler
" 开启行号显示
set number
" 使用 NERDTree 插件查看工程文件。设置快捷键,速记:file list
nmap <Leader>fl :NERDTreeToggle<CR>
" 设置NERDTree子窗口宽度
let NERDTreeWinSize=32
" 设置NERDTree子窗口位置
let NERDTreeWinPos="rigth"
" 显示隐藏文件
let NERDTreeShowHidden=1
" NERDTree 子窗口中不显示冗余帮助信息
let NERDTreeMinimalUI=1
" 删除文件时自动删除文件对应 buffer
let NERDTreeAutoDeleteBuffer=1
" 高亮显示当前行/列
set cursorline
"set cursorcolumn
" 高亮显示搜索结果
set hlsearch
 
" 设置 gvim 显示字体
set guifont=YaHei\ Consolas\ Hybrid\ 11.5
" 禁止折行
set nowrap
 
" 设置状态栏主题风格
let g:Powerline_colorscheme='solarized256'
" 开启语法高亮功能
syntax enable
" 允许用指定语法高亮配色方案替换默认方案
syntax on
" 自适应不同语言的智能缩进
filetype indent on
" 将制表符扩展为空格
set expandtab
" 设置编辑时制表符占用空格数
set tabstop=4
" 设置格式化时制表符占用空格数
set shiftwidth=4
" 让 vim 把连续数量的空格视为一个制表符
set softtabstop=4
 
 
" 随 vim 自启动
let g:indent_guides_enable_on_vim_startup=1
" 从第二层开始可视化显示缩进
let g:indent_guides_start_level=2
" 色块宽度
let g:indent_guides_guide_size=1
" 快捷键 i 开/关缩进可视化
:nmap <silent> <Leader>i <Plug>IndentGuidesToggle

至此,vim基本的安装配置就完成了,之前的问题也就解决了,效果如下:


补充:vim8支持vim编辑栏中分出一个shell窗口,可一边编辑代码,一边运行。命令:“:terminal”


猜你喜欢

转载自www.cnblogs.com/cpl9412290130/p/10084133.html