如何在vim中使用tab進行python代碼補全

來源:互聯網
上載者:User
Pydiction 允許你在 Vim 中實現 TAB 代碼補全, 可以補全的內容包括:標準的、自訂的,以及第三方模組和包。外加關鍵字、BIFs,和字串。

Pydiction 由 3 個主要檔案構成:

python_pydiction.vim -- 該檔案為 Vim 的 plugin 檔案,實現 Python 檔案的 TAB 補全功能。

complete-dict -- 該檔案為 Vim 的 dictionary 檔案,其中包含 Python 關鍵字和模組結構等資訊。是 plugin 進行補全時所尋找的參考檔案。

pydiction.py -- (可選)該檔案是 Python script 檔案,用於產生 dictionary 檔案。可以通過執行該指令碼添加更多的可 TAB 補全模組。


用法

=====

在 Vim 中輸入部分 Python 關鍵字、模組名、屬性或方法名,然後按 Tab 鍵以彈出補全資訊。

例如, 輸入

os.p

會彈出

os.pardir

os.path

os.pathconf(

os.pathconf_names

os.pathsep

os.pipe(

...


如果你發現在 TAB 完成菜單中得到的結果並不是你想要的,可能的一種原因是你沒有設定 Vim 忽略大小寫。可以通過 ":set noic" 方式進行設定。

【如何安裝】

在 UNIX/LINUX 下,將 python_pydiction.vim 放入 ~/.vim/after/ftplugin/ ,若該目錄不存在則手動建立,Vim 會自動去該目錄下尋找相關檔案。不要把除 python_pydiction.vim 之外的其他檔案放入該目錄。

在你的 vimrc 檔案中增加下面的欄位來啟用 ftplugins :

filetype plugin on

之後確保設定 "g:pydiction_location" 指向你放置的 complete-dict 檔案所在的全路徑,例如

let g:pydiction_location = 'C:/vim/vimfiles/ftplugin/pydiction/complete-dict'

設定可以參考

# unzip pydiction-1.2.zip

# cp python_pydiction.vim /usr/share/vim/vim70/ftplugin

# mkdir /usr/share/vim/vim70/pydiction

# cp complete-dict pydiction.py /usr/share/vim/vim70/pydiction/

# vi ~/.vimrc

...

# 增加

let g:pydiction_location = '/usr/share/vim/vim70/pydiction/complete-dict'

let g:pydiction_menu_height = 20

開啟 python 指令檔,在編寫 python 程式時,按 TAB 鍵即可啟用自動補全菜單。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.