Home > Back-end >  Default Vim to always open help in a new tab
Default Vim to always open help in a new tab

Time:09-16

Since I've started using Vim tabs (I'm a bit late to the game since they've been there since 2009!), I find I'd like most thing to default to tabs, so I always open files with vim -p file1 file2 etc. I would like :help / :h to always open in tabs also. I can do :tab help ctrl-w or :tab h ctrl-w but how can I use .vimrc to always default :h or :help to open in a new tab?

Additionally, is there a way to take an open file and push it into a tab, or to tell vim to take all open buffers and dynamically shift them all into tabs?

CodePudding user response:

  1. "take an open file and push it into a tab"

    You can do that with this normal mode command:

    <C-w>T
    

    or this equivalent Ex command:

    :wincmd T
    

    See :help ctrl-w_t and :help :wincmd.

  2. ":h to always open in tabs"

    You only need to put the aforementioned Ex command in after/ftplugin/help.vim:

    wincmd T
    

CodePudding user response:

You can use autocmd to always open help in a new tab

" This won't work if you open the same help file more than once
autocmd FileType help wincmd T

" This works
autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif

Or you can define a new command to only open it in a new tab, when in a small screen or there are many to read, for example. With the following, you can use :Tabhelp ....

function! Tabhelp(arg)
  execute 'tab help '.a:arg 
endfunction

command -nargs=? -complete=help Tabhelp call Tabhelp(<q-args>)
  • Related