1、交换模式自动补齐

#登陆python交换模式,导入sys模块,sys.path查看python搜索路径

[root@python python]# pythonPython 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import sys>>> sys.path['', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib/python2.6/site-packages']>>>

#切换到python第三方模块搜索路径下,创建tab.py模块文件

[root@python python]# cd /usr/lib64/python2.6/site-packages[root@python site-packages]# cat tab.py
#!/usr/bin/python#pyton startup tabimport sysimport readlineimport rlcompleterimport atexitimport osreadline.parse_and_bind('tab: complete')histfile = os.path.join(os.environ['HOME'], '.pythonhistory')try:    readline.read_history_file(histfile)except IOError:   passatexit.register(readline.write_history_file,histfile)del os,histfile,readline,rlcompleter

#在交换模式下导入tab模块,测试tab补齐

>>> import tab,sys>>> sys.sys.__class__(              sys.executablesys.__delattr__(            sys.exit(sys.__dict__                sys.exitfunc(sys.__displayhook__(        sys.flagssys.__doc__                 sys.float_info

2、vim编辑模式下TAB自动补齐

首先下载vim中Tab建第三方模块,其中也介绍详细的使用方法

官网地址:http://rkulla.github.io/pydiction/

wget https://github.com/rkulla/pydiction/zipball/masterunzip -q mastercd rkulla-pydiction-41c7143/

在宿主目录下创建(.vim)文件夹,官网介绍,complete-dict和pydiction.py这两个文件只能安装在(.vim)目录下

[root@python rkulla-pydiction-41c7143]# mkdir ~/.vim[root@python rkulla-pydiction-41c7143]# \cp after/ ~/.vim -r[root@python rkulla-pydiction-41c7143]# \cp complete-dict ~/.vim[root@python rkulla-pydiction-41c7143]# cd ~/.vim[root@python .vim]# tree.├── after│   └── ftplugin│       └── python_pydiction.vim└── complete-dict

在宿主目录下,新建文件(.vimrc),开启filetype插件,指定complete-dict的完整路径:

[root@python .vim]# vim ~/.vimrc"python TAB补齐"启用filetype插件filetype plugin on"指定complete-dict的完整路径let g:pydiction_location = '~/.vim/complete-dict'"设置菜单的高度,默认为8let g:pydiction_menu_height = 3

测试是否生效:

spacer.gif

注意:vim编辑文件只针对后缀为.py的文件,或者在文件开头声明为python运行的头信息(#!/usr/bin/python)

附个人vim配置文件:

cat ~/.vimrc

"语法高亮syntax on"显示行号set number"启用鼠标set mouse=aset selection=exclusiveset selectmode=mouse,key"侦听文件类型filetype on"记录历史的行数set history=1000"下划线高亮显示光标所在行set cursorline"背景使用黑色set background=dark"第一行设置tab键为4个空格,第二行设置当行之间交错时使用4个空格set tabstop=4"设置自动缩进长度为4格set shiftwidth=4"在编辑过程中,在右下角显示光标位置的状态行set ruler"设置编码自动识别,中文引号显示set fileencoding=uft-8set ambiwidth=double"设置高亮搜索set hlsearch"在搜索时,输入的词句的逐字符高亮set incsearch"显示括号匹配set showmatch"括号匹配显示时间为1(单位是十分之一秒)set matchtime=1"python TAB补齐"启用filetype插件filetype plugin on"指定complete-dict的完整路径let g:pydiction_location = '~/.vim/complete-dict'"设置菜单的高度,默认为8let g:pydiction_menu_height = 3