I would like to keep my cursor centered vertically as I type away in insert mode even when I reach the end of the buffer I am editing (at which point I would like the virtual lines starting with
~ to populate the screen, or something similar). From this question, I understand that it may be impossible to do this at the top of the file, but since I almost always edit at the bottom, I was wondering if it is possible to maintain this behavior at the bottom of the file. Specifically, this is the behavior I would like to have:
- As I type or scroll in insert or normal mode at the middle of a long file, the cursor should remain vertically centered.
- As I reach the bottom, I would like the cursor to remain vertically centered and the screen be populated with virtual lines.
- If I type at the top, I don't mind the cursor not being vertically centered.
Here is what I have tried:
set scrolloff = 999. This works well in the middle of the file, but does not work at the bottom.
- Remapping scroll keys to append the
zzcommand. This works well in normal mode even at the end of the file, but does not work in insert mode.
autocmdin insert mode. Specifically, I tried both of the following:
au InsertCharPre * norm zz au TextChangedI,TextChangedP * norm zz
Both work, but both have the one weird effect. At the end of a line, whenever I type something, the cursor is positioned before the inserted character. That is, representing cursor with
End of line| <- I type the character '.' here End of line|. <- The cursor is now positioned before the '.'
Note that this happens only at the end of a line. At the middle of a line, things seem to work fine. This seems to be a quirk of
norm, and maybe somehow running different commands in the
autocmd based on weather the cursor is at the end of the line will work, but I feel like there should be a shorter way to achieve what I want.
Any help is much appreciated.