前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python学习-vim插件安装

python学习-vim插件安装

作者头像
py3study
发布2020-01-06 18:32:08
1.2K0
发布2020-01-06 18:32:08
举报
文章被收录于专栏:python3python3

centos7上自带python2.7,我们需要优化一下python环境。

  1. 一、使用豆瓣源加速软件安装
pip install -i   flask    #使用-i 选项
mkdir ~./pip && vim pip.conf        #修改pip的配置文件
[global]
index-url = https://pypi.douban.com/simple/
image.png
image.png

二、修改.vimrc文件 主要增加一些配置选项,例如显示行号,一键执行等

vim .vimrc

set nocompatible "关闭与vi的兼容模式
set number "显示行号
set nowrap    "不自动折行
set showmatch    "显示匹配的括号
set scrolloff=3        "距离顶部和底部3行"
set encoding=utf-8  "编码
set fenc=utf-8      "编码
set mouse=a        "启用鼠标
set hlsearch        "搜索高亮
syntax on    "语法高亮
au BufNewFile,BufRead *.py
\ set tabstop=4   "tab宽度
\ set softtabstop=4  
\ set shiftwidth=4   
\ set textwidth=79  "行最大宽度
\ set expandtab       "tab替换为空格键
\ set autoindent      "自动缩进
\ set fileformat=unix   "保存文件格式
set foldmethod=indent
set foldlevel=99
map <F8> :call RunPython()<CR>
func! RunPython()
    exec "W"
    if &filetype == 'python'
        exec "!time python2.7 %"
    endif
endfunc

一键F8执行效果

image.png
image.png

三、配置vim插件管理vundle

Vundle 是 Vim bundle 的简称,使用git来管理vim插件,有了它,安装其它插件就方便很多。

创建目录

cd ~
mkdir .vim
cd .vim
mkdir bundle

进入目录,下载文件

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

然后将下列配置放在.vimrc文件的开头:

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()
 
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
 
" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

如果想下载某个插件,比如自动缩进indentpython.vim插件,需要将

Plugin 'vim-scripts/indentpython.vim'

置于call vundle#begin()和call vundle#end()之间,保存配置后在vim中执行

:PluginInstall
image.png
image.png
image.png
image.png

四、多窗口编辑

五、安装常用python插件

  1. 编程提示插件jedi-vim
pip install jedi
git clone --recursive https://github.com/davidhalter/jedi-vim.git ~/.vim/bundle/jedi-vim
image.png
image.png

2.语法检查syntastic

git clone https://github.com/vim-syntastic/syntastic.git
Plugin 'vim-syntastic/syntastic' #.vimrc中增加

3.flak8代码风格检查

pip install flake8
https://github.com/nvie/vim-flake8.git
Plugin 'nvie/vim-flake8'    #.vimrc中添加

按F7进行检查·

image.png
image.png

4.添加树形目录

git clone  
Plugin 'scrooloose/nerdtree'            #.vimrc中添加
map <C-n> :NERDTreeToggle<CR>            #.vimrc中添加 使用Ctrl+n快捷键
image.png
image.png

5.缩进显示 indentline

git clone https://github.com/Yggdroot/indentLine
Plugin 'Yggdroot/indentLine'    #vimrc中添加
image.png
image.png

6.vim-autopep8自动格式化代码

 pip install autopep8
 git clone https://github.com/tell-k/vim-autopep8.git
 Plugin 'tell-k/vim-autopep8' #vimrc中添加
 autocmd FileType python noremap <buffer> <F9> :call Autopep8()<CR>        #使用快捷键F9
image.png
image.png

7.auto-pairs自动补全括号和引号

git clone  
Plugin 'jiangmiao/auto-pairs'

8.ctrlp.vim搜索文件

在vim普通模式下搜索ctl+P即可

Plugin 'kien/ctrlp.vim'
image.png
image.png

8.supertab

使用supertab插件配合jedi-vim,利用tab键进行自动补全

 Bundle 'ervandew/supertab'

在.vimrc中添加

 let g:SuperTabDefaultCompletionType = "context"
 let g:jedi#popup_on_dot = 0

效果如下

image.png
image.png
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()
 
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'davidhalter/jedi-vim'
Plugin 'vim-syntastic/syntastic'
Plugin 'nvie/vim-flake8'
Plugin 'scrooloose/nerdtree'
Plugin 'tell-k/vim-autopep8'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'kien/ctrlp.vim'
Plugin 'jiangmiao/auto-pairs'
Plugin 'ervandew/supertab'
" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required


set nocompatible "关闭与vi的兼容模式
set number "显示行号
set nowrap    "不自动折行
set showmatch    "显示匹配的括号
set scrolloff=3        "距离顶部和底部3行"
set encoding=utf-8  "编码
set fenc=utf-8      "编码
set mouse=a        "启用鼠标
set hlsearch        "搜索高亮
syntax on    "语法高亮
au BufNewFile,BufRead *.py
\ set tabstop=4   "tab宽度
\ set softtabstop=4  
\ set shiftwidth=4   
\ set textwidth=79  "行最大宽度
\ set expandtab       "tab替换为空格键
\ set autoindent      "自动缩进
\ set fileformat=unix   "保存文件格式
set foldmethod=indent
set foldlevel=50
let python_highlight_all=1
let g:SuperTabDefaultCompletionType = "context"
let g:jedi#popup_on_dot = 0

map <F8> :call RunPython()<CR>
func! RunPython()
    exec "W"
    if &filetype == 'python'
        exec "!time python2.7 %"
    endif
endfunc
map <C-n> :NERDTreeToggle<CR>

autocmd FileType python noremap <buffer> <F9> :call Autopep8()<CR>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 6.vim-autopep8自动格式化代码
  • 7.auto-pairs自动补全括号和引号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档