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

来源:互联网 发布:网络电影《引魂灯》 编辑:程序博客网 时间:2024/06/15 02:00

借鉴文章:

1、http://www.cnblogs.com/samwei/archive/2011/04/25/2026211.html


1.文法高亮

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

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

2.缩进

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

set autoindent " same level indentset smartindent " next level indentset expandtabset tabstop=4set shiftwidth=4set 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 = 1let g:miniBufExplMapWindowNavArrows = 1let g:miniBufExplMapCTabSwitchBufs = 1let g:miniBufExplModSelTarget = 1

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

5.Omnicompletion

  Vim7中添加了对文法提示和自动完成的支持,对于python来说需下载pythoncomplete.vim并将其放在<Vim安装目录>/<$VIMRUNTIME>/autoload/目录下,接着在vimrc中添加如下命令:

filetype plugin onset ofu=syntaxcomplete#Completeautocmd FileType python setomnifunc=pythoncomplete#Completeautocmd FileType python runtime! autoload/pythoncomplete.vim

  最后在编写代码时通过ctrl-x ctrl-o来打开文法提示上下文菜单,如下图所示:


原创粉丝点击