WIP: Snacks.nvim
This commit is contained in:
parent
cebc683566
commit
6458a3e392
4 changed files with 104 additions and 0 deletions
|
@ -28,6 +28,8 @@ with final.pkgs.lib; let
|
|||
all-plugins = with pkgs.vimPlugins; [
|
||||
# bleeding-edge plugins from flake inputs
|
||||
# (mkNvimPlugin inputs.wf-nvim "wf.nvim") # (example) keymap hints
|
||||
lz-n
|
||||
snacks-nvim
|
||||
];
|
||||
|
||||
extraPackages = with pkgs; [
|
||||
|
|
|
@ -6,3 +6,7 @@ vim.g.sqlite_clib_path = require('luv').os_getenv('LIBSQLITE')
|
|||
|
||||
require('options')
|
||||
require('keymaps')
|
||||
|
||||
require('snacks-nvim')
|
||||
|
||||
-- require('lz.n').load('plugins')
|
||||
|
|
53
nvim/lua/lib/lazyvim/format.lua
Normal file
53
nvim/lua/lib/lazyvim/format.lua
Normal file
|
@ -0,0 +1,53 @@
|
|||
-- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/util/format.lua
|
||||
|
||||
---@class lib.lazyvim.format
|
||||
local M = {}
|
||||
|
||||
---@param buf? number The buffer to enable for
|
||||
function M.enabled(buf)
|
||||
buf = (buf == nil or buf == 0) and vim.api.nvim_get_current_buf() or buf
|
||||
local gaf = vim.g.autoformat
|
||||
local baf = vim.b[buf].autoformat
|
||||
|
||||
-- If the buffer has a local value, use that.
|
||||
if baf ~= nil then
|
||||
return baf
|
||||
end
|
||||
|
||||
-- Otherwise use the global value if set, or true by default.
|
||||
return gaf == nil or gaf
|
||||
end
|
||||
|
||||
---@param enable? boolean Whether to enable or disable
|
||||
---@param buf? boolean Whether to enable for current buffer only
|
||||
function M.enable(enable, buf)
|
||||
if enable == nil then
|
||||
enable = true
|
||||
end
|
||||
|
||||
if buf then
|
||||
vim.b.autoformat = enable
|
||||
else
|
||||
vim.g.autoformat = enable
|
||||
vim.b.autoformat = nil
|
||||
end
|
||||
end
|
||||
|
||||
---@param buf? boolean Whether to toggle for current buffer only
|
||||
function M.snacks_toggle(buf)
|
||||
return Snacks.toggle({
|
||||
name = 'auto format (' .. (buf and 'buffer' or 'global') .. ')',
|
||||
get = function()
|
||||
if not buf then
|
||||
return vim.g.autoformat == nil or vim.g.autoformat
|
||||
end
|
||||
|
||||
return M.enabled()
|
||||
end,
|
||||
set = function(state)
|
||||
M.enable(state, buf)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
45
nvim/lua/snacks-nvim.lua
Normal file
45
nvim/lua/snacks-nvim.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
-- Snacks needs to be loaded very early, so it gets its own special file.
|
||||
local set = vim.keymap.set
|
||||
local format = require('lib.lazyvim.format')
|
||||
|
||||
require('snacks').setup({
|
||||
bigfile = { enabled = true },
|
||||
dashboard = { enabled = true },
|
||||
})
|
||||
|
||||
-- Buffers -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
set({ 'n' }, '<LEADER>bd', function()
|
||||
Snacks.bufdelete()
|
||||
end, { desc = 'Delete buffer' })
|
||||
|
||||
set({ 'n' }, '<LEADER>bo', function()
|
||||
Snacks.bufdelete.other()
|
||||
end, { desc = 'Delete other buffers' })
|
||||
|
||||
-- Toggles -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
local toggle = Snacks.toggle
|
||||
|
||||
format.snacks_toggle():map('<LEADER>uf')
|
||||
format.snacks_toggle(true):map('<LEADER>uF') -- current buffer only
|
||||
|
||||
toggle.option('spell', { name = 'spelling' }):map('<LEADER>us')
|
||||
toggle.option('wrap', { name = 'wrap' }):map('<LEADER>uw')
|
||||
|
||||
toggle.option('relativenumber', { name = 'relative number' }):map('<LEADER>uL')
|
||||
toggle.line_number():map('<LEADER>ul')
|
||||
|
||||
toggle.diagnostics():map('<LEADER>ud')
|
||||
|
||||
toggle
|
||||
.option(
|
||||
'conceallevel',
|
||||
{ off = 0, on = vim.o.conceallevel > 0 and vim.o.conceallevel or 2 }
|
||||
)
|
||||
:map('<LEADER>uc')
|
||||
|
||||
-- LazyGit -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
set({ 'n' }, '<LEADER>gg', function()
|
||||
Snacks.lazygit()
|
||||
end, { desc = 'Lazygit' })
|
Loading…
Reference in a new issue