Is there a way to target the set of lines changed in the previous command? Say I do a search and replace, bulk indent, or some other command that affects either a series or scattered collection of lines. Next, I want to run a command that targets those lines only. Is there a range shortcut or other motion command to target the previous action?
As @romainl said, you can use the
] marks for this purpose, e.g.:
nnoremap gc `[v`]
Pressing gc visually select the previous change.
Replace in the last modified lines every
If you want to use it in your function you can get informations about the last changed lines like so:
let firstline = line("'[") let lastline = line("']")
:h '] and