Created
October 10, 2011 20:31
-
-
Save grota/1276427 to your computer and use it in GitHub Desktop.
Easier buffer navigation, to review
This file contains 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
" 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> |
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
If you move the | and _ wincmd's into the Restore function you wouldn't have to worry about inadvertently maximizing any windows.
You could prefix the function names with
s:
to make them local to the script.Performance will probably not even be noticeably affected, but if it is you'll be able to tell pretty quickly.
I wouldn't worry about expr -- this is clear enough and it works.