This commit is contained in:
morfize 2026-03-09 16:02:33 +09:00
parent 8921b605ec
commit ff0445d6fd
2 changed files with 222 additions and 4 deletions

View File

@ -33,7 +33,42 @@ local opts = { noremap = true, silent = true }
map('n', ';', ':', { desc = '' })
-- buffer control
map('n', '<Tab>', '<cmd>bnext<CR>', { desc = 'Next buffer' })
map('n', '<Leader>x', '<cmd>bdelete<CR>', { desc = 'delete buffer' })
map('n', '<Leader>x', function()
local cur_win = vim.api.nvim_get_current_win()
local cur_buf = vim.api.nvim_get_current_buf()
local cur_ft = vim.bo[cur_buf].filetype
local wins = vim.api.nvim_tabpage_list_wins(0)
local non_float = {}
for _, win in ipairs(wins) do
if vim.api.nvim_win_get_config(win).relative == '' then
non_float[#non_float + 1] = win
end
end
local function is_neotree_win(win)
local buf = vim.api.nvim_win_get_buf(win)
return vim.bo[buf].filetype == 'neo-tree'
end
if cur_ft == 'neo-tree' then
if #non_float <= 1 then
vim.cmd 'enew'
return
end
vim.api.nvim_win_close(cur_win, true)
return
end
if #non_float == 2 then
local other = non_float[1] == cur_win and non_float[2] or non_float[1]
if is_neotree_win(other) then
vim.api.nvim_win_close(other, true)
end
end
vim.cmd 'bdelete'
end, { desc = 'Delete buffer' })
-- telescope
map('n', '<Leader>tc', '<cmd>Telescope colorscheme<CR>', { desc = '[T]elescope [C]olorscheme' })

View File

@ -1,3 +1,98 @@
local function titleize(action)
if type(action) ~= 'string' then
return nil
end
if action == '' then
return nil
end
local out = action:gsub('_', ' ')
return out:sub(1, 1):upper() .. out:sub(2)
end
local function action_desc(action)
if type(action) == 'string' then
return titleize(action)
end
if type(action) == 'function' then
return 'Custom action'
end
if type(action) ~= 'table' then
return nil
end
if action.desc then
return action.desc
end
if action.action then
return action_desc(action.action)
end
local is_list = vim.islist or vim.tbl_islist
if is_list and is_list(action) then
local parts = {}
for _, item in ipairs(action) do
local desc = action_desc(item)
if desc then
parts[#parts + 1] = desc
end
end
if #parts > 0 then
return table.concat(parts, ', ')
end
end
return nil
end
local function add_desc_to_picker_keys(opts)
local function apply(keys)
if not keys then
return
end
for _, spec in pairs(keys) do
if type(spec) == 'table' and spec.desc == nil then
local action = spec[1] or spec[2]
local desc = action_desc(action)
if desc then
spec.desc = desc
end
end
end
end
for _, win in pairs(opts.win or {}) do
apply(win.keys)
end
for _, source in pairs(opts.sources or {}) do
if type(source) == 'table' and source.win then
for _, win in pairs(source.win) do
apply(win.keys)
end
end
end
end
local function ensure_dashboard_desc_keymaps()
if vim.g.snacks_dashboard_desc_keymaps then
return
end
vim.g.snacks_dashboard_desc_keymaps = true
local group = vim.api.nvim_create_augroup('snacks_dashboard_desc', { clear = true })
vim.api.nvim_create_autocmd('FileType', {
group = group,
pattern = 'snacks_dashboard',
callback = function(ev)
vim.keymap.set('n', 'q', '<cmd>bd<cr>', { buffer = ev.buf, silent = true, desc = 'Close dashboard' })
local cfg = vim.api.nvim_win_get_config(0)
if cfg and cfg.relative ~= '' then
vim.keymap.set('n', '<esc>', '<cmd>bd<cr>', { buffer = ev.buf, silent = true, desc = 'Close dashboard' })
end
end,
})
end
return {
'folke/snacks.nvim',
priority = 1000,
@ -8,16 +103,104 @@ return {
-- or leave it empty to use the default settings
-- refer to the configuration section below
bigfile = { enabled = true },
dashboard = { enabled = true },
dashboard = {
enabled = true,
config = function()
ensure_dashboard_desc_keymaps()
end,
},
explorer = { enabled = true },
indent = { enabled = true },
input = { enabled = true },
picker = { enabled = true },
notifier = { enabled = true },
picker = {
enabled = true,
config = function(opts)
add_desc_to_picker_keys(opts)
end,
},
notifier = {
enabled = true,
top_down = false,
},
quickfile = { enabled = true },
scope = { enabled = true },
scroll = { enabled = false },
statuscolumn = { enabled = false },
words = { enabled = true },
styles = {
input = {
keys = {
n_esc = {
'<esc>',
{ 'cmp_close', 'cancel' },
mode = 'n',
expr = true,
desc = 'Cancel input',
},
i_esc = {
'<esc>',
{ 'cmp_close', 'stopinsert' },
mode = 'i',
expr = true,
desc = 'Cancel input',
},
i_cr = {
'<cr>',
{ 'cmp_accept', 'confirm' },
mode = { 'i', 'n' },
expr = true,
desc = 'Confirm input',
},
i_tab = {
'<tab>',
{ 'cmp_select_next', 'cmp' },
mode = 'i',
expr = true,
desc = 'Next completion',
},
i_ctrl_w = {
'<c-w>',
'<c-s-w>',
mode = 'i',
expr = true,
desc = 'Delete word',
},
i_up = {
'<up>',
{ 'hist_up' },
mode = { 'i', 'n' },
desc = 'History up',
},
i_down = {
'<down>',
{ 'hist_down' },
mode = { 'i', 'n' },
desc = 'History down',
},
q = { 'q', 'cancel', desc = 'Cancel input' },
},
},
terminal = {
keys = {
q = { 'q', 'hide', desc = 'Hide terminal' },
gf = {
'gf',
function(self)
local f = vim.fn.findfile(vim.fn.expand '<cfile>', '**')
if f == '' then
Snacks.notify.warn 'No file under cursor'
else
self:hide()
vim.schedule(function()
vim.cmd('e ' .. f)
end)
end
end,
desc = 'Open file under cursor',
},
},
},
},
},
}