| 131 | == Mappings == |
| 132 | |
| 133 | I have this in my vimrc to make file jumps between relative django files easier. |
| 134 | {{{ |
| 135 | let g:last_relative_dir = '' |
| 136 | nnoremap \1 :call RelatedFile ("models.py")<cr> |
| 137 | nnoremap \2 :call RelatedFile ("views.py")<cr> |
| 138 | nnoremap \3 :call RelatedFile ("urls.py")<cr> |
| 139 | nnoremap \4 :call RelatedFile ("admin.py")<cr> |
| 140 | nnoremap \5 :call RelatedFile ("tests.py")<cr> |
| 141 | nnoremap \6 :call RelatedFile ( "templates/" )<cr> |
| 142 | nnoremap \7 :call RelatedFile ( "templatetags/" )<cr> |
| 143 | nnoremap \8 :call RelatedFile ( "management/" )<cr> |
| 144 | nnoremap \0 :e settings.py<cr> |
| 145 | nnoremap \9 :e urls.py<cr> |
| 146 | |
| 147 | fun! 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 '' |
| 160 | endfun |
| 161 | |
| 162 | fun SetAppDir() |
| 163 | if filereadable(expand("%:h"). '/models.py') || isdirectory(expand("%:h") . "/templatetags/") |
| 164 | let g:last_relative_dir = expand("%:h") . '/' |
| 165 | return '' |
| 166 | endif |
| 167 | endfun |
| 168 | autocmd BufEnter *.py call SetAppDir() |
| 169 | }}} |
| 170 | |