In Vim we can travel to different lines using ':<line-number>'.

And we can also sync the screen by typing 'zt' in normal mode.

But how do we have the screen get synced automatically every time we go to a specific line?

有帮助吗?

解决方案

If by syncing you mean centering the line at the top (what zt does) / middle / bottom, you can achieve an always-on centering of the current line in the middle via:

:set scrolloff=999

For all other, I'd recommend a custom G mapping:

:nnoremap G Gzt

To make this also work with :[N] and all other jump commands, you'd have to define :autocmds, and I would recommend against that.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top