2017-02-23 74 views
0

我按照說明上的Django網站添加以下到我的vimrc文件,但是當我嘗試保存文件,我得到一個錯誤:函數SetAppDir已經存在,添加!來代替它 - Django的VIM

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

通知了'樂趣!'?對'SetAppDir'做同樣的操作。至於你爲什麼得到這個錯誤,我不確定。該功能只應定義一次,除非您重複採購此文件。 –

+0

Heehaaa,工作。 Django需要糾正他們的網站。非常感謝。 – Stryker

+1

這個wiki沒有被任何人主動維護,並且有很多過時的信息。您可以自己編輯頁面,但個人而言,我大多忽略它的存在並從更可靠的來源獲取我的信息(如[官方文檔](https://docs.djangoproject.com/en/1.10/)或SO)。 – knbk

回答

0

感謝@蘭迪·莫里斯爲他的提示。

不得不修改代碼並添加!剛過樂趣和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的RelatedFile`定義之前調用SetAppDir()

相關問題