As title. I have the following script and I want to set scrolloff to 0 when the cursor is approaching the last line of the current file.

vim.cmd [[
  augroup switchScrolloffTopBottom
    autocmd CursorMoved * if winline() != &lines/2
          \| setlocal scrolloff=0
          \| setlocal scrolloff=100
  augroup END

  • 2
    Line of the cursor is line('.') and last line is line('$'), so you could just compare these two? If you get to figure it out given this hint, feel free to post a self-answer with what worked for you...
    – filbranden
    Dec 16 '21 at 17:32
  • Something like if... > &lines/10 ... else if ... < &line/10 should do. Problem is, if the result is lower than your current scrolloff, you won't be able to move your cursor on this line so it'll never get a chance to update.
    – Biggybi
    Dec 16 '21 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.