Python的Vim的簡單設定

來源:互聯網
上載者:User

1、安裝pydiction

pydiction可以讓vim自動補全Python代碼,無論是關鍵字,標準庫還是第三方庫。它主要包含3個檔案:

  python_pydiction.vim: vim外掛程式檔案。 
  complete-dict: 一個字典檔案,包含了Python的關鍵字和模組。外掛程式引用的內容即來自於此。 
  pydiction.py: 一個py指令碼,運行此檔案可以增加新的模組到complete-dict字典中。

Linux/Unix系統:將python_pydiction.vim檔案複製到 ~/.vim/after/ftplugin 目錄下。如果該目錄不存在,則建立它,vim會自動在此目錄下搜尋。

$ cp after/ftplugin/python_pydiction.vim ~/.vim/after/ftplugin
$ cp complete-dict ~/.vim
$ cp pydiction.py ~/.vim
2、編輯~/.vimrc檔案,如果不存在則建立。添加以下內容:

let Tlist_Auto_Highlight_Tag=1
let Tlist_Auto_Open=1
let Tlist_Auto_Update=1
let Tlist_Display_Tag_Scope=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Enable_Dold_Column=1
let Tlist_File_Fold_Auto_Close=1
let Tlist_Show_One_File=1
let Tlist_Use_Right_Window=1
let Tlist_Use_SingleClick=1
nnoremap <silent> <F8> :TlistToggle<CR>
                                                   
filetype plugin on
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascrīpt set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
                                                   
                                                   
let g:pydiction_location='~/.vim/complete-dict'
set autoindent
set tabstop=4
set shiftwidth=4
set expandtab
set number

3、在~/.vimrc中加入下面兩行設定,實現離開補全彈窗或者離開插入模式時自動關閉scratch preview。

autocmd InsertLeave * if pumvisible() == 0|pclose|endif
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif

備忘: ctrl x,ctrl o開啟代碼補齊,ctrl e關閉補齊,ctrl y 選擇當前的補齊代碼,並關閉。

推薦閱讀:

《Python開發技術詳解》.( 周偉,宗傑).[高清PDF掃描版+隨書視頻+代碼]

Python指令碼擷取Linux系統資訊

強大的Vim 編輯器

在CentOS 6.2上搭建Vim開發環境

Vim 7.4a 發布,全新更快的Regex引擎

CentOS 5.4 安裝高亮Vim編輯工具

Python 的詳細介紹:請點這裡
Python 的:請點這裡

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.