2016-02-25 70 views
2

是做什麼(在我.vimrc)之間的區別:vim的 '源' 與 'EXE /執行' 命令

set runtimepath+=$HOME/.vim/conf 
source ~/.vim/conf/hotkeys.vim 

set runtimepath+=$HOME/.vim/conf 
exe 'source' '~/.vim/conf/hotkeys.vim' 

做我的腳本的內容(這種情況下hotkeys.vim)有什麼關係我應該使用?

此外,exe,execexecute命令之間是否有任何區別?

回答

3

在您的示例中,使用sourceexecute之間沒有區別。

source方法只是加載一個靜態文件路徑。

execute版本評估它給出的字符串,但最終它只是運行與第一個示例完全相同的source命令。

如果您提前不知道文件名,並且必須計算它,或者從其他來源獲取它,則會出現差異。然後,你可以建立一個源命令是這樣的:

" A file name we obtained from user input or some other source 
let g:file_we_want = 'foo' 

" Calculate a file path as a string 
let g:path_to_source = '~/' . g:file_we_want . '.vim' 

" This is equivalent to: 
"  source ~/foo.vim 
execute 'source' g:path_to_source 

exeexecexecute之間沒有什麼區別。他們都是一樣的命令。 exeexec是縮寫。

+0

哦,好吧,我明白了。非常感謝! – TheCrafter