-1

Code

"" http://vi.stackexchange.com/a/7787/2923
function! OpenSelectionAsTabs() range
    let tabnr = tabpagenr()
    for line in range(a:firstline, a:lastline)
        execute "tabedit " . getline(line)
        execute "tabp"
    endfor
endfunction

nnoremap <leader>gf :'<,'>call OpenSelectionAsTabs()<CR>
vnoremap <leader>gf :call OpenSelectionAsTabs()<CR>

Filelist where I select two files in Visual mode and Press <leader>gf

/Users/masi/Raspberry Pi/me-hello-yes.tex
/Users/masi/hello.tex
...

Output

Error detected while processing function OpenSelectionAsTabs:
line    3:
E172: Only one file name allowed: tabedit /Users/masi/Raspberry Pi/me-hello-yes.tex

There are several complications such as artifact tabs. I think the empty spaces can be one source of the problem.


Why is there the error message E172?

3

You need to escape the line so that

tabedit /Users/masi/Raspberry Pi/me-hello-yes.tex

becomes

tabedit /Users/masi/Raspberry\ Pi/me-hello-yes.tex

Otherwise, tabedit sees two filenames /Users/masi/Raspberry and Pi/me-hello-yes.tex.

You can do this with the function fnameescape():

execute "tabedit " . fnameescape(getline(line))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.