I'm trying to make it easier to refactor stuff by running a single command that "performs the last rename interactively".
I have a binding for doing this that sort of works, but I'm curious whether there's a way to prevent it from ever getting "out of sync" by replacing an old substitution with a recent edit.
so far the best I've been able to find is this, which clobbers a register and a marker and the user to manually "wrap" commands so that they populate the contents of the p
register. It's also very easy for <leader>,
to pick up a new edit and there's absolutely no indication that this has happened.
nnoremap ciw mP"pyiw`Pciw
nnoremap <silent> <leader>, :%s/<c-r>p/<c-r>./gc<cr>
I'd like to be able to start with a file that looks like this:
AAAA (instant 1)
AAAA
AAAA
AAAA
run the following commands gg0ciwBBBBBBB<esc>
, get the following buffer
BBBBBBB (instant 2)
AAAA
AAAA
AAAA
since ciw
has been remapped, running <leader>,
causes the buffer to look like this
BBBBBBB (instant 3)
BBBBBBB
BBBBBBB
BBBBBBB
This is correct behavior. If, however, I performed I inserted and then deleted some text after (instant 2)
. By performing 0ia<esc>
and then x
aBBBBBBB (instant 2.1 -- alternate)
AAAA
AAAA
AAAA
BBBBBBB (instant 2.2 -- alternate)
AAAA
AAAA
AAAA
then performing <leader>,
will result in the following buffer
BBBBBBB (instant 3 -- alternate)
a
a
a
the correct identifier AAAA
was targeted, but the contents of the .
register has changed. I'd like a solution where performing a mismatched substitution is simply impossible.
nnoremap {key} :%s/<c-r><c-w>//gc<left><left><left>
? maybe add<c-f>
to bring up the command-line window? Would that be sufficient? – Peter Rincker Mar 21 '19 at 17:21ciw
+ entering text as an action that targets the substituted text. Ideally what I'd like to do is set upciw
in such a way that the subsequent edit is stored in a particular register (sayo
) sop
ando
are always in sync. – Gregory Nisbet Mar 21 '19 at 17:29:%s
substitution. In other words, you want to make it interactive. I'm guessing you are writing a plugin. I don't have any idea though. You should look at established plugins that use this type of features. – klaus Mar 21 '19 at 17:55