Mika Fischer
Mika Fischer

Reputation: 4258

vim: open preview window without moving text in main window

When omni-completion (or other things) opens the preview window, the size of the main window is reduced in order to make room for the preview window.

By default, the first line that was visible in the main window before the preview window pops up will also be the same after the preview window pops up. This has the unfortunate effect that the text in the main window is pushed down visually.

I would prefer if the text in the main window would stay where it is. This would effectively mean that the first visible line in the main window would need to change when the preview window pops up and closes.

Does anyone know a nice way to accomplish this?

Upvotes: 11

Views: 1769

Answers (4)

gillyb
gillyb

Reputation: 8910

Update: I stopped maintaining the plugin mentioned below, plus vim implemented a setting to fix this, called splitkeep

Original Answer:

I reached this question when searching for a solution to this problem myself (although I don't use omni-completion, but other windows also mess with the windows scroll position). 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! :)

Upvotes: 3

Peter Benjamin
Peter Benjamin

Reputation: 460

As of September 2022, vim introduced the native option splitkeep.

Setting the option set splitkeep=screen achieves the desired behavior.

Upvotes: 2

erwin
erwin

Reputation: 738

There's a new neovim plugin called "Stabilize" that handles this. Even the author of the plugin referenced above, "stable windows" has moved to NeoVim and "Stabilize".

I've only been using it for a few minutes, but overall this seems to fix exactly the current line jumping around issues that were bothering me with splits and the quickfix list.

https://github.com/luukvbaal/stabilize.nvim

Upvotes: 2

Benoit
Benoit

Reputation: 79165

I don't know how to trigger this, but use : :normal! Hmx`` to save current window position, and :normal! `xzt`` to restore it.

Upvotes: 3

Related Questions