I'd like to keep the cursor at the middle of the screen wherever I am in the file, without scrolling. This mean to have blank space above the file when I'm at the start of the file, and have blank space under the file when I'm at the end of the file.

I now there is this answer who give a hack (only to have blank space after the file), but we have to remap all keys, which is not really convenient, and it does not work in insert or visual modes.


I have part of a solution.

I am not sure for the top of the file, but for the bottom of the file, if you use CTRL_e to scroll down, you can scroll as far as having the last line of the file at the top of your screen. You can also use CTRL_y to scroll up, but at the top of the file it will not scroll higher.

These two commands allow to scroll the view without moving your cursor (unlike using k and j to scroll up or down when the cursor is at the top or bottom). It is similar to scrolling with the mouse.

And it works in visual mode, however not in insert mode.

If anyone has suggestions for the uncovered cases (top of the file and insert mode, if it is possible), a completion of this answer would be welcome.

  • Thanks for your answer, but I'm looking for something automatic. I edited my post.
    – Phantom
    May 17 '19 at 7:56
  • So when you move your cursor, you want the the view to automatically move so that it stays in the middle, correct?
    – padawin
    May 17 '19 at 7:58
  • yes, that's it :)
    – Phantom
    May 17 '19 at 8:10
  • Fair enough. From what I see online, it seems only possible through mappings, or configurations such as the link you provided or vim.fandom.com/wiki/…
    – padawin
    May 17 '19 at 8:16

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.