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>
3
  • 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, 2017 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, 2017 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, 2017 at 12:41

2 Answers 2

2

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>
0
0

finally, I found the answer after some years. add below in .vimrc

let g:tagbar_width = winwidth(0) * 10/100

it set the taglist 10 percent of screen.

Your Answer

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

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