2

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.

Samuel Simões
  • 141
  • 1
  • 2
  • 13
  • You have given only `tabnew`, not any file name with it. How do you expect it to work? – SibiCoder Jun 10 '16 at 05:36
  • Thanks for your comment. The previous snippet had `exe "e"file`, of course, I could do a `tabe ` but the idea isn't only open a new tab with the file, but open the file in a new tab keeping the previous tab's buffer. I removed the odd snippet in favor an example to make more clear my question. – Samuel Simões Jun 10 '16 at 11:50
  • So you want to override `:e`? Fine, use [cmdalias.vim](http://www.vim.org/scripts/script.php?script_id=746). Personally I think you should just use `:tabe` and forget messing with `:e`. What about other commands `:split`? `:enew`? `:find`? Would you override `gf` to open a tab as well? I feel like doing this would be changing a great deal of Vim to match your choice of plugin(s) and/or a some workflow (possibly a mythical workflow). – Peter Rincker Jun 10 '16 at 14:20
  • I not exactly want override commands, I want to intercept the buffer opening to redirect it to other tab for my plugin. I made a PoC of my plugin applying very rudimentary commands to do this. This gif https://raw.githubusercontent.com/samuelsimoes/vim-drawer/master/fx/demo.gif shows the idea and this is the way that I accomplished this https://github.com/samuelsimoes/vim-drawer/blob/master/plugin/vim-drawer.vim#L120-L129 – Samuel Simões Jun 12 '16 at 14:33

2 Answers2

2

You are making things more complicated than needed.

augroup tab
    autocmd!
    autocmd BufReadPost * tabedit %
augroup END
romainl
  • 186,200
  • 21
  • 280
  • 313
  • This does part of the job, but I need the previous tab keeping the previous buffer. – Samuel Simões Jun 10 '16 at 10:38
  • Complementing: let say that you are on `foo.txt` buffer, when you try to open `bar.txt` a new tab will open with `bar.txt` and the previous tab will stay with `foo.txt`. – Samuel Simões Jun 10 '16 at 10:46
  • 1
    Well, you are describing the default behavior of `:tabedit` so I'm really confused about what you are trying to do. – romainl Jun 10 '16 at 11:54
  • Let's say that you type the command `:e bar.txt`, I want in this situation the aforementioned behavior, an interception when a buffer is created and where it will be placed. This looks weird, but I need this to my plugin idea. – Samuel Simões Jun 10 '16 at 12:10
  • Trying to explain better I want the `tabe` behavior even when it's no used, like `:e bar.txt`. – Samuel Simões Jun 10 '16 at 12:34
0

Try using this

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