romgrk / barbar.nvim

The neovim tabline plugin.
2.16k stars 81 forks source link

Currently there are multiple buffers in nvim. I want to close the operation. When only one buffer is included, exit nvim. But it seems that the following code does not take effect. How should I deal with it? #520

Closed whxcode closed 10 months ago

whxcode commented 11 months ago

Currently there are multiple buffers in nvim. I want to close the operation. When only one buffer is included, exit nvim. But it seems that the following code does not take effect. How should I deal with it?

It will execute the exit nvim operation

image

if vim.F.if_nil(vim.g.rafi_window_q_mapping, true) then vim.api.nvim_create_autocmd({ 'BufWinEnter', 'VimEnter' }, { group = augroup('quit_mapping'), callback = function(event) if vim.bo.buftype == '' and vim.fn.maparg('q', 'n') == '' then local c =#vim.api.nvim_list_bufs() if c == 1 then --map('n', 'q', 'quit', {}) else --map('n', 'q', 'BufferClose', {}) end end end, }) end

Iron-E commented 10 months ago

It would probably work best as a functional mapping. Something like this:

vim.keymap.set('n', 'q', function()
    vim.api.nvim_command(#vim.api.nvim_list_bufs() > 1 and 'quit' or 'BufferClose')
end, {})
whxcode commented 10 months ago

It would probably work best as a functional mapping. Something like this:

vim.keymap.set('n', 'q', function()
    vim.api.nvim_command(#vim.api.nvim_list_bufs() > 1 and 'quit' or 'BufferClose')
end, {})

Thanks!