No edit summary |
(Some clean up) |
||
Line 6: | Line 6: | ||
|complexity=intermediate |
|complexity=intermediate |
||
|author=Yakov Lerner |
|author=Yakov Lerner |
||
− | |version= |
+ | |version=7.0 |
|rating=97/28 |
|rating=97/28 |
||
|text= |
|text= |
||
− | When switching buffers (especially with Ctrl-^ and :bp), vim might change the *visual* line position. Even when vim preserves the line number |
+ | When switching buffers (especially with <tt>Ctrl-^</tt> and <tt>:bp</tt>), vim might change the *visual* line position. Even when vim preserves the line number relative to file, it might reposition the screen view such that, for example, before switching, current line (line 1234 of the file) was top line of the screen, after <tt>:bn :bp</tt> current line becomes center line of the screen (but still line 1234 relative to file). |
⚫ | |||
+ | <pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | </pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | can use following autocommands to restore screen view exactly when switching buffers: |
||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
− | check out tip [[VimTip80]] , and |
||
− | |||
− | [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:'viminfo'}} :help 'viminfo'], [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:last-position-jump}} :help last-position-jump] |
||
− | |||
− | |||
− | |||
− | Yakov |
||
⚫ | |||
}} |
}} |
Revision as of 10:45, 15 August 2007
Tip: #1375 - Avoid scrolling when switch buffers
Created: October 31, 2006 16:42 Complexity: intermediate Author: Yakov Lerner Version: 7.0 Karma: 97/28 Imported from: Tip#1375
When switching buffers (especially with Ctrl-^ and :bp), vim might change the *visual* line position. Even when vim preserves the line number relative to file, it might reposition the screen view such that, for example, before switching, current line (line 1234 of the file) was top line of the screen, after :bn :bp current line becomes center line of the screen (but still line 1234 relative to file).
If your line number is restored correctly but the shift in screen view bothers you, you can use following autocommands to restore screen view exactly when switching buffers:
" When switching buffers, preserve window view if v:version >= 700 au BufLeave * let b:winview = winsaveview() au BufEnter * if(exists('b:winview')) | call winrestview(b:winview) | endif endif
This requires vim7.
Another possibility is to use :set scrolloff=999 (which keeps current line vertically centered). Check out also :help 'nosol' (not needed if the above autocommands are used).
If you have problem with restoration of file-relative line numbers, then check out tip VimTip80, :help 'viminfo', and :help last-position-jump