Search code examples
vimkeyboard-shortcutsvi

vi/vim: how to scroll by a third of window height


As I understand it, Ctrl + D and Ctrl + U scroll the window by the number of lines that is set in the scroll option, which defaults to half of the height of the window. Can it be changed to scroll by a third of the window height?


Solution

  • Use following ex command. It uses the variable lines that show how many lines are shown in a window and calculates the third.

    :execute "set scroll=" .&lines / 3
    

    EDIT: When window is resized the scroll value won't change, so add following autocommand to your vimrc to fix it:

    :au VimResized * execute "set scroll=" . &lines / 3