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

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

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.