vim编程配置python3开发环境初级(两个版本)

建议直接尝试相对简单的第二版

vim第一版(该版本也默认不支持python3)

Centos7.3 的自带vim版本为7.4,只支持python2不支持python3,故升级为vim8

1、卸载原vim安装8.0的vim

1.yum -y remove vim  
或(第二种会导致没有sudo命令,建议先别尝试)
rpm -Uvh http://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm
rpm --import http://mirror.ghettoforge.org/distributions/gf/RPM-GPG-KEY-gf.el7
yum -y remove vim-minimal vim-common vim-enhanced sudo
yum -y --enablerepo=gf-plus install vim-enhanced sudo

2、安装dirccolors

git clone https://github.com/seebi/dircolors-solarized.git

cd dircolors-solarized/


mv dircolors.ansi-dark ~/.dircolors
#配置环境变量
vim /etc/profile
export TERM=xterm-256color
if [ -x /usr/bin/dircolors ]; then
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias tree='tree -C'
fi

3、安装依赖



yum -y install python-devel ruby ruby-devel perl perl-devel perl-ExtUtils-Embed

yum install ncurses-devel

yum install ctags
yum -y install libXt-devel gtk2-devel 
 

4安装Python3.6

1)前往用户根目录
>: cd ~

2)下载  Python3.6
下载3.6.8
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz

3)解压安装包
>:tar xJf Python-3.6.8.tar.xz

4)进入目标文件

>:cd Python-3.6.8

5)配置安装路径:/usr/local/python3
>:./configure --prefix=/usr/local/python3

6)编译并安装
>: make && sudo make install

7)建立软连接:终端命令 python3,pip3
>: ln -s /usr/local/python3/bin/python3 /usr/bin/python3
>: ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3


5\配置pip源:

1)创建pip配置路径
>: mkdir ~/.pip

2)进入目录编辑配置文件:填入下方内容
cd ~/.pip && vim pip.conf

[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com

6\安装vendle

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

touch ~/.vimrc

touch ~/.vimrc.bundles

if &compatible
  set nocompatible
end

filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Plugin 'VundleVim/Vundle.vim'
Plugin 'altercation/vim-colors-solarized'
Plugin 'tomasr/molokai'
Plugin 'vim-scripts/phd'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'octol/vim-cpp-enhanced-highlight'
Plugin 'derekwyatt/vim-fswitch'
Plugin 'vim-scripts/a.vim'
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 'scrooloose/nerdcommenter'
Plugin 'vim-scripts/DrawIt'
Plugin 'SirVer/ultisnips'
Plugin 'Valloric/YouCompleteMe'
Plugin 'rdnetto/YCM-Generator'
Plugin 'derekwyatt/vim-protodef'
Plugin 'scrooloose/nerdtree'
Plugin 'gcmt/wildfire.vim'
Plugin 'sjl/gundo.vim'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'suan/vim-instant-markdown'
Plugin 'qpkorr/vim-bufkill'
Plugin 'skywind3000/asyncrun.vim'
 if filereadable(expand("~/.vimrc.bundles.local"))
  source ~/.vimrc.bundles.local
endif
filetype on

# 备份,非此次操作所需
if &compatible
  set nocompatible
end

filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" Let Vundle manage Vundle
Bundle 'gmarik/vundle'
" Define bundles via Github repos
" 标签导航
Bundle 'majutsushi/tagbar'
Bundle 'vim-scripts/ctags.vim'
" 静态代码分析
Bundle 'scrooloose/syntastic'
" 文件搜索
Bundle 'kien/ctrlp.vim'
" 目录树导航
Bundle "scrooloose/nerdtree"
" 美化状态栏
Bundle "Lokaltog/vim-powerline"
" 主题风格
Bundle "altercation/vim-colors-solarized"
" python自动补全
Bundle 'davidhalter/jedi-vim'
Bundle "klen/python-mode"
" 括号匹配高亮
Bundle 'kien/rainbow_parentheses.vim'
" 可视化缩进
Bundle 'nathanaelkane/vim-indent-guides'
if filereadable(expand("~/.vimrc.bundles.local"))
  source ~/.vimrc.bundles.local
endif
filetype on                      

7、下载编译ycm


 
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
 
cd ~/.vim/bundle/YouCompleteMe
 
git submodule update --init --recursive
报错
无法克隆 'https://go.googlesource.com/tools' 到子模组路径 'third_party/go/src/golang.org/x/tools'
解决:
cd ~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x

git clone https://github.com/golang/tools.git

#回到 YouComplateMe 目录继续安装其他子模块
cd ~/.vim/bundle/YouCompleteMe

# 继续子模块的安装
git submodule update --init --recursive

8\在vundel中安装插件


Plugin 'gmarik/Vundle.vim'
Plugin 'Valloric/YouCompleteMe’

9\

cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
#报错
ERROR: Unable to find executable 'cmake'. CMake is required to build ycmd
#解决
wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz
 
tar xvf cmake-3.6.2.tar.gz && cd cmake-3.6.2/
 
./bootstrap
gmake
gmake install
 

10\ycm进行nodejs和golang的补全


cd ~/.vim/bundle/YouCompleteMe

./install.py  --clang-completer  --gocode-completer --tern-completer

vim配置第二版

1、.vimrc文件的配置

# 1.在根目录下创建.vimrc文件,
vim .vimrc

2、安装插件管理器vim.plug

# github官网安装命令
curl -fLo ~/.vim/autoload/plug.vim --create-dirs     https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
#copy 官方案例


官方案例只需保留以下两行,写到 .vimrc文件,准备在这两行之间安装‘’需要的插件‘’

" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Initialize plugin system
call plug#end()

3、插件安装实例

# 插件1,开屏插件 vim-startify
https://github.com/mhinz/vim-startify
# 插件名,写在.vimrc文件plug内
 Plug 'mhinz/vim-startify'
 # 按esc,输入:
 :source ~/.vimrc
 # 按回车,再输入
 :PlugInstall

步骤图1

[外链图片转存失败(img-6IrqUquK-1568016673102)(/Users/bobwang/Library/Application Support/typora-user-images/image-20190907184715608.png)]

步骤图2

[外链图片转存失败(img-9v8CkvDV-1568016673103)(/Users/bobwang/Library/Application Support/typora-user-images/image-20190907185028493.png)]

安装完成后,输入:qa 退出全部窗口

:qa

再输入vim,发现有如下开机显示

[外链图片转存失败(img-kj6gvMmh-1568016673104)(/Users/bobwang/Library/Application Support/typora-user-images/image-20190907185524039.png)]

4、其他插件查找

https://vimawesome.com/

5、常用插件

#1、修改状态栏
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
#2 缩进线
Plug 'yggdroot/indentline'
#3、配色
Plug 'w0ng/vim-hybrid'
:colorscheme hybrid  按回车
# 如果安装失败试下一种方式
git clone https://github.com/w0ng/vim-hybrid.git
# 移动文件到.vim/colors/,没有就先创建
mkdir  .vim/colors
cp vim-hybrid/colors/hybrid.vim  ./.vim/colors/ 
# 配色持久化
set background=dark
colorscheme hybrid
#4、目录树
Plug 'scrooloose/nerdtree'
autocmd vimenter * NERDTree 自动开启目录
#5 模糊搜索器
Plug 'ctrlpvim/ctrlp.vim'  
// 按下ctrl+p 开启模糊搜索文件
#6、快速定位插件easymotion
Plug 'easymotion/vim-easymotion'
# 设置映射
nmap ss <Plug>(easymotion-s2)

6、go插件(前提是能访问go的官方网站)

Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }

