0

I have a nifty autocommand in my vimrc that automatically maximizes any :help window:

augroup LargeHelpWindow
    autocmd!
    autocmd BufWinEnter * if &l:buftype ==# 'help' | wincmd _ | endif
augroup END

This is really useful to optimize screen usage when using :help and it is based on buffer type. I would like to achieve the same for :Man so that I can comfortably view and navigate man documentation in Vim. However, since :Man buffers have buftype set to nofile and filetype set to man, I have to configure the resizing based on filetype. I have tried the following:

    autocmd Filetype man wincmd -
    autocmd BufWinEnter * if &l:filetype ==# 'man' | wincmd _ | endif
    autocmd WinEnter * if &l:filetype ==# 'man' | wincmd _ | endif

but this has not worked, i.e. :Man windows stay small and they need to be resized manually. I believe the reason for the failure of the autocommands above is the relative order of BufWinEnter and WinEnter vs Filetype. Unfortunately, the exact relative order is not well documented.

Is there a way to achieve automatic resizing of windows based on filetype?

1

autocmd FileType man wincmd _ should work okay. Most probably you have a typo (e.g. in your post it's "dash" instead of "underscore").

Concerning auto-events, not all of them are bound to follow specific sequence. For example, FileType is triggered right after 'filetype' option was set. For whatever reason.

1
  • I can confirm that the problem was indeed a dash - instead of an underscore _. Thanks! – mgarort Feb 26 at 12:30
1

Caveat: I don't have the :Man command which you have presumably defined yourself, but this should work:

autocmd BufEnter * if &filetype ==# "man" | wincmd _ | endif
2
  • Thanks! This works too. I have decided to accept the other answer because it was a bit more informative as to why my solution didn't work, but this also fixes the problem. Regarding :Man, in order to use it you have to source the appropriate plugin first: runtime ftplugin/man.vim, – mgarort Feb 26 at 12:31
  • No worries, glad it worked out and thanks for the the information on :Man, I was not aware of that. – Andrew Ho-Lee Feb 26 at 12:38

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.