Compare commits

...

2 commits

Author SHA1 Message Date
168475a988
nvim: Stay centered in zen mode
By default we always stay centered in zen mode, like using a typewriter.
The old zen mode can still be reached with `[sZ` (capital Z).
2025-07-16 20:18:34 +02:00
368a6fcb37
nvim: Add mini.ai textobjects from lazyvim
Shamelessly stolen from http://www.lazyvim.org/plugins/coding#miniai,
allows us to select in/around:

[c]lass, [f]unction, [d]igits, MultiCas[e] words, [g]lobal buffer,
[u]sage of functions (function calls) or the last part of a function
[Usage] and the current code bl[o]ck (loop, conditional or block).

Super useful!
2025-07-16 20:18:34 +02:00
3 changed files with 60 additions and 4 deletions

View file

@ -86,6 +86,7 @@
"rainbow-delimiters.nvim": { "branch": "master", "commit": "1ab18259472d9fe5756750fec722c31bab1712da" },
"render-markdown.nvim": { "branch": "main", "commit": "6d03af10063d5a2fadec3559de5dfa68da7d00ef" },
"smartcolumn.nvim": { "branch": "main", "commit": "d01b99355c7fab13233f48d0f28dc097e68a03f7" },
"stay-centered.nvim": { "branch": "main", "commit": "e1a63ccaf2584e97c0ef8e64f9654c9a80d983f6" },
"stickybuf.nvim": { "branch": "master", "commit": "2160fcd536d81f5fa43f7167dba6634e814e3154" },
"texpresso.vim": { "branch": "main", "commit": "907838c08bbf99ad6bed3c908f1d0551a92ab4e0" },
"todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" },

View file

@ -210,8 +210,45 @@ return {
"echasnovski/mini.nvim",
event = { "InsertEnter", "VeryLazy" },
config = function()
-- manually create lazy loading scenarios
require("mini.ai").setup()
local ai = require("mini.ai")
local function ai_buffer(ai_type)
local start_line, end_line = 1, vim.fn.line("$")
if ai_type == "i" then
-- Skip first and last blank lines for `i` textobject
local first_nonblank, last_nonblank = vim.fn.nextnonblank(start_line), vim.fn.prevnonblank(end_line)
-- Do nothing for buffer with all blanks
if first_nonblank == 0 or last_nonblank == 0 then
return { from = { line = start_line, col = 1 } }
end
start_line, end_line = first_nonblank, last_nonblank
end
local to_col = math.max(vim.fn.getline(end_line):len(), 1)
return { from = { line = start_line, col = 1 }, to = { line = end_line, col = to_col } }
end
ai.setup({
custom_textobjects = {
c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }), -- class
d = { "%f[%d]%d+" }, -- digits
e = { -- single part of MultiCaseWords
{
"%u[%l%d]+%f[^%l%d]",
"%f[%S][%l%d]+%f[^%l%d]",
"%f[%P][%l%d]+%f[^%l%d]",
"^[%l%d]+%f[^%l%d]",
},
"^().*()$",
},
f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }), -- function
g = ai_buffer, -- buffer with or without whitespace
o = ai.gen_spec.treesitter({ -- current 'codeblock'
a = { "@block.outer", "@conditional.outer", "@loop.outer" },
i = { "@block.inner", "@conditional.inner", "@loop.inner" },
}),
u = ai.gen_spec.function_call(), -- function [u]sage
U = ai.gen_spec.function_call({ name_pattern = "[%w_]" }), -- function [U]sage of last dot element
},
})
-- Align tables and other alignable things
require("mini.align").setup({})

View file

@ -33,10 +33,28 @@ local prose_plugs = {
"folke/zen-mode.nvim",
config = true,
cmd = { "ZenMode" },
dependencies = { "folke/twilight.nvim" },
dependencies = { "folke/twilight.nvim", { "arnamak/stay-centered.nvim", opts = { enabled = false } } },
keys = {
{
"[sz",
function()
require("zen-mode").close()
require("stay-centered").disable()
end,
silent = true,
desc = "stop center zen mode",
},
{
"]sz",
function()
require("zen-mode").open()
require("stay-centered").enable()
end,
silent = true,
desc = "start center zen mode",
},
{
"[sZ",
function()
require("zen-mode").close()
end,
@ -44,7 +62,7 @@ local prose_plugs = {
desc = "stop zen mode",
},
{
"]sz",
"]sZ",
function()
require("zen-mode").open()
end,