From a0bd84df02ce235123dfc939327e8bd33dffdd7e Mon Sep 17 00:00:00 2001 From: Elvis Claros Castro Date: Sat, 27 Jun 2026 22:48:15 -0300 Subject: Remplazando y eliminando plugins a favor de cosas nativas. --- lua/config/autocmds.lua | 52 +++++++++++++++++++++++++++++++++++++++++ lua/config/direnv.lua | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ lua/config/init.lua | 3 +++ lua/config/keymaps.lua | 42 +++++++++++++++++++++++++++++++++ lua/config/usercmds.lua | 15 ++++++++++++ lua/config/worktree.lua | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 233 insertions(+) create mode 100644 lua/config/direnv.lua create mode 100644 lua/config/worktree.lua (limited to 'lua/config') diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index f9ce4da..ffb5d57 100644 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -90,6 +90,24 @@ local function augroup(name) return vim.api.nvim_create_augroup("my_lazyvim_" .. name, { clear = true }) end +vim.api.nvim_create_autocmd("FileType", { + group = augroup "disable_treesitter_special_buffers", + pattern = { "oil", "snacks_notif" }, + callback = function(event) + pcall(vim.treesitter.stop, event.buf) + end, +}) + +-- Auto-ajustar la altura del quickfix a su contenido (reemplaza nvim-bqf auto_resize_height) +vim.api.nvim_create_autocmd("FileType", { + group = augroup "qf_autoresize", + pattern = "qf", + callback = function() + local height = math.max(1, math.min(10, vim.fn.line "$")) + vim.cmd("resize " .. height) + end, +}) + -- Set filetype for .env and .env.* files vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { group = augroup "env_filetype", @@ -125,3 +143,37 @@ vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { vim.opt_local.filetype = "embedded_template" end, }) + +vim.api.nvim_create_autocmd("User", { + pattern = { + "CodeCompanionToolApprovalRequested", + "CodeCompanionChatDone", + }, + callback = function(args) + local event = args.match + + local messages = { + CodeCompanionToolApprovalRequested = "Aprobación requerida", + CodeCompanionChatDone = "Respuesta lista", + } + + local msg = messages[event] or event + vim.fn.jobstart({ "notify-send", "-a", "CodeCompanion", "CodeCompanion", msg }) + end, +}) + + + +-- vim.api.nvim_create_autocmd("User", { +-- pattern = "CodeCompanion*", +-- callback = function(args) +-- local event = args.match +-- local line = os.date("%H:%M:%S") .. " " .. event .. "\n" +-- +-- local f = io.open("/tmp/codecompanionEvents.txt", "a") +-- if f then +-- f:write(line) +-- f:close() +-- end +-- end, +-- }) diff --git a/lua/config/direnv.lua b/lua/config/direnv.lua new file mode 100644 index 0000000..bc89e33 --- /dev/null +++ b/lua/config/direnv.lua @@ -0,0 +1,62 @@ +-- Integración nativa con direnv (reemplaza direnv/direnv.vim) +-- `direnv export json` emite el diff de variables a aplicar para el cwd actual; +-- las variables a eliminar llegan como null (vim.NIL). +local M = {} + +local function apply(env) + if type(env) ~= "table" then + return + end + for k, v in pairs(env) do + if v == vim.NIL then + vim.env[k] = nil + else + vim.env[k] = v + end + end +end + +local function load(sync) + if vim.fn.executable("direnv") == 0 then + return + end + if sync then + -- Carga inicial sincrónica: el entorno debe estar listo antes de los LSP. + local out = vim.fn.system({ "direnv", "export", "json" }) + if vim.v.shell_error ~= 0 or vim.trim(out) == "" then + return + end + local ok, env = pcall(vim.json.decode, out) + if ok then + apply(env) + end + else + vim.system({ "direnv", "export", "json" }, { text = true }, function(obj) + if obj.code ~= 0 then + return + end + local out = vim.trim(obj.stdout or "") + if out == "" then + return + end + local ok, env = pcall(vim.json.decode, out) + if ok then + vim.schedule(function() + apply(env) + end) + end + end) + end +end + +function M.setup() + vim.api.nvim_create_autocmd("DirChanged", { + group = vim.api.nvim_create_augroup("direnv", { clear = true }), + callback = function() + load(false) + end, + }) + load(true) +end + +return M diff --git a/lua/config/init.lua b/lua/config/init.lua index ee1c549..5da196b 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -19,6 +19,9 @@ if vim.fn.has "termguicolors" == 1 then end -- ===================================================== +-- Cargar entorno de direnv temprano (reemplaza direnv/direnv.vim) +require("config.direnv").setup() + -- autocmds and keymaps can wait to load vim.api.nvim_create_autocmd("User", { group = vim.api.nvim_create_augroup("LazyVim", { clear = true }), diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index 3b20175..c1e126e 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -32,6 +32,48 @@ map("n", "", ":cprevzz", { desc = "Goes to the previous item in the qui -- map("n", "o", ":lprevzz") map("n", "cc", ":cclose", { desc = "Close the quick fix list" }) +-- Toggle de diagnósticos en quickfix (reemplaza trouble.nvim) +map("n", "t", function() + local qf_open = false + for _, win in ipairs(vim.fn.getwininfo()) do + if win.quickfix == 1 then + qf_open = true + end + end + if qf_open then + vim.cmd "cclose" + else + vim.diagnostic.setqflist() + end +end, { desc = "Toggle diagnostics quickfix list" }) + +-- Navegación entre referencias del símbolo bajo el cursor (snacks.words; reemplaza vim-illuminate) +map("n", "]r", function() + Snacks.words.jump(1, true) +end, { desc = "Next Reference" }) +map("n", "[r", function() + Snacks.words.jump(-1, true) +end, { desc = "Previous Reference" }) + +-- Modo sin distracciones (reemplaza zen-mode.nvim) +map("n", "cz", function() + Snacks.zen() +end, { desc = "Distraction Free Mode" }) + +-- Git worktrees (reemplaza git-worktree.nvim) +map("n", "gt", function() + require("config.worktree").switch() +end, { desc = "Git Worktree switch" }) +map("n", "gn", function() + require("config.worktree").create() +end, { desc = "Git Worktree new branch" }) + +-- Redimensionar ventanas (reemplaza smart-splits.nvim) +map("n", "", "vertical resize -3", { desc = "Resize window: narrower" }) +map("n", "", "vertical resize +3", { desc = "Resize window: wider" }) +map("n", "", "resize +3", { desc = "Resize window: taller" }) +map("n", "", "resize -3", { desc = "Resize window: shorter" }) + map("n", "tc", ":TSContextToggle", { desc = "Toggle treesitter context" }) -- tabulation diff --git a/lua/config/usercmds.lua b/lua/config/usercmds.lua index e69de29..c9cf9f3 100644 --- a/lua/config/usercmds.lua +++ b/lua/config/usercmds.lua @@ -0,0 +1,15 @@ +-- Alternar la columna de color (reemplaza ecthelionvi/NeoColumn.nvim) +vim.api.nvim_create_user_command("ToggleColorColumn", function() + vim.opt_local.colorcolumn = vim.wo.colorcolumn == "" and "80" or "" +end, { desc = "Alternar colorcolumn (80)" }) + +-- Atenuar el código fuera del scope (reemplaza twilight.nvim con snacks.dim) +local dim_on = false +vim.api.nvim_create_user_command("Twilight", function() + dim_on = not dim_on + if dim_on then + Snacks.dim.enable() + else + Snacks.dim.disable() + end +end, { desc = "Toggle dim del scope (snacks)" }) diff --git a/lua/config/worktree.lua b/lua/config/worktree.lua new file mode 100644 index 0000000..dd4e837 --- /dev/null +++ b/lua/config/worktree.lua @@ -0,0 +1,59 @@ +-- Git worktrees nativos vía `git` + vim.ui (reemplaza ThePrimeagen/git-worktree.nvim). +-- vim.ui.select/input los provee Snacks, así que se elimina además una dependencia de telescope. +local M = {} + +local function git(args) + local res = vim.system(vim.list_extend({ "git" }, args), { text = true }):wait() + return res.code == 0, vim.trim(res.stdout or ""), vim.trim(res.stderr or "") +end + +function M.switch() + local ok, out = git { "worktree", "list", "--porcelain" } + if not ok then + vim.notify("No es un repositorio git con worktrees", vim.log.levels.WARN) + return + end + local trees = {} + for path in out:gmatch "worktree (.-)\n" do + table.insert(trees, path) + end + -- el último no termina en \n + local last = out:match "worktree ([^\n]+)$" + if last then + table.insert(trees, last) + end + if #trees == 0 then + vim.notify("Sin worktrees", vim.log.levels.WARN) + return + end + vim.ui.select(trees, { prompt = "Cambiar a worktree" }, function(choice) + if not choice then + return + end + vim.cmd("cd " .. vim.fn.fnameescape(choice)) + vim.notify("Worktree: " .. choice) + end) +end + +function M.create() + vim.ui.input({ prompt = "Nueva rama/worktree: " }, function(name) + if not name or name == "" then + return + end + local ok, root = git { "rev-parse", "--show-toplevel" } + if not ok then + vim.notify("No es un repositorio git", vim.log.levels.WARN) + return + end + local path = vim.fn.fnamemodify(root, ":h") .. "/" .. name + local cok, _, cerr = git { "worktree", "add", path, "-b", name } + if not cok then + vim.notify("Error al crear worktree: " .. cerr, vim.log.levels.ERROR) + return + end + vim.cmd("cd " .. vim.fn.fnameescape(path)) + vim.notify("Worktree creado: " .. path) + end) +end + +return M -- cgit v1.2.3