As far as I am aware, there is no way to prevent a tab from being closed in Vim. However (and I am only being partially facetious here), Vim won't close a tab unless you tell it to. So if you want a tab to stay open, just don't close it!
If you want a tab to be preserved across multiple Vim sessions, I would
suggest experimenting with the :mksession command, which automatically
generates a Vim script that will restore a variety of your session's
characteristics (tabs, windows, buffer list, etc.) when sourced.
The other part of your request, that a tab never be used for a different
buffer, doesn't quite make sense. Tabs don't contain buffers in Vim;
they contain an arrangement of windows, and individual windows may be
bound to buffers. As before, I don't know of any way to prevent a
particular window from being re-bound to a different buffer, but once
again, if you don't explicitly ask Vim to do so, it won't.
It sounds like you want basically Vim to protect you from mistakenly
closing a tab or changing which buffer is displayed in a given window,
but Vim has no way of knowing whether the command you gave it was
intentional or mistaken, so it just does what you tell it. I suppose,
though, that it wouldn't be very challenging to write a plugin (or add
some lines to your .vimrc) that allow you to tag a window with a
particular variable, and then use e.g. a BufWinLeave autocommand to
prevent changing buffers if that variable is set. For example:
function! s:no_buf_change(prev_buf)
if exists('w:nobufchange') && w:nobufchange
execute 'buffer' a:prev_buf
endif
endfunction
autocmd BufWinLeave * call s:no_buf_change("<afile>")
The above is completely untested and probably won't work as-is, but
maybe it gives you an idea to work from. The idea is that you would use
`let w:nobufchange = 1` in a particular window to prevent it from being
changed to display a different buffer. The function is intended to
automatically re-load the previous buffer for a given window whenever
the buffer is changed, if the window has been tagged with that variable.
pgpfam9xlaftG.pgp
Description: PGP signature
