Let's see. I have a gvim running and I want open a file, respecting the autocmds (which rules out --remote-tab).
Now I know I can do (basically, with some tweak):
gvim --remote-send ":tabe my_file<CR>"
which works. But if a file has spaces or strange chars in it, I have to do the following:
gvim --remote-send ":tabe my\\ file<CR>"
(the double \\ is because one of them is eaten by the shell; this is equivalent to manually type
`:tabe my\ file`
in vim and it works). Now, I can find a way to create that string in the shell or whatever, but I hoped I could "globally quote" the string in the ":tabe" command, like
gvim --remote-send ":tabe 'my file'<CR>"
or
gvim --remote-send ":tabe \"my file\"<CR>"
--- this is equivalent to writing directly in the vim command line :tabe "my file"; it seems it is not working. I can explicitly quote all space in the string with the shell, doing something like
# <ESC> because the gvim instance can be in a mode different from normal
# the double CR: do not ask.
# the argument MUST be a full path
file="$(readlink -f "$@")"
fileq="$(echo "$file" | awk '{gsub(/ /,"\\\ ")}1')" # quote spaces FIXME add other chars
exec gvim 2>/dev/null --servername $desktop --remote-send "<ESC>:tabe $fileq <CR><CR>"
but it works just for spaces and not other special chars like tabs and " (nor newlines, but if you have newlines in your file names you deserve it!).
The question:
Independently on the particular shell, with which I will deal after :-), is there a way when directly typing in the vim tabe: line to globally quote a filename without going to quote the "strange" chars one by one?
gvim --remote-send ':tabe foo\ bar.txt<CR>'worked for me on bash and zsh. And the quotes seem to matter too. If I use"internally, it didn't work, but'did:gvim --remote-send ":tabe 'foo bar.txt'<CR>"– muru Feb 21 '15 at 11:12gvim --remote-send ":tabe 'f s.txt'<CR>"didn't work for me, nor writing:tabe 'f s.txt'in vim, I gotE77: Too many files names. – Rmano Feb 21 '15 at 12:00'foo bar.txt', with the quotes. But a single backslash still works, as doesfoo="f\ s.txt" gvim --remote-send ":tabe $foo<CR>". – muru Feb 21 '15 at 12:07fileq="$(echo "$file" | awk '{gsub(/ /,"\\\ ")}1')"andgvim --servername $desktop --remote-send "<ESC>:tabe $fileq <CR><CR>"which works, but just for spaces... – Rmano Feb 21 '15 at 12:20gvim --servername $desktop --remote-send "<ESC>:tabe ${file// /\\ }<CR>"be simpler? – muru Feb 21 '15 at 12:25<Space>? Since<Esc>and<Cr>is captured by Vim and interpreted correctly maybe<Space>would too – Sukima Feb 21 '15 at 13:27", or other special chars?) – Rmano Feb 21 '15 at 13:34shellescapefunction be helpful? – EvergreenTree Feb 21 '15 at 19:13:edit(and its variants) doesn't accept a quoted filename. All special characters need to be individually escaped. So,:edit "foo bar.txt"won't work; you need:edit foo\ bar.txt. That said, something like:execute 'tabedit' escape('$file', ' ')might be on the right track. – tommcdo Feb 22 '15 at 03:13