天天看點

【原創】如何在vim中使用tab進行python代碼補全

      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<tab>  

會彈出 

        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'  

網上有人做如下設定可以參考 

<a href="http://my.oschina.net/moooofly/blog/170696#">?</a>

1

2

3

4

5

6

7

8

9

10

<code># unzip pydiction-1.2.zip</code>

<code># cp python_pydiction.vim /usr/share/vim/vim70/ftplugin</code>

<code># mkdir /usr/share/vim/vim70/pydiction</code>

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

<code># vi ~/.vimrc</code>

<code>...</code>

<code># 增加</code>

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

<code>let</code> <code>g:pydiction_menu_height = 20</code>

打開 python 腳本檔案,在編寫 python 程式時,按 tab 鍵即可激活自動補全菜單。

展示:

按 tab 前 

【原創】如何在vim中使用tab進行python代碼補全

按 tab 後

【原創】如何在vim中使用tab進行python代碼補全