On 2014-03-04, Gary Johnson wrote:
> On 2014-03-04, Christian Brabandt wrote:
> > Am 2014-03-04 08:15, schrieb Gary Johnson:
> > >There is a difference between the expansion of % and Ctrl-R % on the
> > >command line.
> > >
> > >I use Dropbox to keep a number of my configuration files, including
> > >my ~/.vim directory, synchronized between various machines running
> > >Linux and Windows.
> > >
> > >Today I discovered this file in the ~/Dropbox/vimfiles of a machine
> > >named toucan which is running Fedora 14:
> > >
> > >    filetype (toucan's conflicted copy 2014-03-01).vim
> > >
> > >Using a GUI file manager, I opened this file with gvim.  I made some
> > >changes to it, then tried comparing the changed buffer with the
> > >copy on disk with this command which I have used for years:
> > >
> > >    :w !diff "%" -
> > >
> > >The result surprised me.
> > >
> > >    diff: Dropbox/vimfiles/filetype \(toucan's conflicted copy
> > >2014-03-01\).vim: No such file or directory
> > 
> > That indeed looks wrong. Interestingly, it seems to work for me, when
> > escaping the quote, like this:
> > 
> > :w !cmd \"%\" -
> > 
> > (note sure, why this works).
> > 
> > For the most recent versions, I think :w !cmd %:S - should also work.
> 
> I observed the problem on Linux, not Windows, so cmd is not
> involved.  Vim's expansion of % may differ between Linux and
> Windows.

Attached is a patch that fixes this on Linux.

I think the original code was a well-intentioned but incorrect
attempt to quote characters in the expansion of % that are special
to the shell.  The problem is that the quoting is inconsistent.  If
one is going to quote a file name so that % expands usefully in a
shell command such as

    :!cat %

then all characters special to the shell must be quoted.  The
current Vim code quotes the characters "!&;()<>" but not space.
Consequently, any spaces in the file name are seen by the shell as
separators.

If one attempts to fix the space problem by quoting the file name as

    :!cat "%"

and the file name contains any of the characters "!&;()<>", then the
backslashes used by Vim to quote those characters appear to the
shell as literal backslashes.

Since users are used to placing file names that may contain special
characters withing quotes, I think it would be least confusing for
Vim not to try to help with additional quoting.  Therefore this
patch removes this extra quoting.  This also preserves the current
behavior in the most common case of file names containing spaces.
It is much less common for file names to include any of "!&;()<>",
and with this bug, there is no way for the user to use % in a shell
command if % expands to a name containing any of those characters
and a space.

The patch is based on Vim 7.4.135.

Regards,
Gary

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -4571,25 +4571,15 @@
 
 	/* For a shell command a '!' must be escaped. */
 	if ((eap->usefilter || eap->cmdidx == CMD_bang)
-			    && vim_strpbrk(repl, (char_u *)"!&;()<>") != NULL)
+			    && vim_strpbrk(repl, (char_u *)"!") != NULL)
 	{
 	    char_u	*l;
 
-	    l = vim_strsave_escaped(repl, (char_u *)"!&;()<>");
+	    l = vim_strsave_escaped(repl, (char_u *)"!");
 	    if (l != NULL)
 	    {
 		vim_free(repl);
 		repl = l;
-		/* For a sh-like shell escape "!" another time. */
-		if (strstr((char *)p_sh, "sh") != NULL)
-		{
-		    l = vim_strsave_escaped(repl, (char_u *)"!");
-		    if (l != NULL)
-		    {
-			vim_free(repl);
-			repl = l;
-		    }
-		}
 	    }
 	}
 

Raspunde prin e-mail lui