0

I use Vim to do some C coding and for this I installed the YouCompleteMe extension. This extension, among other things, provides source code autocompletion and when I select an item within the menu, a new buffer is opened and it disappears when I choose the right autocompletion alternative.

If I have a split window setup and I have resized windows (for instance, enlarging the window at the top), each time the new buffer appears and then disappears, the smaller window gets enlarged again, forcing me to run the command 10^W+ each time that buffer appears. This is quite annoying: is there a way to tell ViM to "preserve windows sizes"?

1

Option equalalways is on by default and responsible for this.

set noequalalways

should preserve windows sizes

There is also winfixheight and winfixwidth settings you can use to preserve height and width of a current window before any other resize commands. I use it to implement "lens.vim" like functionality (simplified version):

"" There is lens.vim plugin but essentially this simplified version could be used
"" instead. Original lens.vim laaaags if switched to a huge file, it
"" calculates target width consuming whole file into memory....
""
"" Add following lines somewhere in you vimrc:
"" augroup autosize_windows | au!
""     au BufWinEnter,WinEnter * silent! call Lens()
"" augroup end
func! Lens() abort
    let width = max([
                \ 80,
                \ winwidth(0)
                \ ])
    let height = max([
                \ 20,
                \ winheight(0)
                \ ])

    execute 'vertical resize ' . width
    execute 'resize ' . height
    setlocal winfixheight
    setlocal winfixwidth
    wincmd =
    setlocal nowinfixheight
    setlocal nowinfixwidth
    normal! ze
endfunction

My current implementation if you are interested.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.