2

Editing at the top or bottom of the screen is uncomfortable, so why use zz all the time (also scrolloff). That works fine in the middle of the document, and in the end, and I can keep the cursor centralized.

However, it seems the beginning of the document cannot be centralized. More precisely, I can't scroll above the first line (while below the last line works fine). Is there anyway to fix this?

Thanks.

  • AFAIK, there's no fix for this. Vim simply can't go "passed" the first line of the document. – Tumbler41 Aug 17 '17 at 17:11
2

There is no direct solution to this unless you play with the internals. However you can use a macro to simulate what you are trying to acheive.

use :1s/\%^/\="\n\n\n\n\n\n\n\n\n\n\n"/g <Enter> zz as the first macro to enter 10 lines above the first line of text and center the screen.

After you are done editing, you can use :1s/\n\n\n\n\n\n\n\n\n\n//g as the second macro to delete the first 10 lines.

More details and explainations can be found here: https://github.com/alphaCTzo7G/stackexchange/blob/master/solution.md

You can clone this and play around with this file and see if it works for you.

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.