2016-03-15 15 views
0

開放我想開一個bld.log文件作爲默認別人在vim VSPLIT窗口或NEWTAB無論輸入文件名從嵌套子文件夾,我打開它。
所以我在〜/ .vimrc中添加下列功能,但不是開放路徑1檢索與名稱路徑1打開的newfile路徑。
請讓我知道我在這裏錯過了什麼,或者我該如何實現它?搜索的父目錄向上文件,並在VSPLIT或NEWTAB

function! Err1(...) 
if a:0 > 0 
    let s:path1 = findfile(a:1,';') 
else 
    let s:path1 = findfile('bld.log',';') 
end 
exec ':vsp ' . s:path1 
endfunction 
command -nargs=1 Err call Err1(...) 

P.S.我想在.bashrc中在上面的.vimrc只做不

回答

0

你可以做到這一點使用exec(這個回答編輯之前的原始問題,如何使用:tabnew從功能):

function! Err1() 
    let s:path1 = findfile('README.md','.,**') 
    echo findfile('README.md',';') 
    exec ':tabnew ' . s:path1 
endfunction 
command Err call Err1() 

這裏它接受一個可選的參數的函數的一個例子:

function! Err1(...) 
    if len(a:1) > 0 
     let l:path = a:1 
    else 
     let l:path = 'README.md' 
    end 
    let l:file = findfile(l:path,'.,**') 
    if len(l:file) > 0 
     exec ':vsp ' . l:file 
    else 
     echom 'File not found: ' . l:path . ' ' . l:file 
    end 
endfunction 
command -nargs=* Err call Err1('<args>') 

另一種選擇是添加set path=.,**到的.vimrc,然後只用標準的「文件」命令,像:find bld.log

+0

非常感謝鮑里斯。還有一個疑問可以告訴我,我們可以重寫相同的函數來接收README.md作爲參數,例如運行時參數。 – ypp

+0

@ypp':H輸入()' – sidyll

+0

@sidyll:我試過,但沒有工作'的功能! Err1(file1) let s:path1 = findfile('a:file1',';') 「findfile('xr_bld.ncs4k.log',';') exec':vsp'。s:path1 endfunction 命令錯誤調用ERR1()' – ypp