1

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?

  • I doubt whether it is possible with hour function. If you would have used dd like command, it would be difficult to find and use. By creating functions, we can remember the line numbers and perform on them – SibiCoder Jul 25 '16 at 7:41
  • 5
    '[ 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
2

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 '[

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.