"" 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"

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


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?

1 Answer 1


You need to escape the line so that

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


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 and acknowledge you have read our privacy policy.

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