|
Size: 1407
Comment:
|
Size: 2268
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 9: | Line 9: |
| ''本文档介绍如何在 Vim 中更方便的编写 Python 程序。'' | ''本文档介绍如何在 Vim 中更方便的编写 Python 程序。 作者:Xie Yanbo,版权:创作共用/cc 1.0'' |
| Line 39: | Line 41: |
你可以下载我使用的[attachment:xyb.vimrc 完整的 .vimrc 文件],还有前面配置中用到的模板文件:[attachment:skeleton.py skeleton.py]、[attachment:test.py test.py] 和 [attachment:alltests.py alltests.py]。 另外,我还使用了 [http://vim.sourceforge.net/scripts/script.php?script_id=850 pydiction],这是一个相当不错的 Python 代码自动完成的脚本。为了使用这个功能,我把它放在了 ~/.vim/tools 目录中,并在 .vimrc 中增加如下设置: {{{ " python auto-complete code " Typing the following (in insert mode): " os.lis<Ctrl-n> " will expand to: " os.listdir( " Python 自动补全功能,只需要反覆按 Ctrl-N 就行了 if has("autocmd") autocmd FileType python set complete+=k~/.vim/tools/pydiction endif }}} |
在 Vim 中编写 Python 程序
-- xyb [DateTime(2004-09-21T00:21:07Z)] TableOfContents
在 Vim 中编写 Python 程序
本文档介绍如何在 Vim 中更方便的编写 Python 程序。 作者:Xie Yanbo,版权:创作共用/cc 1.0
vimrc
.vimrc 是 Vim 的用户配置文件,我们的大多数定制都得在这个文件中设置。在 Windows 中,它的文件名为 _vimrc。
下面是我的 .vimrc 中与 Python 相关的设置,你可以直接把它们拷贝到你的 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你可以下载我使用的[attachment:xyb.vimrc 完整的 .vimrc 文件],还有前面配置中用到的模板文件:[attachment:skeleton.py skeleton.py]、[attachment:test.py test.py] 和 [attachment:alltests.py alltests.py]。
另外,我还使用了 [http://vim.sourceforge.net/scripts/script.php?script_id=850 pydiction],这是一个相当不错的 Python 代码自动完成的脚本。为了使用这个功能,我把它放在了 ~/.vim/tools 目录中,并在 .vimrc 中增加如下设置:
" python auto-complete code
" Typing the following (in insert mode):
" os.lis<Ctrl-n>
" will expand to:
" os.listdir(
" Python 自动补全功能,只需要反覆按 Ctrl-N 就行了
if has("autocmd")
autocmd FileType python set complete+=k~/.vim/tools/pydiction
endif