JugglerShu/XVim — pull request #496 by xoob (2013-10-12 11:36:57+00:00)
Title: Full search implementation (work in progress)

I've taken some time to extend the XVim search command to support more Vim capabilities. This is a work in progress and I would like to get some feedback as well.

**New Features**

- Templates in replacement text, `:s/do(.+)Now/do$1Later/`. Note that it currently uses the `NSRegularExpression` format `$1`, `$2`, ...
- Replace all occurrences in the line, `:s/../../g`. Without replacement occurs only for the first occurrence in each line.
- Implementation is very close to the actual Vim method and handles multiline replacements and line count changes. This fixes some looping conditions and works overall very similar to Vim now.

**To-Do**

- [ ] Prompt `replace with %s (y/n/a/q/l/^E/^Y)?` when confirm flag is set (`:s/.../.../c`)
- How do we show the message and let the user respond?
- [ ] Set and use `self.isCaseInsensitive`, `self.lastSearchCmd`, etc.
- [ ] Merge the new substitute code with the other search methods
- [ ] Fix infinite loop with `:s/\n/#/`. `:s/\n/#/g` works fine.
- [ ] Add unit tests for normal expressions and edge cases
- `:s/\xXX//`
- `:%s/$/;/`
- `:%s/\n/#/g`
- `:%s/[a-z] */(&)/g`
- [ ] Handle `\c`, `\C`
- [ ] Handle `:s/../../{offset}`
- [ ] Handle `&` (repeat last substitute)
- [ ] Handle Vim-style replacement templates (`\0 \& \~ \u \U \l \L \e \E`)
- [ ] Add support for `fromCol` and `toCol` instead of only allowing `fromLine` and `toLine`
- [ ] Review text substitution methods
- The original method to replace text was `[NSTextView insertText:replacementRange:]` but calling it caused position errors on undo. The text `testingSomething` with `:s/testing/xxx/` would say `testingtingSomething`.
- New code is using `[NSTextStorage replaceCharactersInRange:withString:]` which works great. Undo and redo works as long as you call `[NSTextView shouldChangeTextInRange:replacementString:]` before.
- [ ] Refactor `XVimSearchMatch`
- I've introduced it to track line and col for the match range. Should this be in a different place, maybe `XVimRange` or a new struct instead?
- [ ] Refactor the `arg_next`, .. macros. What's the best way to do this?