Open a buffer on a new Tab on Vim

1.8k Views Asked by At

I'm creating a Vim plugin that I need intercept when a new buffer is loaded.

The basic idea consists in when I open a new buffer this new buffer must be screened on another tab, and the previous tab must keep the previous buffer loaded.

Eg.: I have a buffer with the foo.txt, when I try to open bar.txt with :e bar.txt It will open in a new tab and the previous tab must stay with the foo.txt. I know that :tabe bar.txt does the job, but to my plugin I need the "tabe behavior" even when it's not used to open a file.

Does anyone have any idea how to do this with Vimscript?

The reason behind this: https://github.com/vim-ctrlspace/vim-ctrlspace/issues/177.

2

There are 2 best solutions below

5
romainl On

You are making things more complicated than needed.

augroup tab
    autocmd!
    autocmd BufReadPost * tabedit %
augroup END
0
BlackORTS On

Try using this

au BufNewFile,BufRead * nested
  \ if &buftype != "help" |
  \   tab sball |
  \ endif