In vim, how do you scroll a buffer so the cursor location is centered in the screen?

后端 未结 5 431
半阙折子戏
半阙折子戏 2021-02-02 06:42

In vim, often I will jump to a mark I made, or a search result, and the cursor will be at the very bottom or very top of the screen. At this point, in order for the screen to b

5条回答
  •  礼貌的吻别
    2021-02-02 06:57

    The 'scrolloff' (scroll offset) option determines the number of context lines you would like to see above and below the cursor. Setting it to, say, 5 makes it so there are always 5 lines visible above and below the cursor while moving/scrolling. Setting 'scrolloff' to a large value causes the cursor to stay in the middle line when possible:

    :set so=999
    

    To restore normal behavior, enter:

    :set so=0
    

    If you're switching between those a lot, you can create a mapping to toggle quickly:

    :nnoremap ts :let &scrolloff=999-&scrolloff " ToggleScrolloff
    

提交回复
热议问题