Author Topic: Bug with vim line-end matching in substitution  (Read 5492 times)

Ian P

  • Community Member
  • Posts: 59
  • Hero Points: 2
Bug with vim line-end matching in substitution
« on: July 30, 2012, 09:02:48 PM »
Hi,
I recently purchased SlickEdit 2012, upgrading from 2009, and just discovered this new bug in vim-mode line-end matching in substitution:

It should accept an ex command like ":s/$/whatever/" to append "whatever" to the end of the line, or ":s/something$/whatever/" to replace the word "something" at the end of the line. These both work fine in SE 2009 (14.0.2.2) but do not work in 2012 (17.0.0.8) - it reports "String not found".

Using line-end matching in searching, however, does work OK in 2012; e.g. "/something$/" will find the word that the above replace command fails to find.

Ian

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Bug with vim line-end matching in substitution
« Reply #1 on: July 30, 2012, 09:52:18 PM »
Thanks for the report...I'll see if we can get this hotfixed soon and fixed in the next minor release.

davew

  • Senior Community Member
  • Posts: 224
  • Hero Points: 6
Re: Bug with vim line-end matching in substitution
« Reply #2 on: August 01, 2012, 01:41:36 PM »
I was just about to report a similar issue when I found this in the search.
I'm using vim as well to search/replace line endings. Here's what I'm seeing ...

I want to replace two CR/LF's with one to eliminate blank lines, so I'm using this:
%s/\n\n/\n/
Doesn't work. So I tried this:
%s/\x0d\x0a\x0d\x0a/\x0d\x0a/
Doesn't work either (and the line endings are CR/LF's).

If I use the Replace dialog, I can use either \n or \x0d\x0a and the replace will work, so I have a workaround, but it would be nice to use vim as it was designed.

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Bug with vim line-end matching in substitution
« Reply #3 on: August 01, 2012, 01:47:36 PM »
There is an issue with how the Vim ex command line substitute command is handling line endings.  I'll let you know if this particular use case falls into the same category as the OPs problem when this is fixed...I'll be sure to look into it.  Thanks for the example.

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Bug with vim line-end matching in substitution
« Reply #4 on: August 05, 2012, 07:42:51 PM »
@Ian P: I've attached a new version of ex.e for v17.0.1 that has an altered implementation of the Vim ex command line substitution commands.  It should handle line endings and different regular expression types much better, and more consistently.  I'd like for you to load it into your SE v17.0.1 and try it out, if you could.  Hammer command line Vim substitutions and/or replaces as much as you can :).  Let me know if it fixes your particular issue(s) and if you have any other problems with it.

@davew: This is a different problem...this never worked in SE, I tested in v16.0.3 hotfixed just to be sure.  The issue is that the way the Vim ex command line substitution is implemented, which goes line by line.  Thus, if you are to specify a regex which spans multiple lines, this isn't going to work.  I've filed a bug report for this and we need to be able to detect multiline regex searches/substitutions so that we can support these.  But in short, this particular case you've posted is a different issue and isn't addressed by the attached version of ex.e.  Hopefully we can get this support in for v17.0.2.

Ian P

  • Community Member
  • Posts: 59
  • Hero Points: 2
Re: Bug with vim line-end matching in substitution
« Reply #5 on: August 07, 2012, 07:55:42 PM »
No, unfortunately that doesn't work. It does behave slightly differently in that the cursor moves to the end of the line (actually moves out past the end of it) but the substitute command still does not work. The command that I tried to use was "s/;$//" on a line ending with ";". Searching for it using "/;$" does find that character.

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Bug with vim line-end matching in substitution
« Reply #6 on: August 07, 2012, 08:01:22 PM »
Hmm...that works for me in a plain text file with DOS style line endings.

What do you have set at Tools > Options > Editing > Search for both Regular expression (on or off?) and Regular expression syntax?

What kind of file are you searching in, and what kind of line endings does the file have?

Ian P

  • Community Member
  • Posts: 59
  • Hero Points: 2
Re: Bug with vim line-end matching in substitution
« Reply #7 on: August 07, 2012, 08:16:15 PM »
Ah - your fixed version works with a local file with Windows line endings, but I'm editing files over a Samba share to a Linux machine, and those have Unix line endings, and in those files it does not work. The original 2012 version does not work in either case so your fix is halfway there  ;)

Regular expressions are enabled with Unix format..

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Bug with vim line-end matching in substitution
« Reply #8 on: August 07, 2012, 08:47:58 PM »
It should work with Unix line endings, too, and with any of the Regular expression syntaxes, now that I've double-checked.

I think the problem is that it's not working editing over a Samba share to a Linux box...I'll have to see if we can reproduce this.

Ian P

  • Community Member
  • Posts: 59
  • Hero Points: 2
Re: Bug with vim line-end matching in substitution
« Reply #9 on: August 07, 2012, 09:02:22 PM »
I tried a local file with Unix line endings and that worked OK, then I copied that file onto the Linux share and it worked OK there too. So then I copied its content into one of the files showing the problem and found that it worked on the added lines but not on other lines, so then started whittling the content down to minimal differences to see what affects it.

It turns out that the command does not work on a line that starts with a tab character. And my guess is that the tab is throwing off its calculation of where the line end is, which would also explain why the cursor ends up to the right of the line end position.

And note that for these files I have the tab stop distance set to 4. I thought maybe something in there by might be assuming a tab stop of 8, but I changed it to that and it still fails.

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Bug with vim line-end matching in substitution
« Reply #10 on: August 07, 2012, 09:19:58 PM »
Ah!  Thank you!  Ok try with the attached version...

Ian P

  • Community Member
  • Posts: 59
  • Hero Points: 2
Re: Bug with vim line-end matching in substitution
« Reply #11 on: August 07, 2012, 09:36:11 PM »
Yep, that version works nicely. Thank you.  ;D