2

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.

3

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
  • Easier is wincmd p here, since you're in command-line mode already...
    – filbranden
    Nov 10 '20 at 5:17
  • 1
    @filbranden Thanks, I've edited my answer. Nov 10 '20 at 5:22

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.