Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

vim-plugin

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)   |
+--------------+              +--------------+
like image 336
rburny Avatar asked Jun 01 '15 21:06

rburny


2 Answers

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! :)

like image 112
gillyb Avatar answered Nov 03 '22 04:11

gillyb


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

like image 45
Ôrel Avatar answered Nov 03 '22 04:11

Ôrel