From ab6244ecbe88fd2d95bab2eb519aab82b2ebd3f4 Mon Sep 17 00:00:00 2001 From: Job79 Date: Thu, 3 Sep 2026 19:17:30 +0200 Subject: [PATCH] refactor: simplify --- lua/terminal.lua | 14 ++++++-------- plugin/10_options.lua | 15 --------------- plugin/20_keymaps.lua | 36 +++++++++++------------------------- plugin/40_plugins.lua | 17 ++++++++++++----- 4 files changed, 29 insertions(+), 53 deletions(-) diff --git a/lua/terminal.lua b/lua/terminal.lua index c49f77b..62052e5 100644 --- a/lua/terminal.lua +++ b/lua/terminal.lua @@ -3,21 +3,19 @@ local M = {} --- Opens a TUI application in a simple centered floating window. function M.open_terminal_app(cmd) local buf = vim.api.nvim_create_buf(false, true) + local w, h = math.floor(vim.o.columns * 0.95), math.floor(vim.o.lines * 0.95) - -- Open a centered floating window (80% screen width/height) local win = vim.api.nvim_open_win(buf, true, { relative = "editor", - width = math.floor(vim.o.columns * 0.95), - height = math.floor(vim.o.lines * 0.95), - row = math.floor(vim.o.lines * 0.025), - col = math.floor(vim.o.columns * 0.025), + width = w, + height = h, + row = math.floor((vim.o.lines - h) / 2), + col = math.floor((vim.o.columns - w) / 2), border = "rounded", }) vim.fn.termopen(cmd, { - on_exit = function() - pcall(vim.api.nvim_win_close, win, true) - end, + on_exit = function() pcall(vim.api.nvim_win_close, win, true) end, }) end diff --git a/plugin/10_options.lua b/plugin/10_options.lua index b1316b2..fe65c1f 100644 --- a/plugin/10_options.lua +++ b/plugin/10_options.lua @@ -38,9 +38,6 @@ vim.o.tabstop = 2 -- Show tab as this number of spaces vim.o.virtualedit = 'block' -- Allow going past end of line in blockwise mode vim.opt.autoread = true -- Do not prompt to reread files on update --- Pattern for a start of numbered list (used in `gw`). -vim.o.formatlistpat = [[^\s*[0-9\-\+\*]\+[\.\)]*\s\+]] - -- Built-in completion vim.o.complete = '.,w,b,kspell' -- Use less sources vim.o.completeopt = 'menuone,noselect,fuzzy,nosort' -- Use custom behavior @@ -71,16 +68,4 @@ Config.later(function() }, update_in_insert = false, }) - - local dap_signs = { - DapBreakpoint = { text = '', texthl = 'DapBreakpoint', linehl = '', numhl = '' }, - DapBreakpointCondition = { text = '', texthl = 'DapBreakpointCondition', linehl = '', numhl = '' }, - DapLogPoint = { text = '', texthl = 'DapLogPoint', linehl = '', numhl = '' }, - DapStopped = { text = '', texthl = 'DapStopped', linehl = 'DapStoppedLine', numhl = '' }, - DapBreakpointRejected = { text = '', texthl = 'DapBreakpointRejected', linehl = '', numhl = '' }, - } - - for name, sign in pairs(dap_signs) do - vim.fn.sign_define(name, sign) - end end) diff --git a/plugin/20_keymaps.lua b/plugin/20_keymaps.lua index 2624e46..0e03817 100644 --- a/plugin/20_keymaps.lua +++ b/plugin/20_keymaps.lua @@ -14,32 +14,18 @@ Config.leader_group_clues = { } -- Helpers ===================================================================== -local function lazy_wrap(name, action) - return function() - if Config["setup_" .. name] then Config["setup_" .. name]() end - action() - end +local function map(mode, lhs, rhs, desc, plugin) + local final_rhs = plugin and function() + if Config["setup_" .. plugin] then Config["setup_" .. plugin]() end + rhs() + end or rhs + vim.keymap.set(mode, lhs, final_rhs, { desc = desc }) end -local nmap = function(lhs, rhs, desc, plugin) - local final_rhs = plugin and lazy_wrap(plugin, rhs) or rhs - vim.keymap.set("n", lhs, final_rhs, { desc = desc }) -end - -local tmap = function(lhs, rhs, desc, plugin) - local final_rhs = plugin and lazy_wrap(plugin, rhs) or rhs - vim.keymap.set("t", lhs, final_rhs, { desc = desc }) -end - -local nmap_leader = function(suffix, rhs, desc, plugin) - local final_rhs = plugin and lazy_wrap(plugin, rhs) or rhs - vim.keymap.set("n", "" .. suffix, final_rhs, { desc = desc }) -end - -local xmap_leader = function(suffix, rhs, desc, plugin) - local final_rhs = plugin and lazy_wrap(plugin, rhs) or rhs - vim.keymap.set("x", "" .. suffix, final_rhs, { desc = desc }) -end +local nmap = function(lhs, rhs, desc, plugin) map("n", lhs, rhs, desc, plugin) end +local tmap = function(lhs, rhs, desc, plugin) map("t", lhs, rhs, desc, plugin) end +local nmap_leader = function(suffix, rhs, desc, plugin) map("n", "" .. suffix, rhs, desc, plugin) end +local xmap_leader = function(suffix, rhs, desc, plugin) map("x", "" .. suffix, rhs, desc, plugin) end -- Buffers ===================================================================== nmap_leader("bd", function() pcall(vim.cmd, "bdelete") end, "Delete") @@ -122,7 +108,7 @@ nmap_leader("sw", function() MiniSessions.write() end, "Write current") -- Terminal ==================================================================== nmap_leader("tT", function() vim.cmd("horizontal term") end, "Terminal (horizontal)") nmap_leader("tt", function() vim.cmd("vertical term") end, "Terminal (vertical)") -nmap_leader("tc", function() vim.cmd("vertical term claude") end, "Terminal (vertical)") +nmap_leader("tc", function() vim.cmd("vertical term claude") end, "Claude") nmap_leader("tg", function() require("terminal").open_terminal_app("lazygit") end, "LazyGit") nmap_leader("ts", function() require("terminal").open_terminal_app("lazysql") end, "LazySQL") diff --git a/plugin/40_plugins.lua b/plugin/40_plugins.lua index aa0de1a..7ad4fd8 100644 --- a/plugin/40_plugins.lua +++ b/plugin/40_plugins.lua @@ -83,12 +83,19 @@ function Config.setup_dap() Config.setup_dap = nil vim.pack.add({ "https://github.com/mfussenegger/nvim-dap" }) - local dap = require("dap") - dap.adapters.go = { - type = "server", - host = "127.0.0.1", - port = "${port}", + local dap_signs = { + DapBreakpoint = { text = '', texthl = 'DapBreakpoint' }, + DapBreakpointCondition = { text = '', texthl = 'DapBreakpointCondition' }, + DapLogPoint = { text = '', texthl = 'DapLogPoint' }, + DapStopped = { text = '', texthl = 'DapStopped', linehl = 'DapStoppedLine' }, + DapBreakpointRejected = { text = '', texthl = 'DapBreakpointRejected' }, } + for name, sign in pairs(dap_signs) do + vim.fn.sign_define(name, sign) + end + + local dap = require("dap") + dap.adapters.go = { type = "server", host = "127.0.0.1", port = "${port}" } end -- Kulala ======================================================================