180807 16步Ubuntu下利用YouCompleteMe配置Anaconda+Vim自动补齐tensorflow+keras+pytorch

参考博客

参考1-让vim支持python3的自动补全【促使我利用YouCompleteMe配置Anaconda环境】
参考2-Ubuntu16.04下配置YouCompleteMe【常规安装套路】
参考3-Ubuntu16.04 为vim安装YouCompleteMe插件【主要参考这篇文章成功安装YCM】
参考4-ycm_core loading issues on Ubuntu 16.04 #2136【在这里找到了Anaconda环境无法识别的原因】
参考5-YouCompleteMe does not work with Anaconda Python #1241【另外一种配置Vim+Anaconda的方法(未实验)】
参考6-Ubuntu16.04 为vim安装YouCompleteMe插件【转载的参考3,内容一模一样】
参考7-一步一步带你安装史上最难安装的 vim 插件 —— YouCompleteMe【评论很多的一篇博客】


安装方法:

  • Step-1:安装vim:sudo apt-get install vim-gtk
  • Step-2:查看vim对python的支持:vim --version | grep python
  • Step-3:安装CMake:sudo apt-get install build-essential cmake
  • Step-4:安装python-dev:sudo apt-get install python-dev python3-dev
  • Step-5:安装YouCompleMegit clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  • Step-6:复制YCM官网vimrc文件到/home根目录下,通过显示隐藏文件查看以及后续编辑操作
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)

" 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'}

" cs Plugin
Plugin 'Valloric/YouCompleteMe'

" 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
  • Step-7:在.vimrcbegin/end之间添加PluginInstall 'Valloric/YouCompleteMe'如图所示
  • Step-8:ctrl+alt+T打开terminal输入vim激活打开vim
  • Step-9:键盘输入:PluginInstall就可以开始安装YouCompleteMe.vimrc中的其他插件(网络原因,速度巨慢!)解决方法如下:
    先下载再配置安装:
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle  
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe  
cd ~/.vim/bundle/YouCompleteMe  
git submodule update --init --recursive 
  • Step-10:切换到YouCompleteMe目录
  • Step-11:最重要的一步:利用Anaconda中的python3执行python3 ./install.py文件
    180807 16步Ubuntu下利用YouCompleteMe配置Anaconda+Vim自动补齐tensorflow+keras+pytorch_第1张图片
    如下图所示,默认状态下的python3Anaconda的python3
    180807 16步Ubuntu下利用YouCompleteMe配置Anaconda+Vim自动补齐tensorflow+keras+pytorch_第2张图片
  • Step-12:根据需要参考参考3,进行相关配置(感觉非必要)
  • Step-13-1:如果需要vim自动补齐Anaconda自带环境下的site-packages则在.vimrc最后添加下面第一行,并保存
  • Step-13-2:如果需要vim自动补齐Anaconda虚拟环境envs下的site-packages则在.vimrc最后添加下面第二行,并保存
let g:ycm_python_binary_path  = '/home/brucelau/anaconda3/bin/python3.6'

let g:ycm_python_binary_path  = '/home/brucelau/anaconda3/envs/fcn/bin/python3.5'
  • Step-14:利用Vim创建或编辑.py文件
  • Step-15:Tab键可自动显示补齐模块内容

180807 16步Ubuntu下利用YouCompleteMe配置Anaconda+Vim自动补齐tensorflow+keras+pytorch_第3张图片

  • Step-16:虚拟环境下记得激活虚拟环境source activate envs_name才可运行程序

PS:.vimrc文件设置截图

你可能感兴趣的:(Installation)