Python 自动补全(vim)

yipeiwu_com5年前Python基础

一、vim python自动补全插件:pydiction

可以实现下面python代码的自动补全:

1.简单python关键词补全
2.python 函数补全带括号
3.python 模块补全
4.python 模块内函数,变量补全
5.from module import sub-module 补全

想为vim启动自动补全需要下载插件,地址如下:

http://vim.sourceforge.net/scripts/script.php?script_id=850
https://github.com/rkulla/pydiction

安装配置:

wget https://github.com/rkulla/pydiction/archive/master.zip
unzip -q master
mv pydiction-master pydiction
mkdir -p ~/.vim/tools/pydiction
cp -r pydiction/after ~/.vim
cp pydiction/complete-dict ~/.vim/tools/pydiction

确保文件结构如下:

# tree ~/.vim
/root/.vim
├── after
│   └── ftplugin
│       └── python_pydiction.vim
└── tools
    └── pydiction
        └── complete-dict

创建~/.vimrc,确保其中内容如下:

# cat ~/.vimrc
filetype plugin on
let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'

用vim编辑一个py文件,import os.,这时候应该出现提示,证明成功,如下图

二、python交互模式下Tab自动补齐

创建文件如下:

# cat ~/.pythonstartup
# python startup file
#!/usr/bin/env python
import sys
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
  readline.read_history_file(histfile)
except IOError:
  pass
atexit.register(readline.write_history_file, histfile)
 
del os, histfile, readline, rlcompleter
1
	
echo 'export PYTHONSTARTUP=~/.pythonstartup' >> ~/.bash_profile

重新登陆shell,输入python命令进入交互模式,就可以用Tab键进行补全。如下图:

相关文章

python事件驱动event实现详解

python事件驱动event实现详解

所有的计算机程序都可以大致分为两类:脚本型(单次运行)和连续运行型(直到用户主动退出)。 脚本型:脚本型的程序包括最早的批处理文件以及使用Python做交易策略回测等等,这类程序的特点是...

对Python3中的input函数详解

对Python3中的input函数详解

下面介绍python3中的input函数及其在python2及pyhton3中的不同。 python3中的ininput函数,首先利用help(input)函数查看函数信息: 以上信息...

python使用psutil模块获取系统状态

获取操作系统的当前运行状态和负载情况,是一个系统管理员的基本技能,因为这对我们日常排查故障,定位问题有着非常紧密的联系,比如查看当前系统的基本信息,例如cpu,内存,网络接收包情况,磁盘...

Python3.6.x中内置函数总结及讲解

Python3.6.x中内置函数总结 # -*- coding:utf-8 -*- """ abs() dict() help() min() s...

Windows下PyCharm安装图文教程

Windows下PyCharm安装图文教程

本文记录了PyCharm安装的图文教程,供大家参考,具体内容如下 PyCharm的官网  1.在官网下载安装包 2.选择Windows系统下的社区版本。 3.下载好的安装包...