AndyHancock wrote:
> I've been kluging an old version of BufExplorer plugin to trim down
> displayed paths when invoked by different gvim versions (Solaris,
> Windows, and Cygwin).  Without such trimming, BufExplorer might
> display:
> 
>   5 %    Temp.txt c:\cygwin\home\Administrator\Temp
>   1 #    diff.out c:\cygwin\home\Administrator\Temp
> 
> I've managed to cobble the code so that in Solaris and Cygwin, it is
> displayed as
> 
>   5 %    Temp.txt ~\Temp
>   1 #    diff.out ~\Temp
> 
> However, I'm having some trouble making the code work with Windows vim
> 7.2.  Currently, I am using the code:
> 
>    let _cfile = _cfile." ".substitute(
>       \ expand("#"._cnr.":p:h"),
>       \ "[Cc]:\\cygwin\\home\\".$USERNAME, "~", "g" )
> 
> Here, _cfile is the basename of the file path before the statement is
> excuted.  This code doesn't do anything.  As a debugging test,
> however, this "works":
> 
>    let _cfile =
>       \ _cfile." ".substitute( expand("#"._cnr.":p:h"),
>       \ "c:\\", "~", "g" )
> 
> It works in the sense that "c:\" in the file path is replaced by "~".
> This test "works" too:
> 
>    let _cfile =
>       \ _cfile." ".substitute( expand("#"._cnr.":p:h"),
>       \ "cygwin", "~", "g" )
> 
> It works in the sense that "cygwin" is replaced by "~".
> 
> Strangely enough, the combination of the above two tests does not
> work:

When you specify a pattern such as "c:\\", the 2 backslashes become 1 
prior to compilation of the regex. Thus, what the regex compiler sees is 
  'c:\'. Since nothing follows the backslash, it can't be an escape, so 
the regex engine matches it as a literal backslash character. Similarly, 
when you specify a pattern such as "c:\\cygwin", the 2 backslashes 
become 1 prior to compilation of the regex. Thus, what the regex 
compiler sees is 'c:\cygwin'. Note that something (the `c' in cygwin) 
now follows the backslash, so the regex engine interprets the backslash 
as an escape, and assumes you want to match `c:', followed by a literal 
`c' (indicated by `\c'), followed by `ygwin'. In other words, the regex 
engine is looking for...
c:cygwin
...which is probably not what you want. To match what I think you want, 
you should use 'c:\\cygwin' instead of "c:\\cygwin". If you wanted to 
use double quotes, it would be "c:\\\\cygwin".

Brett Stahlman

> 
>    let _cfile =
>    \ _cfile." ".substitute( expand("#"._cnr.":p:h"),
>    \ "c:\\cygwin", "~", "g"
> 
> I am partly using this exercise as a prompt to get to know vim
> scripting better.  Could someone please advise on what might be the
> problem, and where I can dig up more about its resolution?
> 
> Thanks.
> > 
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to