1

I'm trying to select specific lines without too much cursor movement - ranages to the rescue! But, let's assume I'm working on line 15370 (legacy codebase :() and want to delete lines 15355 and the tree following lines. I could :15355,15358d or to save some typing :15355;+3d but both will move the cursor. Actually, the ; will even move the cursor if I'm only yanking instead of deleting those now.

How could I specify a relative line number as the second argument of a range without moving the cursor? Is there something like a back reference in regular expressions for ranges?

  • Hi Chris. vim is computer software and therefore absolutely on-topic here. Can you please point me to the thread that claims they're off topic here and should be asked on Stack Overflow? That's simply not correct. Of course, they are acceptable there as well, so if you really want, let me know and I'll move it. Cheers – slhck Nov 10 '13 at 11:49
  • slhck: I was referreing to this thread on meta. Personally don't care much where it is, just wanted to make sure it fits :) – c089 Nov 10 '13 at 13:55
  • Ah, I see. Well, that was posted in 2009, where SU was still very young. It's all changed a bit. I added a note on that thread. Anyway, if you don't get a sufficient answer, flag and let us know. – slhck Nov 10 '13 at 13:59
5

You cannot avoid that Ex commands like :substitute change the cursor position; that's their built-in behavior. But Vim stores the previous position in the jump list, so a <C-O> (or ``) brings you back to where you issued the command.

PS: That relative addressing command in your question needs to be :15355;+3d; the + is needed to go 3 lines down instead of to line 3.

  • Thanks for the correction, I updated the question. C-o is a possible workaround of course :) – c089 Nov 10 '13 at 14:04

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.