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 [
and ]
marks for this purpose, e.g.:
nnoremap gc `[v`]
Pressing gc visually select the previous change.
:'[,']s/var_name/varName/g
Replace in the last modified lines every var_name
with varName
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("']")
See: :h ']
and :h '[
'[
and']
mark the first line and the last line of the last change but individual lines are not remembered in a useful way. Useful in the context of your question anyway. – romainl Jul 25 '16 at 8:03