7.python mode

Plug 'python-mode/python-mode', { 'for': 'python', 'branch': 'develop' }

8.自动补全代码deplete.vim

if has('nvim')
  Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
  Plug 'Shougo/deoplete.nvim'
  Plug 'roxma/nvim-yarp'
  Plug 'roxma/vim-hug-neovim-rpc'
endif
Plug 'deoplete-plugins/deoplete-jedi'
let g:deoplete#enable_at_startup = 1
set completeopt-=preview

bug:

vim-hug-neovim-rpc] Vim(pythonx):ModuleNotFoundError: No module named ‘neovim’

#解决
pip3 install pynvim

.vimrc配置

set nu
set background=dark
colorscheme murphy
set nocompatible
set encoding=utf-8
set showmatch

call plug#begin('~/.vim/plugged')
 
    Plug 'mhinz/vim-startify'
 
    Plug 'yggdroot/indentline'
 
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
 
    Plug 'w0ng/vim-hybrid'
    Plug 'scrooloose/nerdtree'
    Plug 'ctrlpvim/ctrlp.vim'
    Plug 'easymotion/vim-easymotion'
    Plug 'python-mode/python-mode', { 'for': 'python', 'branch': 'develop' }
if has('nvim')
    Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
    Plug 'Shougo/deoplete.nvim'
    Plug 'roxma/nvim-yarp'
    Plug 'roxma/vim-hug-neovim-rpc'
endif
  	Plug 'deoplete-plugins/deoplete-jedi'
     
call plug#end()
let g:pymode_python = 'python3'
let g:pymode_trim_whitespaces = 1
let g:pymode_doc = 1
let g:pymode_doc_bind = 'K'
let g:pymode_rope_goto_definition_bind = ""
let g:pymode_lint = 1
let g:pymode_lint_checkers = ['pyflakes', 'pep8', 'pylink']
let g:pymode_options_max_line_length = 120

let g:deoplete#enable_at_startup = 1
set completeopt-=preview

你可能感兴趣的:(vim)