Changes between Version 44 and Version 45 of UsingVimWithDjango


Ignore:
Timestamp:
Oct 1, 2009, 10:21:19 PM (15 years ago)
Author:
mjbrownie
Comment:

added related file mapping

Legend:

Unmodified
Added
Removed
Modified
  • UsingVimWithDjango

    v44 v45  
    129129Although this is not Django-specific (I don't think some of the other stuff in here is very Django-specific either), [http://pida.co.uk PIDA] looks like a pretty nice IDE environment for VIM+Python, which would therefore help you out in Django :).
    130130
     131== Mappings ==
     132
     133I have this in my vimrc to make file jumps between relative django files easier.
     134{{{
     135let g:last_relative_dir = ''
     136nnoremap \1 :call RelatedFile ("models.py")<cr>
     137nnoremap \2 :call RelatedFile ("views.py")<cr>
     138nnoremap \3 :call RelatedFile ("urls.py")<cr>
     139nnoremap \4 :call RelatedFile ("admin.py")<cr>
     140nnoremap \5 :call RelatedFile ("tests.py")<cr>
     141nnoremap \6 :call RelatedFile ( "templates/" )<cr>
     142nnoremap \7 :call RelatedFile ( "templatetags/" )<cr>
     143nnoremap \8 :call RelatedFile ( "management/" )<cr>
     144nnoremap \0 :e settings.py<cr>
     145nnoremap \9 :e urls.py<cr>
     146
     147fun! RelatedFile(file)
     148    #This is to check that the directory looks djangoish
     149    if filereadable(expand("%:h"). '/models.py') || isdirectory(expand("%:h") . "/templatetags/")
     150        exec "edit %:h/" . a:file
     151        let g:last_relative_dir = expand("%:h") . '/'
     152        return ''
     153    endif
     154    if g:last_relative_dir != ''
     155        exec "edit " . g:last_relative_dir . a:file
     156        return ''
     157    endif
     158    echo "Cant determine where relative file is : " . a:file
     159    return ''
     160endfun
     161
     162fun SetAppDir()
     163    if filereadable(expand("%:h"). '/models.py') || isdirectory(expand("%:h") . "/templatetags/")
     164        let g:last_relative_dir = expand("%:h") . '/'
     165        return ''
     166    endif
     167endfun
     168autocmd BufEnter *.py call SetAppDir()
     169}}}
     170
    131171
    132172== Suggestions ==
Back to Top