您的位置:首页 > 编程语言 > Python开发

为Vim做方便Python编程的配置(集合-不断收集)

2013-05-21 16:58 253 查看
借鉴文章:

1、/article/5676239.html

1.文法高亮

  为了能在Vim中支持Python文法需要用到插件python.vim,该插件默认位于<Vim安装目录>/<$VIMRUNTIME>/syntax/下,如果你在该路径下没有找到这个插件,需要到python.vim : Enhanced version of the python syntax
highlighting script下载。然后为了能让Vim识别Python文法需要在vimrc中添加:

set filetype=python
au BufNewFile,BufRead *.py,*.pyw setf python


2.缩进

  在vimrc中添加如下缩进相关的代码:

set autoindent " same level indent
set smartindent " next level indent
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4


3.项目视图

  像Visual Studio或Eclipse之类的IDE都会提供项目视图(位于左侧或右侧),程序员利用该视图在文件间或类间跳转。利用Ctags和插件Tasklist可以在vim中实现此功能。

首先下载Exuberant Ctags
然后解压Ctags,并进入解压后的目录,利用如下命令编译安装Ctags:

./configure && sudo make install


通过这种方式,Ctags被安装在/usr/local/bin下。接下来在vimrc中添加如下命令告诉Vim Ctags的安装路径:

let Tlist_Ctags_Cmd='/usr/local/bin/ctags'


接着安装Tasklist插件:下载TaskList.vim,然后把它放入plugin目录下

最后使用命令:TlistToggle打开taglist窗口,下图展示了该窗口。



4.MiniBufExplorer

  在Visual Studio或Eclipse中你打开的缓存会以tab的形式列在窗口的顶端或底部,在Vim中插件MiniBufExplorer来实现此功能。下载minibufexpl.vim并将其放在plugin目录下。接着在vimrc中添加如下命令:

let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1


  下图展示了MiniBufExplorer的使用效果:



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来打开文法提示上下文菜单,如下图所示:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: