4

After running a command that opens a new split (e.g. :botright 10new), how can I have the cursor move back to its previous position? A use case would be to show a message in a scratch buffer without moving out of the current file.

1 Answer 1

6

Use :h :wincmd to go to the previous window with :h CTRL-W_p, leaving your cursor where you were before the split.

Following your example, to create a window 10 lines tall at the bottom of the tab, then return to the previous cursor position:

:botright 10new | wincmd p
2
  • 1
    Easier is wincmd p here, since you're in command-line mode already...
    – filbranden
    Nov 10, 2020 at 5:17
  • 1
    @filbranden Thanks, I've edited my answer. Nov 10, 2020 at 5:22

Your Answer

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

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