Python 自动补全(vim)
2019/7/13 21:38:51
本文主要是介绍Python 自动补全(vim),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、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 自动补全(vim)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-04Python外包有哪些常见的主要库-icode9专业技术文章分享
- 2024-10-02基于深度学习的钢铁缺陷检测系统(yolov8、注意力机制、PyQt5界面、Python)
- 2024-10-01怎么用python搭建一个系统-icode9专业技术文章分享
- 2024-09-30Python基础入门教程
- 2024-09-30获取参数学习:Python中的基础教程
- 2024-09-30Python编程基础详解
- 2024-09-29点击加载学习:Python编程基础教程
- 2024-09-29数据科学五大Python前端库:第二部分
- 2024-09-27使用python 将ETH账户的资产打散
- 2024-09-26Python编程基础