Skip to content

Instantly share code, notes, and snippets.

@lqez
Created July 8, 2012 16:42
Show Gist options
  • Save lqez/3071726 to your computer and use it in GitHub Desktop.
Save lqez/3071726 to your computer and use it in GitHub Desktop.
vimrc for Django development
let g:last_relative_dir = ''
nnoremap \m :call RelatedFile ("models.py")<cr>
nnoremap \v :call RelatedFile ("views.py")<cr>
nnoremap \u :call RelatedFile ("urls.py")<cr>
nnoremap \a :call RelatedFile ("admin.py")<cr>
nnoremap \t :call RelatedFile ("templates/")<cr>
nnoremap \T :e templates/<cr>
nnoremap \S :e settings.py<cr>
nnoremap \U :e urls.py<cr>
fun! RelatedFile(file)
if filereadable(expand("%:h"). '/models.py') || isdirectory(expand("%:h") . "/templatetags/")
exec "edit %:h/" . a:file
let g:last_relative_dir = expand("%:h") . '/'
return ''
endif
if g:last_relative_dir != ''
exec "edit " . g:last_relative_dir . a:file
return ''
endif
echo "Can't determine where relative file is : " . a:file
return ''
endfun
fun SetAppDir()
if filereadable(expand("%:h"). '/models.py') || isdirectory(expand("%:h") . "/templatetags/")
let g:last_relative_dir = expand("%:h") . '/'
return ''
endif
endfun
autocmd BufEnter *.py call SetAppDir()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment