Comments (14)
I also love this feature in Vim but I'm afraid it'd be a lot of work. The problem is that this feature is so incredibly flexible and nuanced that I don't think we could reach full support for it. I think it'd be possible to add support for maybe :s/foo/bar/ and probably :%s/foo/bar/ but I'm afraid of how much work would be involved to provide full regex support and support for all the regex flags.
I might be able to put together a first pass implementation of this. Again, it would be very basic at first. I'll give it a shot though. I'll admit I've been avoiding this feature because it feels pretty daunting. If anyone wants to contribute code for this feature I would gladly accept it. :)
from vrapper.
I've committed an initial implementation for this. It actually appears to work pretty well. I have support for flags 'g' and 'i' and I let Eclipse parse the regex.
The one issue I've seen is with it not calculating the end index correctly for :s, which should only affect the current line. If the line below the current one starts with a match then it performs the replace there too. I think it's an issue with Eclipse including newline characters when determining the offset but I'm not sure.
from vrapper.
I've updated the unstable update site with 0.21.20120523 which contains this feature. Give it a try and let me know if you see any glaring holes. I'm hoping this will cover the majority of the use cases even though it isn't 100%.
from vrapper.
Pretty cool, thanks.
One issue I think I'm seeing is that in vim :%s/foo/bar/ will replace the first occurence on any line, whereas in Vrapper it only replaces the first occurence globally. When the /g flag is set, vim will replace all occurences on all lines, which works the same in Vrapper.
from vrapper.
You're right. I totally implemented that wrong. I need to process each
line individually for :%s rather than treating the whole file as a single
line. I can fix that. Thanks for finding it!
from vrapper.
Awesome. Even basic string matching will be a big help. Unfortunately I know nothing about eclipse plugin development and I'm already cramming a bunch of new information (mobile apps, yay!) . Otherwise I'd be happy to work with you on this, because it is a great feature. Maybe sometime in the future if you haven't got around to regexp yet I'll dig in.
from vrapper.
Honestly, I'm not sure how much extra work will be needed for the regex. One of the arguments for Eclipse's 'find' method I'm using is essentially isRegex. I set that to true and it magically treats the search string as a regex. I'll need to investigate what exactly Eclipse supports compared to Vim's implementation of regex though. The Eclipse 'replace' method I'm using also has an argument isRegex but I have no idea how that would be used. For now, I've set that to false. I've never used a regex in the 'replace' side of things so I don't know how Vim handles that.
I think the bulk of the work in finishing this feature will be the related commands and flags. Vim's documentation shows this as the arguments:
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
As of right now, I don't support any [range] except '%' and I don't support [count] at all. I also haven't mapped 'substitute' to 's'.
In addition, there are commands such as '&' and 'g&' and a couple others which repeat that last substitution (I've already tied the Vrapper implementation to the '.' command at least). Most of those shouldn't be too bad, though I'm not sure how helpful they are either. They might be a waste of my time.
As for the flags, I don't think most of them are relevant for Vrapper. See the Vim documentation for :s_flags to see all of them.
I'd still like to think that the current implementation will cover the majority of use cases (after fixing matf's defect). I'll probably only extend it as feature requests come in rather than spending my time on features no one uses. Again though, let me know if you see any glaring holes that I should close up before releasing this feature to the world.
from vrapper.
Ok, I've updated the unstable update site again (0.21.20120524) since you guys actually seem to be testing this for me. This version contains a fix for matf's defect. Also, if a search/replace didn't find any matches, I wasn't updating the '.' command with this search. That's fixed too.
from vrapper.
Thanks, the /g flag now works as expected.
Eclipse regex syntax follows the syntax used by Java's Pattern class. Replacement syntax is documented here: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-regex-find-replace.htm
Group references in replacement strings don't seem to work yet, for example :%s/foo(.*)/bar$1/ does not expand $1, but rather replaces it literally.
Some patterns seem to produce infinite loops (Eclipse needs to be killed) with the /g flag, such as :%s/(.)/x/g
from vrapper.
Nice man, thanks for your work on this. I need to switch to the unstable
update site so I can start using it. I do often use the visual selection
range in standard Vim, but it seems that's not quite implemented yet in
vrapper so it can't be added. Most of my use cases involve something along
the lines of :[%]s/(regexp)/(replacement)/g. Use of references in the
replacement text would be cool but the more obscure features don't seem
like a priority to me. The only flags I seem to ever use are g and i, so
those are the most important imho.
Justen Robertson
http://www.justen.us
Web Development | PHP | MySQL | AJAX
On Fri, May 25, 2012 at 3:41 AM, Matt <
[email protected]
wrote:
Thanks, the /g flag now works as expected.
Eclipse regex syntax follows the syntax used by Java's Pattern class.
Replacement syntax is documented here:
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-regex-find-replace.htmGroup references in replacement strings don't seem to work yet, for
example :%s/foo(.*)/bar$1/ does not example $1, but rather replaces it
literally.Some patterns seem to produce infinite loops with the /g flag, such as
:%s/(.)/x/g
Reply to this email directly or view it on GitHub:
#64 (comment)
from vrapper.
Thanks for keeping me motivated on this feature guys, it really helps. matf, I've enabled regex support on the replace string so :s/foo(.*)/bar$1/ now works as expected.
Also, I "fixed" the infinite loop. To perform the 'g' flag, I iterate over starting offsets until I reach the end of the line. Every time I find a match, I set the starting offset to that match's offset and go again. In your /(.)/ example, the matching offset equaled my starting offset, so I was just spinning on that one index indefinitely. I changed it so that if the start index equals the offset of the match, I increment the offset before looking for the next match. This means I'll hit every index in the line, but it'll stop when it reaches the end.
I say I "fixed" it because I'm not actually sure what the desired behavior is. Obviously it isn't desirable to be stuck in an infinite loop, but I don't know what I should be doing. In Vim, it flags (.) as "pattern not found". I guess I could throw an error here, but I don't actually know under which conditions this happens. Is (.) the only string I need to watch out for? I'm sure there are other dangerous regex's and I don't want to check for all of them. So, this behavior might not be what the user intended, but at least it won't crash Eclipse.
nphyx, I'll see what I can do about visual selection range. It might be possible. That looks like a useful feature but it's a slippery slope to support all ranges. Of course, if I can get visual selection range working then an arbitrary range might end up being trivial.
There's one last defect I've found that I need to work out. I thought Vim treated whatever character was after 's' as the delimiter. So you can do :s/foo/bar/g or :s,foo,bar,g and the two operations are equivalent. However, this totally messes with Vrapper's parsing of :set . It thinks the delimiter is 'e' and tries parsing the substitution. Vim doesn't do this. I take this to mean Vim only supports a small set of characters to act as the delimiter in a substitution. I need to find what that set is so I know the word "set" doesn't match it.
from vrapper.
Figures. Someone makes an innocent comment like "I often use the visual selection range" and suddenly my Friday night is spent. I've horribly refactored the search/replace feature. It's much more complicated than before but it's also arguably a better implementation. It now supports ranges, both visual and :2,3s/foo/bar/g
style.
I believe I've now addressed every random suggestion you guys have made so please play with it and see if I broke anything during my Friday night refactoring. And yes, apparently the more time I spend on this the more cynical I become. :)
I've updated the unstable update site with 0.21.20120525. So far it seems to handle everything I've tried, though I really wish we had a way to write unit tests for this. I haven't really dug into the unit testing framework the original author wrote for Vrapper and he never supported CommandLine tests beyond the "set" functionality.
from vrapper.
Nice work man. I've been playing with it a little over the weekend, but now that the work week has started I'll get some real time with it. So far no hitches, but I'll report any issues that come up.
from vrapper.
I'm going to close this feature request. I believe it's more or less done. Still, let me know if you run into any issues.
from vrapper.
Related Issues (20)
- _vrapperrc HOT 5
- Cannot get rename to work HOT 1
- Replacing something with forward slashes HOT 8
- :reg command doesn't work when used alone HOT 8
- Vrapper not running on Eclipse 4.21.0 HOT 10
- Insert macro with { don't work HOT 2
- Replace regex within visual-box \%V is not working HOT 2
- Can't bind "option+[KEY]" using MacOS. HOT 3
- content assist like navigation in quick assist and hyperlink menus
- Can't change to a different tab that is far away with <C-w><number>gt HOT 2
- Add ":wrap" command line command bind to Eclipse's action "Toggle Word Wrap" HOT 1
- Sub-Word plugin unexpected behaviors
- Adding DVT (a SystemVerilog plugin) action to vrapper keymaps HOT 2
- Vim doesn't work on windows of Table views HOT 2
- Cannot find active input interceptor for error editor HOT 1
- ctrl+v -> i -> w leaves visual block mode
- Typing after double quote locks up Eclipse
- Stay in visual mode while jumping through editor commands
- How to assign the leader key to the spacebar? HOT 1
- Need to integrate vim and emacs plugin HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vrapper.