1

I know <C-w> = equalises window sizes but I often want to keep the heights as they are. I have set noequalalways in my .vimrc as leaving it on ruins layouts when temporary windows open (like Tagbar). I thought there'd be a one-liner to do this.

1 Answer 1

1

I ended up writing a plugin ~/.vim/plugin/equalise-window-widths.vim.

nnoremap <Leader>= :call EqualiseWindowWidths()<CR>

function! EqualiseWindowWidths()
    let l:i = 1
    let l:n = winnr('$')
    let l:wfh = ['dummy']
    let l:wfw = ['dummy']
    while l:i <= l:n
        let l:wfh = add(l:wfh, getwinvar(l:i, '&winfixheight', 0))
        call setwinvar(l:i, '&winfixheight', 1)
        let l:wfw = add(l:wfw, getwinvar(l:i, '&winfixwidth', 0))
        call setwinvar(l:i, '&winfixwidth', 0)
        let l:i += 1
    endwhile
    execute 'wincmd ='
    let l:i = 1
    while l:i <= l:n
        call setwinvar(l:i, '&winfixheight', l:wfh[l:i])
        call setwinvar(l:i, '&winfixwidth', l:wfw[l:i])
        let l:i += 1
    endwhile
endfunction

It's on Vim scripts so you can install it with your preferred plugin manager. It doesn't add any mappings so you may want to add the example, above, to your vimrc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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