在 Vim 中编写 Python 程序
-- xyb [DateTime(2004-09-21T00:21:07Z)] TableOfContents
在 Vim 中编写 Python 程序
本文档介绍如何在 Vim 中更方便的编写 Python 程序。
.vimrc
.vimrc 是 Vim 的用户配置文件,我们的大多数定制都得在这个文件中设置。在 Windows 中,它的文件名为 _vimrc。
if has("autocmd")
" 自动检测文件类型并加载相应的设置
filetype plugin indent on
" Python 文件的一般设置,比如不要 tab 等
autocmd FileType python setlocal et | setlocal sta | setlocal sw=4
" Python Unittest 的一些设置
" 可以让我们在编写 Python 代码及 unittest 测试时不需要离开 vim
" 键入 :make 或者点击 gvim 工具条上的 make 按钮就自动执行测试用例
autocmd FileType python compiler pyunit | setlocal makeprg=python\ %
autocmd FileType python setlocal makeprg=python\ ./alltests.py
autocmd BufNewFile,BufRead test*.py setlocal makeprg=python\ %
" 自动使用新文件模板
autocmd BufNewFile test*.py 0r ~/.vim/skeleton/test.py
autocmd BufNewFile alltests.py 0r ~/.vim/skeleton/alltests.py
autocmd BufNewFile *.py 0r ~/.vim/skeleton/skeleton.py
endif