I have relativenumber turned on and sometimes find it convenient to use ex copy/move/delete on certain lines. For instance, my cursor might be at the top of the screen and there are two lines I want to delete, but they're way down the page. So I run something like :+43,+44d.

Unfortunately, this moves the cursor down 43 lines (along with deleting the specified lines), which means I have to waste keystrokes getting back where I started (with, e.g., 43gk). I could set a mark before entering the initial command, but that ends up using just as many keystrokes. Is there some kind of flag that could be used to run the command without moving the cursor position, or some way to implement such as a mapping or function?

2 Answers 2


I don't believe there is a way to run an ex command without moving the cursor, but there is a much more convenient way to get back to where you were. When you run an ex command, the current location will be added to your "jumplist". You can use <C-o> to move back in the jumplist. From :h ctrl-o

CTRL-O          Go to [count] Older cursor position in jump list
            (not a motion command).  {not in Vi}
            {not available without the |+jumplist| feature}

That should be more convenient than 43gk.

  • 1
    +1. I use the jumplist all the time, but I never thought to see if running an ex command would make an entry! I should really review the rules for what creates one, I'm always guessing. Commented Oct 8, 2016 at 22:03

Ex commands have always worked like this:

  1. move the cursor to the given line,
  2. perform the given command

and there's no way to change that.

But you don't have to set a mark manually or climb back to where you were: you only have to use the automatic marks ' or `:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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