[patch] implement undo in :s_flags

138 views
Skip to first unread message

Christian Brabandt

unread,
Sep 28, 2012, 3:22:45 PM9/28/12
to vim...@vim.org
Bram,
attached patch implements undo when doing :s/.../.../gc

This has been requested recently in
https://groups.google.com/group/vim_dev/msg/9930ef0f86421814

And I think, I saw a request like this on the sf.net bug tracker, but I
can't find it right now. Additionally, I also added using Ctrl-L for
redrawing the screen as I found this useful.

regards,
Christian
u_flag.diff

Bram Moolenaar

unread,
Sep 30, 2012, 8:42:49 AM9/30/12
to Christian Brabandt, vim...@vim.org
Yeah, this is useful. But also tricky, if the undo is done wrong then
the text may get messed up. Can you think of situations where something
could go wrong? And it would be nice to have tests for that.


--
Dreams are free, but there's a small charge for alterations.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Andy Wokula

unread,
Sep 30, 2012, 9:41:37 AM9/30/12
to vim...@googlegroups.com
Am 30.09.2012 14:42, schrieb Bram Moolenaar:
>
> Christian Brabandt wrote:
>
>> Bram,
>> attached patch implements undo when doing :s/.../.../gc
>>
>> This has been requested recently in
>> https://groups.google.com/group/vim_dev/msg/9930ef0f86421814
>>
>> And I think, I saw a request like this on the sf.net bug tracker, but I
>> can't find it right now. Additionally, I also added using Ctrl-L for
>> redrawing the screen as I found this useful.
>
> Yeah, this is useful. But also tricky, if the undo is done wrong then
> the text may get messed up. Can you think of situations where something
> could go wrong? And it would be nice to have tests for that.

What about a replacement function that edits text?


com! InsaneSubst :%s/\w\+/\=InsaneEdit(submatch(0))/

func! InsaneEdit(str)
$put = a:str
return '('. a:str. ')'
endfunc

--
Andy

Christian Brabandt

unread,
Oct 1, 2012, 4:35:30 AM10/1/12
to vim...@googlegroups.com
This works, although I would personally don't think this is very
reasonable. :%s will not consider the newly added lines (it determines
the range before starting the command) and I have seen strange effects
when doing a replacement and the function changes the text directly
(e.g. E315 ml_get: invalid lnum...)

regards,
Christian

Christian Brabandt

unread,
Oct 9, 2012, 1:55:09 AM10/9/12
to Bram Moolenaar, vim...@vim.org
On Sun, September 30, 2012 14:42, Bram Moolenaar wrote:
>> attached patch implements undo when doing :s/.../.../gc
>
> Yeah, this is useful. But also tricky, if the undo is done wrong then
> the text may get messed up. Can you think of situations where something
> could go wrong? And it would be nice to have tests for that.
>

Updated patch also works for undo in vi-compatible way and includes a
test. The testing part was harder than expected, because vim doesn't
sync undo, when reading from a script, so I explicitly sync undo
when using :s/.../.../c and reading from a script.

There is one limitation so: Vim only stores up to 256 places for where
to start searching after an undo. If you have replaced more, Vim won't
start at the correct column afterwards. I thought about using a garray_T
for storing the column, but wasn't successful.

regards,
Christian.
s_undo.diff

Bram Moolenaar

unread,
Oct 9, 2012, 7:07:36 AM10/9/12
to Christian Brabandt, vim...@vim.org

Christian Brabandt wrote:

> On Sun, September 30, 2012 14:42, Bram Moolenaar wrote:
> >> attached patch implements undo when doing :s/.../.../gc
> >
> > Yeah, this is useful. But also tricky, if the undo is done wrong then
> > the text may get messed up. Can you think of situations where somethin=
> g
> > could go wrong? And it would be nice to have tests for that.
> >
>
> Updated patch also works for undo in vi-compatible way and includes a
> test. The testing part was harder than expected, because vim doesn't
> sync undo, when reading from a script, so I explicitly sync undo
> when using :s/.../.../c and reading from a script.
>
> There is one limitation so: Vim only stores up to 256 places for where
> to start searching after an undo. If you have replaced more, Vim won't
> start at the correct column afterwards. I thought about using a garray_T
> for storing the column, but wasn't successful.

Thanks. I'll have a look at it later.

--
(letter from Mark to Mike, about the film's probable certificate)
For an 'A' we would have to: Lose as many shits as possible; Take Jesus
Christ out, if possible; Loose "I fart in your general direction"; Lose
"the oral sex"; Lose "oh, fuck off"; Lose "We make castanets out of your
testicles"
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

justrajdeep

unread,
Jan 8, 2015, 7:18:31 AM1/8/15
to vim...@googlegroups.com, cbl...@256bit.org, vim...@vim.org
This would be one great addition to vim if the patch gets accepted.
Reply all
Reply to author
Forward
0 new messages