Created
March 10, 2015 09:26
-
-
Save dahu/10858ec9ccd9a572bf90 to your computer and use it in GitHub Desktop.
Restore buffer position when switching between buffers
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
| " Barry Arthur, March 2015 | |
| " Restore buffer position when switching between buffers | |
| function! SaveBufPos() | |
| let b:tline = line('w0') | |
| endfunction | |
| function! RestoreBufPosTrigger() | |
| if exists('b:tline') | |
| augroup RestoreBufPos | |
| au! | |
| au CursorHold,CursorMoved <buffer> call RestoreBufPos() | |
| augroup END | |
| endif | |
| endfunction | |
| function! RestoreBufPos() | |
| exe 'normal! ' . (b:tline + &scrolloff) . 'Gzt' | |
| normal! `` | |
| augroup RestoreBufPos | |
| au! | |
| augroup END | |
| endfunction | |
| autocmd BufLeave * call SaveBufPos() | |
| autocmd BufEnter * call RestoreBufPosTrigger() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment