Compare commits

...

6 commits

15 changed files with 341 additions and 183 deletions

View file

@ -55,6 +55,41 @@ with final.pkgs.lib; let
flash-nvim
which-key-nvim
gitsigns-nvim
# Treesitter
nvim-treesitter-textobjects
nvim-ts-autotag
(nvim-treesitter.withPlugins (
plugins:
with plugins; [
bash
diff
html
gitignore
javascript
jsdoc
json
jsonc
just
lua
luadoc
markdown
markdown_inline
nix
just
printf
python
query
regex
toml
tsx
typescript
vim
vimdoc
xml
yaml
]
))
];
extraPackages = with pkgs; [

View file

@ -1,13 +1,22 @@
---@type {[string]:"azure" | "blue" | "cyan" | "green" | "grey" | "orange" | "purple" | "red" | "yellow"}
return {
buffers = 'cyan',
change = 'cyan',
delete = 'red',
diagnostics = 'green',
explorer = 'yellow',
fold = 'purple',
format = 'purple',
git = 'orange',
go_to = 'cyan',
notifications = 'orange',
replace = 'blue',
search = 'green',
sessions = 'azure',
spell = 'red',
surround = 'purple',
ui = 'green',
visual = 'purple',
window = 'blue',
search = 'green',
git = 'orange',
notifications = 'orange',
sessions = 'azure',
explorer = 'yellow',
yank = 'yellow',
}

View file

@ -1,15 +1,25 @@
return {
bottom = '',
center = '󰘢',
change = '',
char = '󰾹',
comment = '',
dashboard = {
quit = '',
mru = '',
project = '',
},
delete = '󰆴',
diagnostics = {
Error = '',
Warn = '',
Hint = '',
Info = '',
},
dashboard = {
quit = '',
mru = '',
project = '',
},
explorer = '󰙅',
first = '󰘀',
fold = '',
format = '󰉼',
git = {
added = '',
modified = '',
@ -18,11 +28,29 @@ return {
staged = '󰱒',
diff = '󰫙',
},
left = '',
prev = '',
right = '',
next = '',
first = '󰘀',
go_to = '',
indent = {
left = '󰉵',
decrease = '󰉵',
right = '󰉶',
increase = '󰉶',
},
last = '󰘁',
lazygit = '',
left = '',
next = '',
notifications = '󰈸',
prev = '',
registers = '󰅍',
replace = '',
right = '',
sessions = '',
spell = '',
search = '',
top = '',
ui = '󰙵',
undo = '',
visual = '',
word = '',
yank = '',
}

View file

@ -19,6 +19,15 @@ function M.local_require(prefix)
end
end
---Get and format the foreground of a highlight group.
---@param name string The highlight group name to fetch from.
---@return {fg:string}?
function M.fg(name)
local hl = vim.api.nvim_get_hl(0, { name = name, link = false })
return hl and { fg = string.format('#%06x', hl.fg) } or nil
end
---Generates a function that can be used to create which-key mappings.
---@param color string The color to use for the icon.
---@return function

View file

@ -1,23 +0,0 @@
-- https://github.com/folke/lazy.nvim/blob/main/lua/lazy/core/util.lua
---@class lib.lazy.util
local M = {}
---@return string
function M.norm(path)
if path:sub(1, 1) == '~' then
local home = vim.uv.os_homedir() or ''
if home:sub(-1) == '\\' or home:sub(-1) == '/' then
home = home:sub(1, -2)
end
path = home .. path:sub(2)
end
path = path:gsub('\\', '/'):gsub('/+', '/')
return path:sub(-1) == '/' and path:sub(1, -2) or path
end
return M

View file

@ -1,53 +0,0 @@
-- 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

View file

@ -1,32 +0,0 @@
--https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/util/ui.lua
---@class lib.lazyvim.ui
local M = {}
-- Optimized treesitter foldexpr for Neovim >= 0.10.0
function M.foldexpr()
local buf = vim.api.nvim_get_current_buf()
if vim.b[buf].ts_folds == nil then
-- as long as we don't have a filetype, don't bother checking if treesitter
-- is available (it won't be)
if vim.bo[buf].filetype == '' then
return '0'
end
if vim.bo[buf].filetype:find('dashboard') then
vim.b[buf].ts_folds = false
else
vim.b[buf].ts_folds = pcall(vim.treesitter.get_parser, buf)
end
end
return vim.b[buf].ts_folds and vim.treesitter.foldexpr() or '0'
end
---@return {fg?:string}?
function M.fg(name)
local hl = vim.api.nvim_get_hl(0, { name = name, link = false })
local fg = hl and hl.fg or nil
return fg and { fg = string.format('#%06x', fg) } or nil
end
return M

View file

@ -70,7 +70,7 @@ opt.foldcolumn = '1'
opt.foldlevel = 99
opt.foldenable = true
opt.foldmethod = 'expr'
opt.foldexpr = "v:lua.require'lib.lazyvim.ui'.foldtext()"
opt.foldexpr = 'nvim_treesitter#foldexpr()'
opt.foldtext = ''
-- Always keep 4 lines above/below cursor.

View file

@ -21,41 +21,20 @@ return {
require('lz.n').trigger_load('mini.icons')
end,
after = function()
local icons = require('icons')
local colors = require('colors')
local i = require('icons')
local c = require('colors')
require('which-key').setup({
preset = 'modern',
spec = {
{
mode = { 'n', 'v' },
{
'<LEADER>',
group = 'leader',
icon = { icon = '', color = 'green' },
},
{ '<LEADER><TAB>', group = 'tabs' },
{ '<LEADER>c', group = 'code' },
{ '<LEADER>f', group = 'file/find' },
{ '<LEADER>g', group = 'git' },
{ '<LEADER>gh', group = 'hunks' },
{ '<LEADER>n', group = 'notifications' },
{ '<LEADER>q', group = 'quit/session' },
{ '<LEADER>s', group = 'search' },
{
'<LEADER>u',
group = 'ui',
icon = { icon = '󰙵 ', color = colors.ui },
},
{
'<LEADER>x',
group = 'diagnostics/quickfix',
icon = { icon = '󱖫 ', color = colors.diagnostics },
},
{ '[', group = 'previous' },
{ ']', group = 'next' },
{ 'g', group = 'goto' },
{
'gs',
group = 'surround',
icon = { icon = '󰅲', color = colors.surround },
},
{ 'z', group = 'fold' },
{
'<LEADER>b',
group = 'buffer',
@ -63,6 +42,15 @@ return {
return require('which-key.extras').expand.buf()
end,
},
{ '<LEADER>c', group = 'code' },
{ '<LEADER>f', group = 'file/find' },
{ '<LEADER>g', group = 'git' },
{ '<LEADER>gh', group = 'hunks' },
{ '<LEADER>n', group = 'notifications' },
{ '<LEADER>q', group = 'quit/session' },
{ '<LEADER>s', group = 'search' },
{ '<LEADER>u', group = 'ui', icon = { icon = i.ui, color = c.ui } },
{ '<LEADER>ur', icon = { icon = '', color = c.ui } },
{
'<LEADER>w',
group = 'windows',
@ -70,10 +58,114 @@ return {
return require('which-key.extras').expand.win()
end,
},
{ 'gx', desc = 'open with system app' },
{ '<LEADER>ur', icon = { icon = '', color = colors.ui } },
{ '<LEADER>|', icon = { icon = '' } },
{ '<LEADER>-', icon = { icon = '' } },
{
'<LEADER>x',
group = 'diagnostics/quickfix',
icon = { icon = '󱖫 ', color = c.diagnostics },
},
{ '<LEADER>|', icon = '' },
{ '<LEADER>-', icon = '' },
{ '0', desc = 'start of line', icon = i.first },
{ 'b', desc = 'previous word', icon = i.word },
{ 'B', desc = 'previous WORD', icon = i.word },
{ 'c', desc = 'change' },
{ 'd', desc = 'delete' },
{ 'e', desc = 'next end of word', icon = i.word },
{ 'E', desc = 'next end of WORD', icon = i.word },
{ 'f', desc = 'find next char' },
{ 'F', desc = 'find previous char' },
{ 'g', group = 'goto', icon = { icon = i.go_to, color = c.go_to } },
{ 'gc', group = 'toggle comment' },
{ 'ge', desc = 'previous end of word', icon = i.word },
{ 'gf', desc = 'file under cursor' },
{ 'gg', desc = 'first line', icon = i.first },
{ 'gi', desc = 'last insert' },
{ 'gn', desc = 'search forward & select' },
{ 'gN', desc = 'search backward & select' },
{ 'gO', desc = 'document symbols', icon = '󰊕' },
{ 'gt', desc = 'next tab page' },
{ 'gT', desc = 'previous tab page' },
{ 'gu', desc = 'make lowercase', icon = '󰬵' },
{ 'gU', desc = 'make uppercase', icon = '󰬶' },
{ 'gv', desc = 'last visual selection' },
{ 'w', desc = 'format' },
{
'gs',
group = 'surround',
icon = { icon = '󰅲', color = c.surround },
},
{ 'gx', desc = 'open with system app', icon = '󰏋' },
{ 'g%', desc = 'cycle backward through results' },
{ 'g~', desc = 'toggle case' },
{ 'G', desc = 'last line', icon = i.last },
{ 'M', desc = 'middle line of window', icon = i.center },
{ 'r', desc = 'replace' },
{ 't', desc = 'find before next char' },
{ 'T', desc = 'find before previous char' },
{ 'v', desc = 'visual' },
{ 'V', desc = 'visual line' },
{ 'w', desc = 'next word', icon = i.word },
{ 'W', desc = 'next WORD', icon = i.word },
{ 'y', desc = 'yank' },
{ 'Y', desc = 'yank to end of line' },
{ 'z', group = 'fold/scroll/spell', icon = '' },
{ 'za', desc = 'toggle fold under cursor' },
{ 'zA', desc = 'toggle all folds under cursor' },
{ 'zb', desc = 'bottom this line', icon = i.bottom },
{ 'zc', desc = 'close fold under cursor' },
{ 'zC', desc = 'close all fold under cursor' },
{ 'zd', desc = 'delete fold under cursor' },
{ 'zD', desc = 'delete all folds under cursor' },
{ 'ze', desc = 'right this line', icon = i.right },
{ 'zE', desc = 'delete all folds in file' },
{ 'zf', desc = 'create fold' },
{ 'zg', desc = 'mark word as correctly spelled' },
{ 'zH', desc = 'half screen to the left', icon = i.left },
{ 'zi', desc = 'toggle folding' },
{ 'zL', desc = 'half screen to the right', icon = i.right },
{ 'zm', desc = 'fold more' },
{ 'zM', desc = 'close all folds' },
{ 'zo', desc = 'open fold under cursor' },
{ 'zO', desc = 'open all folds under cursor' },
{ 'zr', desc = 'fold less' },
{ 'zR', desc = 'open all folds' },
{ 'zs', desc = 'left this line', icon = i.left },
{ 'zt', desc = 'top this line', icon = i.top },
{ 'zv', desc = 'show cursor line' },
{ 'zw', desc = 'mark word as mispelled' },
{ 'zx', desc = 'update folds' },
{ 'zz', desc = 'center this line', icon = i.center },
{ 'z<CR>', desc = 'top this line', icon = i.top },
{ 'z=', group = 'spelling suggestions' },
{ '[', group = 'previous', icon = i.prev },
{ ']', group = 'next', icon = i.next },
{ '!', desc = 'run program', icon = '' },
{ '$', desc = 'end of line', icon = i.last },
{ '%', desc = 'matching (){}[]', icon = '󰅪' },
{ '&', desc = 'repeat last subsitute' },
{ ',', desc = 'repeat last char search (backwards)' },
{ '/', desc = 'search forward' },
{ ';', desc = 'repeat last char search' },
{ '<', desc = 'indent decrease', icon = i.indent.decrease },
{ '>', desc = 'indent increase', icon = i.indent.increase },
{ '?', desc = 'search backwards' },
{ '^', desc = 'first char of line', icon = i.first },
{ '_', desc = 'first char of line', icon = i.first },
{ '{', desc = 'previous empty line', icon = i.prev },
{ '}', desc = 'next empty line', icon = i.next },
{ '~', desc = 'toggle case' },
{
'<C-L>',
desc = 'clear & redraw',
icon = { icon = '', color = 'red' },
},
},
{
mode = { 'n', 'i' },
@ -88,42 +180,59 @@ return {
hidden = true,
{ 'j' },
{ 'k' },
},
{
mode = { 'v' },
{ '<', icon = { icon = '󰉵' } },
{ '>', icon = { icon = '󰉶' } },
{ 'h' },
{ 'l' },
{ '<PLUG>' },
},
},
icons = {
rules = {
{ pattern = 'explorer', icon = '󰙅', color = colors.explorer },
{ pattern = 'lazygit', icon = '' },
{ pattern = 'comment', icon = '' },
{ pattern = 'buffer', color = colors.buffer },
{
pattern = 'notification',
icon = '󰈸',
color = colors.notifications,
},
{ pattern = 'message', icon = '󰈸', color = colors.notifications },
{ pattern = 'session', icon = '', color = colors.sessions },
{ pattern = 'hunk', color = colors.git },
{ pattern = 'fold', icon = i.fold, color = c.fold },
{ pattern = 'buffer', color = c.buffer },
{ pattern = 'change', icon = i.change, color = c.change },
{ pattern = 'comment', icon = i.comment },
{ pattern = 'delete', icon = i.delete, color = c.delete },
{
pattern = 'diagnostic',
icon = icons.diagnostics.Info,
icon = i.diagnostics.Info,
hl = 'DiagnosticInfo',
},
{
pattern = 'error',
icon = icons.diagnostics.Error,
icon = i.diagnostics.Error,
hl = 'DiagnosticError',
},
{
pattern = 'explorer',
icon = i.explorer,
color = c.explorer,
},
{ pattern = 'format', icon = i.format, color = c.format },
{ pattern = 'hunk', color = c.git },
{ pattern = 'lazygit', icon = i.git, color = c.git },
{
pattern = 'message',
icon = i.notifications,
color = c.notifications,
},
{
pattern = 'notification',
icon = i.notifications,
color = c.notifications,
},
{ pattern = 'registers', icon = i.registers, color = c.yank },
{ pattern = 'replace', icon = i.replace, colors = c.replace },
{ pattern = 'session', icon = i.sessions, color = c.sessions },
{ pattern = 'spell', icon = i.spell, color = c.spell },
{ pattern = 'subsitute', icon = i.search, color = c.search },
{ pattern = 'visual', icon = i.visual, color = c.visual },
{
pattern = ' warning',
icon = icons.diagnostics.Warning,
icon = i.diagnostics.Warning,
hl = 'DiagnosticWarn',
},
{ pattern = 'yank', icon = i.yank, color = c.yank },
},
},
})

View file

@ -0,0 +1,7 @@
local req = MarleyVim.local_require('plugins.treesitter')
return {
req('nvim-treesitter-textobjects'),
req('nvim-treesitter'),
req('nvim-ts-autotag'),
}

View file

@ -0,0 +1,7 @@
return {
'nvim-treesitter-textobjects',
event = 'DeferredUIEnter',
before = function()
require('lz.n').trigger_load('nvim-treesitter')
end,
}

View file

@ -0,0 +1,56 @@
return {
event = { 'BufReadPost', 'BufWritePost', 'BufNewFile', 'DeferredUIEnter' },
keys = {
{ '<C-space>', desc = 'increment selection' },
{ '<BS>', desc = 'decrement selection', mode = 'x' },
},
before = function()
require('lz.n').trigger_load('which-key.nvim')
end,
after = function()
---@diagnostic disable-next-line: missing-fields
require('nvim-treesitter.configs').setup({
highlight = { enable = true },
indent = { enable = true },
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<C-space>',
node_incremental = '<C-space>',
scope_incremental = false,
node_decremental = '<BS>',
},
},
textobjects = {
move = {
enable = true,
goto_next_start = {
[']f'] = '@function.outer',
[']c'] = '@class.outer',
[']a'] = '@parameter.inner',
},
goto_next_end = {
[']F'] = '@function.outer',
[']C'] = '@class.outer',
[']A'] = '@parameter.inner',
},
goto_previous_start = {
['[f'] = '@function.outer',
['[c'] = '@class.outer',
['[a'] = '@parameter.inner',
},
goto_previous_end = {
['[F'] = '@function.outer',
['[C'] = '@class.outer',
['[A'] = '@parameter.inner',
},
},
},
})
require('which-key').add({
{ '<BS>', desc = 'decrement selection', mode = 'x' },
{ '<C-space>', desc = 'increment selection', mode = { 'x', 'n' } },
})
end,
}

View file

@ -0,0 +1,11 @@
return {
'nvim-ts-autotag',
event = { 'BufReadPost', 'BufWritePost', 'BufNewFile' },
after = function()
require('nvim-ts-autotag').setup({
opts = {
enable_close_on_slash = true,
},
})
end,
}

View file

@ -20,7 +20,6 @@ return {
end
end,
after = function()
local lazyvim_ui = require('lib.lazyvim.ui')
local icons = require('icons')
vim.o.laststatus = vim.g.lualine_laststatus
@ -84,7 +83,7 @@ return {
.has()
end,
color = function()
return lazyvim_ui.fg('Statement')
return MarleyVim.fg('Statement')
end,
},
@ -96,7 +95,7 @@ return {
return package.loaded['dap'] and require('dap').status ~= ''
end,
color = function()
return lazyvim_ui.fg('debug')
return MarleyVim.fg('debug')
end,
},

View file

@ -1,6 +1,5 @@
-- Snacks needs to be loaded very early, so it gets its own special file.
local set = vim.keymap.set
local lazyvim_format = require('lib.lazyvim.format')
require('snacks').setup({
bigfile = { enabled = true },
@ -41,9 +40,6 @@ end, { desc = 'delete other buffers' })
local toggle = Snacks.toggle
lazyvim_format.snacks_toggle():map('<LEADER>uf')
lazyvim_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')