Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim put cursor in the middle of screen after buffer switch

Tags:

vim

When I switch buffer and then go back to it (when I get back to any buffer that was previously opened), cursor is placed in the middle of the screen, loosing previous screen position (e.g. cursor at top of the screen). Maybe this is the normal behaviour of vim, but is there any way to fix this?

This problem happens when I use :bn and bp: to switch buffers. However this behaviour does not happen when switching between tabs which is really strange.

like image 910
milarepa Avatar asked Oct 23 '25 19:10

milarepa


1 Answers

See http://vim.wikia.com/wiki/Avoid_scrolling_when_switch_buffers

" When switching buffers, preserve window view.
if v:version >= 700
   au BufLeave * if !&diff | let b:winview = winsaveview() | endif
   au BufEnter * if exists('b:winview') && !&diff | call   winrestview(b:winview) | endif
endif
like image 162
jduan Avatar answered Oct 26 '25 09:10

jduan