20

When splitting Vim window horizontally, contents of the "old" window are scrolled so as to preserve relative cursor line position. This happens even for small "helper" buffers, like quickfix or preview window.

The text movement caused by this becomes annoying when a split is repeatedly opened and closed - e.g. preview window used by completion plugin. Is it possible to disable this feature, and don't scroll old window when splitting (unless it's necessary to keep cursor line visible)?

Example - current behavior:

+--------------+              +--------------+
| a            |              | b            |
| b            |    copen     | c  (cursor)  |
| c  (cursor)  |     -->      | d            |
| d            |              +--------------+
| e            |              |  (preview)   |
+--------------+              +--------------+

Desired behavior:

+--------------+              +--------------+
| a            |              | a            |
| b            |    copen     | b            |
| c  (cursor)  |     -->      | c  (cursor)  |
| d            |              +--------------+
| e            |              |  (preview)   |
+--------------+              +--------------+
rburny
  • 1,559
  • 1
  • 9
  • 28

2 Answers2

2

I reached this question when searching for a solution to this problem myself. I couldn't find a good solution and it really bugged me so I ended up writing a small vim plugin that will solve this.

https://github.com/gillyb/stable-windows

I think it does exactly what you want it to do. I only wrote it recently, so if there's any bugs feel free to open an issue and I will try to fix them.

Hope it helps! :)

gillyb
  • 8,760
  • 8
  • 53
  • 80
  • 1
    I see you opened an issue on the github repo, thanks! I'll try to fix this soon!! Sorry for the inconvenience.. – gillyb Nov 05 '19 at 09:22
1

Try something like

 map <F12> mcHmh:split<cr>'hzt`c

store position in c mc

H move to top store the position to h mh

your command here split for example

got to h 'h put this to lien to top zt and got to c

Ôrel
  • 7,044
  • 3
  • 27
  • 46
  • Thanks, but this only applies to manually opened splits, and I'm mostly concerened about preview window (edited the question to make it more obvious). – rburny Jun 02 '15 at 09:23