函数SetAppDir已经存在,添加!替换它 - django vim

时间:2017-02-23 14:29:50

标签: django vim

我按照django网站上的说明将以下内容添加到我的vimrc文件中但是当我尝试保存文件时出现错误:

Function SetAppDir already exists, add ! to replace it

试图添加!到SetAppDir()!或致电! SetAppDir但仍然没有运气。

Here is the code from django site:

let g:last_relative_dir = ''
nnoremap \1 :call RelatedFile ("models.py")<cr>
nnoremap \2 :call RelatedFile ("views.py")<cr>
nnoremap \3 :call RelatedFile ("urls.py")<cr>
nnoremap \4 :call RelatedFile ("admin.py")<cr>
nnoremap \5 :call RelatedFile ("tests.py")<cr>
nnoremap \6 :call RelatedFile ( "templates/" )<cr>
nnoremap \7 :call RelatedFile ( "templatetags/" )<cr>
nnoremap \8 :call RelatedFile ( "management/" )<cr>
nnoremap \0 :e settings.py<cr>
nnoremap \9 :e urls.py<cr>

fun! RelatedFile(file)
    #This is to check that the directory looks djangoish
    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 "Cant 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()

1 个答案:

答案 0 :(得分:0)

感谢@ randy-morris的小费。

必须修改代码并添加!在有趣之后和SetAppDir()

之前
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调用SetAppDir()