Python 自动补全(vim)
作者:mdxy-dxy 时间:2021-11-06 16:54:42
一、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,自动补全
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python中urllib.unquote乱码的原因与解决方法
2023-08-24 14:56:43
linux下如何备份还原mysql数据库
2010-08-08 08:59:00
keras 简单 lstm实例(基于one-hot编码)
2023-07-11 05:42:04
Python入门教程(十三)Python元组
2023-10-28 08:42:24
![](https://img.aspxhome.com/file/2023/5/81525_0s.png)
解析python调用函数加括号和不加括号的区别
2023-11-30 17:29:50
详细解读python操作json文件的详细
2021-01-31 10:41:42
用Python实现读写锁的示例代码
2022-09-19 13:51:01
Python实现常见的4种坐标互相转换
2023-11-21 06:22:38
![](https://img.aspxhome.com/file/2023/0/63200_0s.png)
JavaScript遍历求解数独问题的主要思路小结
2023-10-13 16:41:14
python 合并列表的八种方法
2022-06-10 10:07:29
Python叠加两幅栅格图像的实现方法
2023-07-25 17:14:06
![](https://img.aspxhome.com/file/2023/5/61485_0s.jpg)
讲解SQL Server 2005数据库的同义词Bug
2008-11-28 14:22:00
解决 jupyter notebook 回车换两行问题
2022-09-11 17:23:46
![](https://img.aspxhome.com/file/2023/3/72793_0s.jpg)
javascript在线游戏:找相同的图片
2008-03-12 12:18:00
Python编程中的异常处理教程
2022-10-16 04:26:23
Python 绘图和可视化详细介绍
2021-02-16 18:17:31
使用Python的turtle模块画国旗
2021-10-22 12:31:10
![](https://img.aspxhome.com/file/2023/4/93724_0s.jpg)
python实现矩阵打印
2023-04-27 06:34:30
![](https://img.aspxhome.com/file/2023/5/75255_0s.jpg)
谈中国站长站的文章干扰码实现方法
2007-10-13 11:13:00
![](https://img.aspxhome.com/file/UploadPic/up/2007101313560193.jpg)
深入浅析Python中join 和 split详解(推荐)
2022-09-19 17:43:38