refactor: simplify
This commit is contained in:
+6
-8
@@ -3,21 +3,19 @@ local M = {}
|
|||||||
--- Opens a TUI application in a simple centered floating window.
|
--- Opens a TUI application in a simple centered floating window.
|
||||||
function M.open_terminal_app(cmd)
|
function M.open_terminal_app(cmd)
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
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, {
|
local win = vim.api.nvim_open_win(buf, true, {
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
width = math.floor(vim.o.columns * 0.95),
|
width = w,
|
||||||
height = math.floor(vim.o.lines * 0.95),
|
height = h,
|
||||||
row = math.floor(vim.o.lines * 0.025),
|
row = math.floor((vim.o.lines - h) / 2),
|
||||||
col = math.floor(vim.o.columns * 0.025),
|
col = math.floor((vim.o.columns - w) / 2),
|
||||||
border = "rounded",
|
border = "rounded",
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.fn.termopen(cmd, {
|
vim.fn.termopen(cmd, {
|
||||||
on_exit = function()
|
on_exit = function() pcall(vim.api.nvim_win_close, win, true) end,
|
||||||
pcall(vim.api.nvim_win_close, win, true)
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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.o.virtualedit = 'block' -- Allow going past end of line in blockwise mode
|
||||||
vim.opt.autoread = true -- Do not prompt to reread files on update
|
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
|
-- Built-in completion
|
||||||
vim.o.complete = '.,w,b,kspell' -- Use less sources
|
vim.o.complete = '.,w,b,kspell' -- Use less sources
|
||||||
vim.o.completeopt = 'menuone,noselect,fuzzy,nosort' -- Use custom behavior
|
vim.o.completeopt = 'menuone,noselect,fuzzy,nosort' -- Use custom behavior
|
||||||
@@ -71,16 +68,4 @@ Config.later(function()
|
|||||||
},
|
},
|
||||||
update_in_insert = false,
|
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)
|
end)
|
||||||
|
|||||||
+11
-25
@@ -14,32 +14,18 @@ Config.leader_group_clues = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- Helpers =====================================================================
|
-- Helpers =====================================================================
|
||||||
local function lazy_wrap(name, action)
|
local function map(mode, lhs, rhs, desc, plugin)
|
||||||
return function()
|
local final_rhs = plugin and function()
|
||||||
if Config["setup_" .. name] then Config["setup_" .. name]() end
|
if Config["setup_" .. plugin] then Config["setup_" .. plugin]() end
|
||||||
action()
|
rhs()
|
||||||
end
|
end or rhs
|
||||||
|
vim.keymap.set(mode, lhs, final_rhs, { desc = desc })
|
||||||
end
|
end
|
||||||
|
|
||||||
local nmap = function(lhs, rhs, desc, plugin)
|
local nmap = function(lhs, rhs, desc, plugin) map("n", lhs, rhs, desc, plugin) end
|
||||||
local final_rhs = plugin and lazy_wrap(plugin, rhs) or rhs
|
local tmap = function(lhs, rhs, desc, plugin) map("t", lhs, rhs, desc, plugin) end
|
||||||
vim.keymap.set("n", lhs, final_rhs, { desc = desc })
|
local nmap_leader = function(suffix, rhs, desc, plugin) map("n", "<Leader>" .. suffix, rhs, desc, plugin) end
|
||||||
end
|
local xmap_leader = function(suffix, rhs, desc, plugin) map("x", "<Leader>" .. suffix, rhs, desc, plugin) 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", "<Leader>" .. 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", "<Leader>" .. suffix, final_rhs, { desc = desc })
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Buffers =====================================================================
|
-- Buffers =====================================================================
|
||||||
nmap_leader("bd", function() pcall(vim.cmd, "bdelete") end, "Delete")
|
nmap_leader("bd", function() pcall(vim.cmd, "bdelete") end, "Delete")
|
||||||
@@ -122,7 +108,7 @@ nmap_leader("sw", function() MiniSessions.write() end, "Write current")
|
|||||||
-- Terminal ====================================================================
|
-- Terminal ====================================================================
|
||||||
nmap_leader("tT", function() vim.cmd("horizontal term") end, "Terminal (horizontal)")
|
nmap_leader("tT", function() vim.cmd("horizontal term") end, "Terminal (horizontal)")
|
||||||
nmap_leader("tt", function() vim.cmd("vertical term") end, "Terminal (vertical)")
|
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("tg", function() require("terminal").open_terminal_app("lazygit") end, "LazyGit")
|
||||||
nmap_leader("ts", function() require("terminal").open_terminal_app("lazysql") end, "LazySQL")
|
nmap_leader("ts", function() require("terminal").open_terminal_app("lazysql") end, "LazySQL")
|
||||||
|
|
||||||
|
|||||||
+12
-5
@@ -83,12 +83,19 @@ function Config.setup_dap()
|
|||||||
Config.setup_dap = nil
|
Config.setup_dap = nil
|
||||||
vim.pack.add({ "https://github.com/mfussenegger/nvim-dap" })
|
vim.pack.add({ "https://github.com/mfussenegger/nvim-dap" })
|
||||||
|
|
||||||
local dap = require("dap")
|
local dap_signs = {
|
||||||
dap.adapters.go = {
|
DapBreakpoint = { text = '', texthl = 'DapBreakpoint' },
|
||||||
type = "server",
|
DapBreakpointCondition = { text = '', texthl = 'DapBreakpointCondition' },
|
||||||
host = "127.0.0.1",
|
DapLogPoint = { text = '', texthl = 'DapLogPoint' },
|
||||||
port = "${port}",
|
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
|
end
|
||||||
|
|
||||||
-- Kulala ======================================================================
|
-- Kulala ======================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user