python <tab>自动补全

一。这个方法可以修改shell命令行的自动补全

1.获取python目录【我使用的是64位ubuntu系统】

  1. [~$]python

  2. Python 2.7.3 (default, Apr 10 2013, 06:20:15)

  3. [GCC 4.6.3] on linux2

  4. Type "help", "copyright", "credits" or "license" for more information.

  5. >>> import sys

  6. >>> sys.path

  7. ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',

  8. '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages',

  9. '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0',

  10. '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client',

  11. '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch',

  12. '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

  13. >>>

从上面看出python在我电脑上的路径是  /usr/lib/python2.7

2.切换至该目录写个startup.py的脚本,脚本目录就是处理python中<tab>事件,脚本内容如下

[python]

  1. #!/usr/bin/python

  2. # python startup file

  3. import sys

  4. import readline

  5. import rlcompleter

  6. import atexit

  7. import os

  8. # tab completion

  9. readline.parse_and_bind('tab: complete')

  10. # history file

  11. histfile = os.path.join(os.environ['HOME'], '.pythonhistory')

  12. try:

  13. readline.read_history_file(histfile)

  14. except IOError:

  15. pass

  16. atexit.register(readline.write_history_file, histfile)

  17. del os, histfile, readline, rlcompleter

3.切换至自己主目录

[plain]

  1. [/usr/lib/python2.7$]cd

  2. [~$]vi .bashrc

4. 增加环境变量

[plain]

  1. #for python

  2. export PYTHONSTARTUP=/usr/lib/python2.7/startup.py

5.配置环境变量生效

[plain] 

  1. [~$]source .bashrc

PYTHONSTARTUP是什么东西呢?

[plain] view plaincopyprint?

  1. If this is the name of a readable file, the Python commands in that file are executed before the first prompt

  2. is displayed in interactive mode.  The file is executed in the same name space where interactive commands are

  3. executed so that  objects defined  or  imported in it can be used without qualification in the interactive session.

  4. You can also change the prompts sys.ps1 and sys.ps2 in this file.

二。这个方法能在VIM中自动补全

1. 下载插件:

下载地址:http://download.csdn.net/detail/loovejava/6284225

2.拷贝致相应的目录

[plain] view plaincopyprint?

  1. unzip  pydiction-1.2.1.zip

  2. cp python_pydiction.vim  /usr/share/vim/vim73/ftplugin

  3. mkdir  /usr/share/vim/vim73/pydiction

  4. cp complete-dict  /usr/share/vim/vim73/pydiction/

  5. cp pydiction.py  /usr/share/vim/vim73/pydiction/

3.修改vim配置文件

[plain] view plaincopyprint?

  1. let g:pydiction_location = '/usr/share/vim/vim73/pydiction/complete-dict'

  2. let g:pydiction_menu_height = 20

OK,测试是否生效吧

本文转自crazy_charles 51CTO博客,原文链接:http://blog.51cto.com/douya/1563428,如需转载请自行联系原作者

python2.7 tab,自动补全相关推荐

  1. CentOs6.5 更新python2.7,以及tab自动补全

    #安装python2.7之前,准备工作: yum install python-devel gcc patch readline* -y #解压并安装: tar xf Python-2.7.10.ta ...

  2. python的tab自动补全

    之前一直使用shell编程,习惯了shell的 tab 自动补全功能,而Python的命令行却不支持 tab 自动补全,故而研究让Python命令行支持自动补全功能. 1.首先找到Python调用库路 ...

  3. linux下 为自己编写的程序 添加tab自动补全 功能

    linux下 为自己编写的程序 添加tab自动补全功能 入门 complete 在我的tmp下随便写了一个a.sh, 为他补全 edit /etc/bash_completion.d/foo _foo ...

  4. 如何为 .NET Core CLI 启用 TAB 自动补全功能

    Intro 在 Linux 下经常可以发现有些目录/文件名,以及有些工具可以命令输入几个字母之后按 TAB 自动补全,最近发现其实 dotnet cli 也可以,从.NET Core 2.0 SDK ...

  5. Windows 下python的tab自动补全

    Windows 下python的tab自动补全 对于新学python的朋友来说,python模块的功能多而难记,mac和Linux中有tab自动补全命令功能,使用Windows的同学们怎么办?下面我们 ...

  6. python自动补全_Windows 下python的tab自动补全

    Windows 下python的tab自动补全# 对于新学python的朋友来说,python模块的功能多而难记,mac和Linux中有tab自动补全命令功能,使用Windows的同学们怎么办?下面我 ...

  7. VSCode中tab自动补全标签

    VSCode中tab自动补全标签 今天重置了vscode突然发现tab键不能补齐了,于是翻了翻以前记得笔记,就找到了方法. 进入setting.json文件 加入以下代码 "emmet.tr ...

  8. 解决secureCRT命令不能Tab自动补全问题

    首先打开我们的secureCRT软件 然后找到我们的[选项]---[全局选项] 然后找到我们的[默认会话]并且编辑默认会话 将终端协议改为telnet之后,我们点击此处的[telnet]并且设置 现在 ...

  9. linux python tab补全_python交互模式下实现tab自动补全功能

    建立.pythonstartup文件 $ cat .pythonstartup # cat ~/.pythonstartup # python startup file #!/usr/bin/env ...

最新文章

  1. 基于深度学习的文本数据特征提取方法之Glove和FastText
  2. Nginx在mvvm模式中的使用
  3. java提交数据到另一个页面_JS实现把一个页面层数据传递到另一个页面的两种方式...
  4. Operation category READ is not supported in state standby
  5. optfine的jar文件打不开_JAVA版1.14.4 装了最新版的optifine游戏打不开了 求助大佬们...
  6. java 方法调用关系_JAVA方法调用
  7. RabbitMQ消息接收的确认方式
  8. Windows下Mysql定时备份的实现
  9. Linux运维基础入门(二):网络基础知识梳理02
  10. 2017 软工作业结队第二次作业
  11. Oracle 11g RAC 安装数据库软件找不到节点的解决
  12. 30字的完美个人简历
  13. c++ 调用c# dll修改win10锁屏背景
  14. python进阶day6
  15. 振荡周期、机器周期、指令周期
  16. 教小白使用Vmware安装苹果虚拟机
  17. 匿名科创--匿名拓空者PRO--开源光流融合算法使用教程
  18. c#语言入门 刘老师,c#单元测试实例(学习刘老师视频)
  19. vue3+elementplus倒计时效果按钮
  20. overleaf 写论文Latex语法记录

热门文章

  1. matlab分支定界法linprog_序列比对(二十二)——中间字符串分支定界方法中更紧的界...
  2. java对接支付宝微信银联_JavaWEB后端支付银联,支付宝,微信对接
  3. java日期格式化代码的写法_Java中的`DateTimeFormatter`格式化代码中的`uuuu`与`yyyy`?...
  4. python与jupyter关系,Ipython,jupyter和kernels是什么关系?
  5. linux同一目录文件无法执行,linux – 无法在特定目录中执行文件
  6. 报错,ERROR 2572 --- [MessageBroker-2] o.h.engine.jdbc.spi.SqlExceptionHelper : Column ‘create_by‘
  7. 安卓学习笔记03:安卓应用目录结构
  8. 在Linux上安装JDK9
  9. 【codevs1359】【BZOJ1833】数字计数,进击的学弟与数位DP
  10. 最长上升子序列nlogn算法