Ubuntu下將vim配置為Python IDE(轉)
配置好了Django的環境,該把vim好好配置一下當做python的IDE來用。
在Windows下用慣了各種現成的工具,轉到Linux下,一下沒了頭緒……好歹google出一些別人的心得,折騰來折騰去,也算是把開發環境配好了。
1. 安裝完整的vim
# apt-get install vim-gnome
2. 安裝ctags,ctags用於支援taglist,必需!
# apt-get install ctags
3. 安裝taglist
#apt-get install vim-scripts
#apt-get install vim-addon-manager // 貌似我在安裝vim-scripts的時候,已經附帶安裝了vim-addon-manager
# vim-addons install taglist
4. 安裝pydiction(實現程式碼補全)
#wget http://www.pythonclub.org/_media/python-basic/pydiction-1.2.zip
#unzip pydiction-1.2.zip
// ~/.vim/after/ftplugin和~/.vim/tools/pydiction/目錄預設不存在,需要自行建立
#cp pydiction-1.2/python_pydiction.vim ~/.vim/after/ftplugin
#cp pydiction-1.2/complete-dict ~/.vim/tools/pydiction/complete-dict
5. 編輯配置檔案
# vim ~/.vimrc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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> // 設定F8為taglist開關
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/tools/pydiction/complete-dict'
set autoindent // 實現自動縮排
set tabstop=4
set shiftwidth=4
set expandtab
set number
|
至此,python IDE的環境就算是搭好了,來張完成圖:
右邊即為taglist視窗,按F8開啟,使用Ctrl+w,再按w可以在code視窗和taglist視窗間切換。
附加:highlight
http://www.vim.org/scripts/script.php?script_id=1599Line mode Highlight current line Advance color for next line highlight Clear last line highlight Pattern mode Highlight word under cursor (whole word match) Highlight all lines having word under cursor (whole word match) Highlight word under cursor (partial word match) Highlight all lines having word under cursor (partial word match) Highlight last search pattern Highlight all lines having last search pattern Clear last pattern highlight Clear all highlights All above commands work in both normal & insert modes. also works in visual mode. (Select desired lines & hit ) python_fold自動摺疊 http://vim.sourceforge.net/scripts/script.php?script_id=515 zo 展開 zc 收起 zn 全部展開 zN 全部摺疊
安裝NERD_TREE 目錄樹(檔案瀏覽,強烈推薦)
1.下載外掛檔案
http://www.vim.org/scripts/script.php?script_id=1658
解壓檔案到~/.vim/目錄下,如果沒有此目錄,則要自己建立。
2.新增配置檔案
在~/.vimrc 或 /etc/vim/vimrc檔案裡新增如下配置
1 2 3 4 5 |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" F7 NERDTree
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <F7> :NERDTreeToggle<CR>
imap <F7> <ESC>:NERDTreeToggle<CR>
|
則在VIM裡按下F7就可開啟關閉目錄樹。具體操作命令請檢視外掛doc目錄下的幫助檔案。
Auto Complete
http://www.vim.org/scripts/script.php?script_id=1879
過程同上。
最後,來張既有NERDTree,又有taglist的圖。