0

I'm just new to vim script, and I want to make gvim width auto adjust when open/close vimfiler or tagbar window.

here's my not working vim script:

let g:window_raw_width = 90
let g:window_width = g:window_raw_width

function adjust_tagbar_width()
    if (g:window_width == g:window_raw_width)
        g:window_width = g:window_raw_width + 40

    else
        g:window_width = g:window_raw_width
    endif
    set lines=g:window_width
endfunction

nmap <F9> :TagbarToggle<cr>
autocmd VimEnter,BufNewFile,BufRead * nested :TagbarToggle<cr>

please help me.

  • set lines=<number> changes window height. If i clearly understand your question, you need to change column. set columns=g:window_width – Alex Kroll Apr 28 '17 at 9:38
  • @AlexKroll , I think I did set lines=g:window_width, how to auto call this function when I open gvim ? – linrongbin Apr 28 '17 at 12:34
  • You might need to put string 'call adjust_tagbar_width()' into ~/.vimrc And map key to chained call nmap <F9> :TagbarToggle<cr>:call adjust_tagbar_width()<cr> – Alex Kroll Apr 28 '17 at 12:41
1

Function name should start from capital letter

let g:is_tagbar=0

function Adjust_tagbar_width()

    if (g:is_tagbar==0)
      let g:is_tagbar=1
      set columns=120
    else
      let g:is_tagbar=0
      set columns=80
    endif
endfunction

nmap <F9> :TagbarToggle<CR> :exec Adjust_tagbar_width() <CR>

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.