prevent windows from closing on middle_click
Adding an option to prevent windows from being closed when a buffer in
the tabline is middle clicked and the clicked buffer is currently open
in a window.
When this option is enabled, instead of closing the window a new buffer
will be opened in all of the windows editing the clicked buffer instead.
This is my first pull request AND my first experience with vimscript, so
my apologies if this is a bit sloppy 😄
This commit is contained in:
parent
781b4ea6a2
commit
7cb5c24151
|
@ -208,7 +208,41 @@ function! airline#extensions#tabline#buffers#clickbuf(minwid, clicks, button, mo
|
|||
silent execute 'buffer' a:minwid
|
||||
elseif a:button is# 'm'
|
||||
" middle button - delete buffer
|
||||
silent execute 'bdelete' a:minwid
|
||||
|
||||
if get(g:, 'airline#extensions#tabline#middle_click_preserves_windows', 0) == 0
|
||||
" just simply delete the clicked buffer. This will cause windows
|
||||
" associated with the clicked buffer to be closed.
|
||||
silent execute 'bdelete' a:minwid
|
||||
else
|
||||
" find windows displaying the clicked buffer and open an new
|
||||
" buffer in them.
|
||||
let current_window = bufwinnr("%")
|
||||
let window_number = bufwinnr(a:minwid)
|
||||
let last_window_visited = -1
|
||||
|
||||
" Set to 1 if the clicked buffer was open in any windows.
|
||||
let buffer_in_window = 0
|
||||
|
||||
" Find the next window with the clicked buffer open. If bufwinnr()
|
||||
" returns the same window number, this is because we clicked a new
|
||||
" buffer, and then tried editing a new buffer. Vim won't create a
|
||||
" new empty buffer for the same window, so we get the same window
|
||||
" number from bufwinnr(). In this case we just give up and don't
|
||||
" delete the buffer.
|
||||
" This could be made cleaner if we could check if the clicked buffer
|
||||
" is a new buffer, but I don't know if there is a way to do that.
|
||||
while window_number != -1 && window_number != last_window_visited
|
||||
let buffer_in_window = 1
|
||||
silent execute window_number . 'wincmd w'
|
||||
silent execute 'enew'
|
||||
let last_window_visited = window_number
|
||||
let window_number = bufwinnr(a:minwid)
|
||||
endwhile
|
||||
silent execute current_window . 'wincmd w'
|
||||
if window_number != last_window_visited || buffer_in_window == 0
|
||||
silent execute 'bdelete' a:minwid
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
|
|
@ -145,7 +145,6 @@ values):
|
|||
>
|
||||
let g:airline_skip_empty_sections = 1
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
COMMANDS *airline-commands*
|
||||
|
||||
|
@ -693,6 +692,10 @@ Note: Enabling this extension will modify 'showtabline' and 'guioptions'.
|
|||
won't update airline on |:badd| commands) >
|
||||
let airline#extensions#tabline#disable_refresh = 0
|
||||
|
||||
* preserve windows when closing a buffer from the bufferline (default: 0) >
|
||||
|
||||
let airline#extensions#tabline#middle_click_preserves_windows = 1
|
||||
<
|
||||
------------------------------------- *airline-tmuxline*
|
||||
tmuxline <https://github.com/edkolev/tmuxline.vim>
|
||||
|
||||
|
|
Loading…
Reference in New Issue