Skip to content

Instantly share code, notes, and snippets.

@EvergreenTheTree
Created May 20, 2015 00:00
Show Gist options
  • Save EvergreenTheTree/b81d035ff3483d5ee339 to your computer and use it in GitHub Desktop.
Save EvergreenTheTree/b81d035ff3483d5ee339 to your computer and use it in GitHub Desktop.
Vim fixed side scrolling
function! s:FixScroll()
if &wrap
return 0
elseif col(".") - wincol() - &fdc + &number * &numberwidth ==# 0
return 0
endif
let l:targetcol = winwidth(0) - &sidescrolloff
if wincol() < l:targetcol
let l:move_amount = l:targetcol - wincol()
exe 'normal! ' . l:move_amount . 'zh'
endif
endfunction
" Run fixscroll command on cursor move
autocmd CursorMoved,CursorMovedI * call <SID>FixScroll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment