vicoapp/vico — pull request #45 by Shadowfiend (2013-06-17 03:22:29+00:00)
Title: :s fixes/tweaks

I'm going to generally follow a policy of keeping a pull request open for
my own stuff for at least a week to gather any feedback the community
may want to give for now; this can evolve as the community grows. If
I open a pull request and don't see any activity for a week, I'll go ahead
and merge it in. Likewise, I'll try to give feedback on any requests I see
within a week if at all possible.

This PR does a variety of things with the `:s`/`:substitute` command,
and fixes a couple of incidental issues because I ran into them as I was
making these changes. Here's a list:

- Fixes undo behavior for `:s`. Before undo would undo each substitution
in turn, whereas we now properly undo all substitutions at once. This is
more in line with vim behavior.
- Fixes caret behavior for `:s`. At the end of a substitution, the caret is now
properly placed at the end of the last match that was substituted, or at the
end of the file if nothing matched.
- Fixes jumplist tracking for `:s`. After a substitution, the previous location
in the jumplist is now the place where you were when you ran the
substitution command. This means immediately after a substitution
command, you can use `''` or its sibling \`\` to return to the point you were
at before you performed the substitution.
- Fixes newline handling for `:s` (this is the fix for issue #42). Newlines
in the command will properly be matched. We also properly display the
affected lines and the number of matches when the `/n` flag is provided.
- Adds support for the `/m` regex flag in substitutions. vim handles this
situation differently, providing various ways to indicate you're willing to
match newlines with `.` in the regex or whatever, but I'm trying not to
deviate too far from more standard regex syntax if possible.
- Report the number of affected lines and the number of replacements
even when the `/n` flag isn't provided. Before you had to add `/n` to the
end of the pattern to see the lines/replacements, but when you ran the
actual substitution that information was not reported. It is now reported
when you run the regular substitution as well.
- Fix an issue where the new status view would not display messages if
any status components changed during the same run loop cycle as a
message was displayed. This would occur if, for example, a message
was displayed during a command that also updated the caret (like
`:substitute`). We no longer hide messages when a status component
changes if that change occurs during the same run loop cycle as the
message was displayed.