1.文法高亮php
为了能在Vim中支持Python文法须要用到插件python.vim,该插件默认位于(/usr/share/vim/vim72/)<Vim安装目录>/<$VIMRUNTIME>/syntax/下,若是你在该路径下没有找到这个插件,须要到python.vim : Enhanced version of the python syntax highlighting script下载。而后为了能让Vim识别Python文法须要在vimrc中添加:python
set filetype=python
au BufNewFile,BufRead *.py,*.pyw setf python
2.缩进linux
在vimrc(/etc/)中添加以下缩进相关的代码:程序员
set autoindent " same level indent
set smartindent " next level indent
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
3.项目视图vim
像Visual Studio或Eclipse之类的IDE都会提供项目视图(位于左侧或右侧),程序员利用该视图在文件间或类间跳转。利用Ctags和插件Tasklist能够在vim中实现此功能。windows
./configure && sudo make install
""""""""""""""""""""""""""""""
" Tag list (ctags)
""""""""""""""""""""""""""""""
if MySys() == "windows" "设定windows系统中ctags程序的位置
let Tlist_Ctags_Cmd = 'ctags'
elseif MySys() == "linux" "设定windows系统中ctags程序的位置
let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
endif
let Tlist_Show_One_File = 1 "不一样时显示多个文件的tag,只显示当前文件的
let Tlist_Exit_OnlyWindow = 1 "若是taglist窗口是最后一个窗口,则退出vim
let Tlist_Use_Right_Window = 1 "在右侧窗口中显示taglist窗口
在taglist窗口中,能够使用下面的快捷键:缓存
<CR> 跳到光标下tag所定义的位置,用鼠标双击此tag功能也同样 o 在一个新打开的窗口中显示光标下tag <Space> 显示光标下tag的原型定义 u 更新taglist窗口中的tag s 更改排序方式,在按名字排序和按出现顺序排序间切换 x taglist窗口放大和缩小,方便查看较长的tag + 打开一个折叠,同zo - 将tag折叠起来,同zc * 打开全部的折叠,同zR = 将全部tag折叠起来,同zM [[ 跳到前一个文件 ]] 跳到后一个文件 q 关闭taglist窗口 <F1> 显示帮助
能够用”:TlistOpen“打开taglist窗口,用”:TlistClose“关闭taglist窗口。或者使用”:TlistToggle“在打开和关闭间切换。ide
在Visual Studio或Eclipse中你打开的缓存会以tab的形式列在窗口的顶端或底部,在Vim中插件MiniBufExplorer来实现此功能。下载minibufexpl.vim并将其放在plugin目录下。接着在vimrc中添加以下命令:oop
let g:miniBufExplMapWindowNavVim =1
let g:miniBufExplMapWindowNavArrows =1
let g:miniBufExplMapCTabSwitchBufs =1
let g:miniBufExplModSelTarget =1
下图展现了MiniBufExplorer的使用效果:spa
5.Omnicompletion
Vim7中添加了对文法提示和自动完成的支持,对于python来讲需下载pythoncomplete.vim并将其放在<Vim安装目录>/<$VIMRUNTIME>/autoload/目录下,接着在vimrc中添加以下命令:
filetype plugin on
set ofu=syntaxcomplete#Complete
autocmd FileType python set
omnifunc=pythoncomplete#Complete
autocmd FileType python runtime! autoload/pythoncomplete.vim
最后在编写代码时经过ctrl-x ctrl-o来打开文法提示上下文菜单,以下图所示:
参考文献
1.http://www.swaroopch.com/notes/Vim
2.http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/
3.http://www.phacks.net/macvim-code-completion-syntax-highlighting-for-python-pyqt4-twisted-on-mac-osx-snow-leopard/
4.http://vim.wikia.com/wiki/Omni_completion