AndrewRadev/switch.vim

nested patterns change all matches from cursor to EOF

Closed this issue · 8 comments

tek commented

Hi there, this occured to me when using the ruby_array_shorthand builtin:

['foo'] 
['bar']
['far']
something
['boo']

becomes

['foo'] 
%w(bar)
[far)
something
[boo)

when executing :Switch while the cursor is in column 1 of line 2.
Only the second and third rule are being applied everywhere, apparently.

Hm, an odd issue. It seems like, for some reason, the plugin is running the :substitute on all lines instead of just the current one. I can't reproduce this, so it's probably affected by some setting. However, for starters, I just fixed a pretty obvious bug in nested pattern handling, so you might want to check out the newest version and see if the problem persists (maybe it was related). I expect it'll still be there, in which case, could you post your Vim settings somewhere so I can debug?

tek commented

The problem persists. These are my options: https://gist.github.com/6200367

Even with your settings, I can't seem to replicate it. Could you try using the debug-issue-8 branch (https://github.com/AndrewRadev/switch.vim/tree/debug-issue-8), run the :Switch and then let me know what the output of :messages is? Alternatively, could you provide me with your full Vim configuration to test with?

tek commented

There you go: https://gist.github.com/6201229
About my full config – it's distributed over three repos, two of which I don't have on github. I'll try to create a single file from the most relevant parts.

I still don't see anything odd in the messages. The only difference from my run of the same thing is the %>3c, but I'm simply assuming you ran it from the 2nd column or something. And it shouldn't cause this issue anyway.

Could you run the commands you pasted manually and tell me if you get the same result? For example this one:

:s/\%>3c['"]\(\k\+\)['"],\=/\1/ge
tek commented

That revealed the reason: After issuing the first command, the lines from cursor to EOF are being folded. This actually happens quite often in my vim…must be a plugin or setting causing this.

Ah, I see. That seems like weird behaviour, although I can imagine that the replacement of a pattern could turn out to be a foldmarker, causing the area to be folded. Just in case, I've added a silent! foldopen! before the substitute, which should take care of the edge case, hopefully without side effects (if you're switching, you probably don't want to do it on folded text anyway).

tek commented

great, works fine now!