Last active
December 17, 2015 19:39
-
-
Save kshenoy/5661878 to your computer and use it in GitHub Desktop.
Function to toggle/enable/disable scrollbind for a set of open window splits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! ScrollBind(...) | |
" Description: Toggle scrollbind amongst window splits | |
" Arguments: 'mode' ( optional ) If not given, toggle scrollbind | |
" = 0 - Disable scrollbind | |
" 1 - Enable scrollbind | |
let l:curr_bufnr = bufnr('%') | |
let g:scb_status = ( a:0 > 0 ? a:1 : !exists('g:scb_status') || !g:scb_status ) | |
if !exists('g:scb_pos') | let g:scb_pos = {} | endif | |
let l:loop_cont = 1 | |
while l:loop_cont | |
setl noscb | |
if !g:scb_status && has_key( g:scb_pos, bufnr('%') ) | |
call setpos( '.', g:scb_pos[ bufnr('%') ] ) | |
endif | |
execute "wincmd w" | |
let l:loop_cont = !( l:curr_bufnr == bufnr('%') ) | |
endwhile | |
if g:scb_status | |
let l:loop_cont = 1 | |
while l:loop_cont | |
let g:scb_pos[ bufnr('%') ] = getpos( '.' ) | |
normal! gg | |
setl scb | |
execute "wincmd w" | |
let l:loop_cont = !( l:curr_bufnr == bufnr('%') ) | |
endwhile | |
else | |
let g:scb_pos = {} | |
endif | |
"if g:scb_status | |
" echom "Enabling scrollbind" | |
"else | |
" echom "Disabling scrollbind" | |
"endif | |
endfunction | |
nmap <silent> <leader>sb :call ScrollBind()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment