Skip to content

Instantly share code, notes, and snippets.

@grota
Created October 10, 2011 20:31
Show Gist options
  • Save grota/1276427 to your computer and use it in GitHub Desktop.
Save grota/1276427 to your computer and use it in GitHub Desktop.
Easier buffer navigation, to review
" Easy buffer navigation, the following:
" http://vim.wikia.com/wiki/Avoid_scrolling_when_switch_buffers
" does not work because the events BufLeave,BufEnter are called
" before the <C-w>|<C-w>_ commands
function Savewinpos()
let b:winview = winsaveview()
endfunc
function RestoreWinPos()
if(exists('b:winview')) | call winrestview(b:winview) | endif
endfunc
nnoremap <silent> <C-h> :call Savewinpos()<CR><C-w>h<C-w>\|<C-w>_:call RestoreWinPos()<CR>
nnoremap <silent> <C-j> :call Savewinpos()<CR><C-w>j<C-w>\|<C-w>_:call RestoreWinPos()<CR>
nnoremap <silent> <C-k> :call Savewinpos()<CR><C-w>k<C-w>\|<C-w>_:call RestoreWinPos()<CR>
nnoremap <silent> <C-l> :call Savewinpos()<CR><C-w>l<C-w>\|<C-w>_:call RestoreWinPos()<CR>
@grota
Copy link
Author

grota commented Oct 10, 2011

gotcha, thanks!
I'm getting an E81 while using the s: prefix, but I'll work it out.
a 🎩 to you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment