This commit is contained in:
Manuel
2025-08-25 19:49:05 +02:00
parent aed2435b50
commit f916d78fc2
4 changed files with 114 additions and 9 deletions

View File

@@ -83,3 +83,72 @@ map("n", "tt", function()
local height = math.floor(vim.o.lines / 2)
cmd("belowright split | resize " .. height .. " | terminal")
end, { noremap = true, silent = true })
-- toggle-cmp.lua
local ok, cmp = pcall(require, "cmp")
if not ok then return end
-- initial state (true = autocomplete on)
vim.g.cmp_autocomplete = vim.g.cmp_autocomplete == nil and true or vim.g.cmp_autocomplete
function _G.toggle_cmp_autocomplete()
vim.g.cmp_autocomplete = not vim.g.cmp_autocomplete
if vim.g.cmp_autocomplete then
-- enable automatic completion
cmp.setup {
completion = {
-- typical events to auto-open completion
autocomplete = { cmp.TriggerEvent.TextChanged, cmp.TriggerEvent.InsertEnter }
}
}
print("cmp autocomplete: ON")
else
-- disable automatic completion and close any open menu
cmp.setup { completion = { autocomplete = false } }
pcall(cmp.close)
print("cmp autocomplete: OFF")
end
end
-- mappings
vim.keymap.set("n", "<leader>cc", "<cmd>lua _G.toggle_cmp_autocomplete()<CR>", { noremap = true, silent = true })
vim.keymap.set("i", "<C-\\>", function() _G.toggle_cmp_autocomplete() end, { silent = true })
-- manual trigger (still works when autocomplete is off)
vim.keymap.set("i", "<C-Space>", function() require("cmp").complete() end, { silent = true })
-- quick hide/abort in insert
vim.keymap.set("i", "<C-e>", function() require("cmp").abort() end, { silent = true })
-- zen-mode max-width helper
local M = {}
-- configuration: change these to taste
M.zen_ratio = 0.80 -- try to use 80% of the editor width
M.zen_max = 90 -- but never wider than 100 columns
M.zen_min = 60 -- optional: never narrower than 60 columns
function M.open_zen_with_max()
local cols = vim.o.columns or vim.api.nvim_get_option('columns')
local desired = math.floor(cols * M.zen_ratio)
-- clamp between min and max (optional min)
local width = math.max(M.zen_min, math.min(desired, M.zen_max))
require("zen-mode").toggle({
window = {
width = width,
-- keep your usual window options if you like
options = {
number = false,
relativenumber = false,
},
},
})
end
-- map keys (change mapping as you prefer)
vim.keymap.set("n", "<leader>z", function() M.open_zen_with_max() end, { noremap = true, silent = true })
return M

View File

@@ -187,6 +187,7 @@ local builtin_plugins = {
{ 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' },
{ 'nvim-telescope/telescope.nvim', dependencies = { 'nvim-lua/plenary.nvim' } },
{ 'neovim/nvim-lspconfig' },
{ 'folke/zen-mode.nvim' },
@@ -314,3 +315,33 @@ cmp.setup({
['<CR>'] = require('cmp').mapping.confirm({ select = true }),
})
})
-- zen-mode max-width helper
local M = {}
-- configuration: change these to taste
M.zen_ratio = 0.90 -- try to use 80% of the editor width
M.zen_max = 100 -- but never wider than 100 columns
M.zen_min = 60 -- optional: never narrower than 60 columns
function M.open_zen_with_max()
local cols = vim.o.columns or vim.api.nvim_get_option('columns')
local desired = math.floor(cols * M.zen_ratio)
-- clamp between min and max (optional min)
local width = math.max(M.zen_min, math.min(desired, M.zen_max))
require("zen-mode").toggle({
window = {
width = width,
-- keep your usual window options if you like
options = {
number = false,
relativenumber = false,
},
},
})
end
-- map keys (change mapping as you prefer)
vim.keymap.set("n", "<leader>z", function() M.open_zen_with_max() end, { noremap = true, silent = true })