linux vim python编辑代码补全

在网上折腾了好久,找了好多的文章,比如什么Pydiction 这个插件,最后还是没办法使用。最终找到了jedi-vim这个插件,以下说明下这个插件的用法:

第一步:升级vim到8.0
最新jedi-vim 插件需要 Vim 的版本至少不应该低于7.3,并且需要支持 python2 或 python3 ,可以用vim --version 查看版本号,如下图显示,不支持python2 跟python3,需要重新编译安装。

在这里插入图片描述
执行先卸载原来的:
apt-get remove vim-tiny vim-common

第二步:安装依赖包:
apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev \
libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \
python3-dev ruby-dev lua5.1 lua5.1-dev git
第三步:下载vim源码并安装
cd ~
git clone https://github.com/vim/vim.git
cd vim
 ./configure --with-features=huge \
          --enable-multibyte \
          --enable-rubyinterp=yes \
          --enable-pythoninterp=yes \
          --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu  \
          --enable-python3interp=yes \
          --with-python3-config-dir=/usr/lib/python3.5/config-x86_64-linux-gnu  \
          --enable-perlinterp=yes \
          --enable-luainterp=yes \
          --enable-gui=gtk2 --enable-cscope --prefix=/usr
make VIMRUNTIMEDIR=/usr/share/vim/vim80 
make install  

其中参数说明如下: 
–with-features = huge:支持最大特性 
–enable-multibyte:多字节支持可以在Vim中输入中文 
–enable-rubyinterp:启用Vim对ruby编写的插件的支持 
–enable-pythoninterp:启用Vim对python2 编写的插件的支持 
–enable-python3interp: 启用Vim对python3 编写的插件的支持 
–enable-luainterp:启用Vim对于lua 编写的插件的支持 
–enable-perlinterp:启用Vim对perl编写的插件的支持 
–enable-cscope:Vim对cscope支持 
–with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu :指定python路径 
–enable-gui = gtk2:gtk2支持,也可以使用gnome,表示生成gvim 
-prefix = / usr:编译安装路径
第四步:非必需,可不执行

可以安装checkinstall工具将从源码安装的软件变得像用deb包安装的一样,方便以后可以直接用sudo dpkg -P vim删除vim:

apt-get install checkinstall
cd vim
checkinstal
第五步:设置vim默认编辑器

试了下,设置失败了,不过也不影响

update-alternatives --install /usr/bin/editor editor /usr/bin/vim 1
update-alternatives --set editor /usr/bin/vim
update-alternatives --install /usr/bin/vi vi /usr/bin/vim 1
update-alternatives --set vi /usr/bin/vim

以上步骤是升级vim8的操作,以下操作是安装vim8插件的操作:

第六步:下载Vundl管理插件
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
第七步:配置.vimrc
vim  ~/.vimrc

set nocompatible              " be iMproved, required
filetype off                  " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'git://git.wincent.com/command-t.git'
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
Plugin 'davidhalter/jedi-vim'
call vundle#end()            " required
filetype plugin indent on    " required
let g:jedi#completions_enabled = 1
set backspace=indent,eol,start
" 设置utf8编码
set fileencodings=utf-8,gbk,cp936
set fileencoding=utf-8
set encoding=utf-8
set termencoding=utf-8
" 设置标签栏
set showtabline=2

" 去除启动界面
set shortmess=atI

" 设置帮助信息为中文
set helplang=cn

" 设置自动对齐
set autoindent
set smartindent

" 设置c系缩进方式
set cindent
set tabstop=4

" 空格替换Tab
set expandtab
set shiftwidth=4
set softtabstop=4
set smarttab

" 增强命令补全
set wildmenu
" 设置语法高亮
syntax enable
"
" 显示行数
" set nu
第八步:安装jedi插件

vim ~/.vimrc 打开该文件
在这里插入图片描述

:PluginInstall ##插入模式下输入

看到提示done完成,才退出来。这样就完成了。
在这里插入图片描述

第九步:验收
输入导入time模块,然后按"."即可使用(但目前还不支持import 时候自动显示库的功能)

在这里插入图片描述

参考文档:
https://github.com/davidhalter/jedi-vim
https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source
https://github.com/VundleVim/Vundle.vim

额外操作:安装YouCompleteMe插件,功能类似jedi
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/plugged/
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer 

这一步操作可能不成功,不成功的话先执行下面的

 git submodule update --init --recursive
apt-get install build-essential cmake 
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值