1、安裝readline-devel包python
Python的編譯安裝依賴於這個包git
yum -y install readline-develgithub
Python官方網站(到此處下載):https://www.python.org/shell
# tar xf Python-2.7.12.tgzvim
# cd Python-2.7.12bash
# ./configure --prefix=/usr/local/python27python2.7
# make && make install編輯器
# ln -sv /usr/local/python27/bin/python2.7 /usr/bin/python27測試
1、下載Python自動補全插件: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
二、~/.vim的目錄結構以下:
# tree ~/.vim
/root/.vim
├── after
│ └── ftplugin
│ └── python_pydiction.vim
└── tools
└── pydiction
└── complete-dict
三、編輯~/.vimrc,加入以下內容
filetype plugin on
let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'
四、用vim編輯一個py文件,測試是否成功
出現上圖狀況說明配置成功了
一、在Python的安裝目錄下/usr/local/python27/lib/python2.7/site-packages添加tab.py文件
tab文件內容以下:
#!/usr/bin/env python27 # python startup file
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
二、添加環境變量:
#vim ~/.bashrc添加以下內容:
#for python tab
export PYTHONSTARTUP=/usr/local/python27/lib/python2.7/site-packages/tab.py
三、從新登陸shell進行測試:
和shell的用法一下,按一下tab鍵補全,按兩下tab鍵會列出全部以輸入字符開頭可用的命令。