我最近完全转向Vim进行所有Python / Django开发。我花了很多时间来定制它到今天的程度,上帝知道我有多难找到适合Python / Django开发的最佳vim插件的帮助。
我决定问这个问题,所以像我这样的人可以直接从你的经历中受益: 你已经构建了完美的Python / Djangoish Vim编辑器?为我们描述它(插件,脚本,自定义.vimrc,colorschemes ..etc)。
由于
好的,这是我自己的配置。实际上我已经选择创建一个简单的Vim配置,这样我就可以掌握我选择安装的少量插件,而不是制作一大堆我永远不会掌握也不会使用的插件。这是我最常使用的插件列表:
此外,我在$ HOME / .vim / ftplugin /中创建了一个包含此脚本的python.vim文件,因此只需运行Shift + e即可从Vim运行python代码:
" Execute file being edited with <Shift> + e:
map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR>
此外,我收集了一些有用的.vimrc自定义:
set nocompatible " use vim defaults
set number " show line numbers
colorscheme desert
set tags=tags;$HOME/.vim/tags/ "recursively searches directory for 'tags' file
set expandtab " tabs are converted to spac
set tabstop=4 " numbers of spaces of tab character
set shiftwidth=4 " numbers of spaces to (auto)indent
set showcmd " display incomplete commands
set hlsearch " highlight searches
set incsearch " do incremental searching
set ruler " show the cursor position all the time
set numberwidth=4 " line numbering takes up 5 spaces
set ignorecase " ignore case when searching
set nowrap " stop lines from wrapping
filetype plugin indent on " turn on the indent plugins
syntax on " syntax highlighing
" TagList Plugin Configuration
let Tlist_Ctags_Cmd='/usr/bin/ctags' " point taglist to ctags
let Tlist_GainFocus_On_ToggleOpen = 1 " Focus on the taglist when its toggled
let Tlist_Close_On_Select = 1 " Close when something's selected
let Tlist_Use_Right_Window = 1 " Project uses the left window
let Tlist_File_Fold_Auto_Close = 1 " Close folds for inactive files
" Omnicompletion functions
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
au FileType py set expandtab
au FileType py set foldmethod=indent
map <F2> :previous<CR> " map F2 to open previous buffer
map <F3> :next<CR> " map F3 to open next buffer
map <F4> :NERDTreeToggle<CR> " map F4 to open NERDTree
map <F5> :TlistToggle<CR> " map F5 to toggle the Tag Listing
map <silent><C-Left> <C-T> " taglist - map Ctrl-LeftArrow to jump to the method/property under your cursor
map <silent><C-Right> <C-]> " taglist - map Ctrl-RhitArrow to jump back to your source code
map <silent><A-Right> :tabnext<CR> " map Alt-RightArrow to jump to the next tab
map <silent><A-Left> :tabprevious<CR> " map Alt-LeftArrow to jump to the previous tab
答案 0 :(得分:5)
我没有太多Django特定的mod,虽然我给jinja2语法的优先级高于django模板语法。
highlight SpellBad ctermbg=darkred
256色彩方案desert256
if ((&term == 'screen') || (&term == 'screen-bce') || (&term == 'xterm'))
set t_Co=256
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
colo desert256
endif
tabe
,tabn
)答案 1 :(得分:4)
我不会在这里发布我的整个.vimrc文件,但我有一个类似的设置。除了针对snipMate和python-mode的一些自定义片段之外,这不是特定于Python / Django的。这里是我正在使用的vim插件:
%
命令以匹配并圈选例如html标记。要绕过Python代码语句(例如if-elif-else),您可以下载python_match.vim并将其放入ftplugin/python/
目录中。我把它放进了~/.vim/bundle/matchit/ftplugin/python/
let g:pymode_rope = 0
文件中的.vimrc
停用了自动完成功能,因为它在每个文件保存时都滞后于我。语法高亮也扩展为python代码。我经常使用的一些自定义python片段:
snippet #utf
# -*- coding: utf-8 -*-
snippet ds
"""
${1: }
"""
# just the first (or last) three quites for the docstring
snippet dss
"""${1: }
# For file headers
snippet dsfile
"""
:File: ${1:`Filename('$1.py', 'foo.py')`}
:Author: ${2:`g:snips_author`}
:Description: ${3}
"""
snippet pdb
import pdb
pdb.set_trace()