With vim and vim-airline, I've got a situation where I want to be able to close a buffer if it exist, and if not close vim.
So I've first remmapped :x
to ;x
for speed reasons.
nnoremap : ;
Then I mapped ;x
to close the buffers opened with vim-airline
nnoremap :x :bp <BAR> bd #<CR>
Now the issue is when I finally close all the buffers, I can't use ;x
to quit vim.
Is there any way to check if a buffer exist in vim-airline and close it? Saw this post but its more for NERDTree.
The problem: nnoremap : ;
will change the :
key to invoke the original value of the ;
command, i.e. skip to the next character matched by f
, F
, t
or T
. If you want to use ;x
, you need to remap the reverse: nnoremap ; :
.
nnoremap :x ...
will then use the original value of :
for :x
, so everything should work fine. Alternately, and less safely, you could do nmap ;x ...
to invoke the redefined value of :
(and potentially a redefined value of x
as well, if you specified map! x
, cmap x
, lmap x
, or their non-recursive variants).
Also, :bd
will not close the Vim, only the buffer and a window. If you're on your last buffer, you get dumped into a new unnamed buffer (like with :enew
). To close buffer or Vim, use :q
, that's what it's for.
(Also, I don't understand what you meant by "buffer exist in vim-airline". Airline is a status bar plugin. Buffers either exist or not. The two have nothing to do with each other, at least not in a way that is obvious to me.)