歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Python的Vim的簡單設置

Python的Vim的簡單設置

日期:2017/2/28 14:37:42   编辑:Linux教程

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掃描版+隨書視頻+代碼] http://www.linuxidc.com/Linux/2013-11/92693.htm

Python腳本獲取Linux系統信息 http://www.linuxidc.com/Linux/2013-08/88531.htm

強大的Vim 編輯器 http://www.linuxidc.com/Linux/2013-07/87544.htm

在CentOS 6.2上搭建Vim開發環境 http://www.linuxidc.com/Linux/2013-07/87363.htm

Vim 7.4a 發布,全新更快的正則表達式引擎 http://www.linuxidc.com/Linux/2013-07/87035.htm

CentOS 5.4 安裝高亮Vim編輯工具 http://www.linuxidc.com/Linux/2013-06/86508.htm

Python 的詳細介紹:請點這裡
Python 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved