wassimans
wassimans

Reputation: 8672

Describe your customized Vim editor for Python/Django development?

I've recently switched entirely to Vim for all my Python/Django development. It took me a lot of time to customize it to the point it is today, and God knows how hard it was for me to find help regarding the best vim plugins out there suited for Python/Django development.

I decided to ask this question so people like me could benefit directly from your experience: You've built the perfect Python/Djangoish Vim editor? Describe it for us (plugins, scripts, customized .vimrc, colorschemes ..etc).

Thanks

My Configuration

Ok, this is my own configuration. actually I've chosen to create a simple Vim configuration so I can master the little number of plugins I've chosen to install instead of make a big stack of plugins that I'll never master nor use. This is the list of the plugins I use the most:

Also I've created a python.vim file in $HOME/.vim/ftplugin/ containing this script so I can run python code from Vim just by running Shift+e:

" Execute file being edited with <Shift> + e:
map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR>

Also I've collected some useful .vimrc customizations:

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

Upvotes: 27

Views: 8124

Answers (2)

Torsten Engelbrecht
Torsten Engelbrecht

Reputation: 13486

I am not going to post my whole .vimrc file here, but I have a similiar setup as you. This is less Python/Django specific though, except for some custom snippets for snipMate and python-mode. Here the vim plugins I am using:

  • Pathogen: better organized vim plugin structure in .vim dir
  • comments.vim: faster language specific commenting with ctrl-c and ctrl-x
  • NERDTree
  • NERDTree tabs
  • syntastic: Syntax checking plugin (for me mainly used for non-python code)
  • surround.vim and autoclose.vim: Easier handling of brackets, opening and closing tags etc.
  • matchit: extends the % command to also match and circle through for example html tags. For circling through Python code statements (eg. if-elif-else) you can download python_match.vim and put it into your ftplugin/python/ dir. I put it into ~/.vim/bundle/matchit/ftplugin/python/
  • python-mode: Great plugin for Python editing. Has automated pyflakes/pep8 checking (or pylint if you want) on file save. I deactivated the auto complete via let g:pymode_rope = 0 in my .vimrc file though, since it lagged for me on each file save. Also the syntax highlighting is extended for python code.
  • snipMate (custom snippets for python follow below)
  • tagBar: I can't live without an outline for huge code files.

Some custom python snippets I use quite frequently:

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()

Upvotes: 4

Wolph
Wolph

Reputation: 80031

I don't really have much Django specific mods, although I have given the jinja2 syntax a higher priority than the django template syntax.

For Python specifically:

  • For Python syntax checking I use PyFlakes with highlight SpellBad ctermbg=darkred
  • Sometimes (rarely) I feeld the need for autocompletion and in that case I use Eclim
  • For the rest, the default stuff. Tab size 4, soft tabs, etc...

Vim Settings:

  • 256 Color scheme 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
    
  • Lots of tabs (tabe, tabn)
  • Lots of splits (both vertical and horizontal)

Upvotes: 5

Related Questions