Vim: do not move window content when opening preview / quickfix
Asked Answered
C

2

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)   |
+--------------+              +--------------+
Cassondra answered 1/6, 2015 at 21:44 Comment(3)
Note: this question is posted to SO, as the answer will likely require Vimscript programming.Cassondra
Did you find a solution?Sarisarid
Unfortunately, no - and I don't find it annoying enough to write a plugin to fix it :)Cassondra
A
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! :)

Allurement answered 4/10, 2019 at 10:53 Comment(1)
I see you opened an issue on the github repo, thanks! I'll try to fix this soon!! Sorry for the inconvenience..Allurement
C
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

Connelley answered 2/6, 2015 at 7:58 Comment(1)
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).Cassondra

© 2022 - 2024 — McMap. All rights reserved.