Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions home/.config/nvim/after/ftplugin/lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ end, { desc = "Launch osv" })

vim.api.nvim_create_user_command("OsvStop", require("osv").stop, { desc = "Stop osv" })

vim.keymap.set("n", "<leader>.x", function()
local map = require("map").create({
desc = "execute lua",
desc_separator = " ",
buffer = true,
})
map("n", "<leader>.x", function()
vim.cmd(".source")
end, { noremap = true, buffer = true, silent = true, desc = "execute lua lua" })
vim.keymap.set("n", "<leader>.X", function()
end, "lua")
map("n", "<leader>.X", function()
vim.cmd("source %")
end, { noremap = true, buffer = true, silent = true, desc = "execute lua file" })
vim.keymap.set("x", "<leader>.", function()
end, "file")
map("x", "<leader>.", function()
vim.cmd("'<'>source")
end, { noremap = true, buffer = true, silent = true, desc = "execute lua visual" })
end, "visual")
10 changes: 6 additions & 4 deletions home/.config/nvim/after/ftplugin/markdown.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
vim.keymap.set("n", "<leader>p", function()
local map = require("map").create({ buffer = true })

map("n", "<leader>l", function()
vim.cmd("LivePreview start")
end, { noremap = true, buffer = true, silent = true, desc = "LivePreview start" })
end, "LivePreview start")

vim.keymap.set("n", "<leader>P", function()
map("n", "<leader>L", function()
vim.cmd("LivePreview close")
end, { noremap = true, buffer = true, silent = true, desc = "LivePreview stop" })
end, "LivePreview stop")
5 changes: 5 additions & 0 deletions home/.config/nvim/lua/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local M = {}

M.border = "rounded"

return M
22 changes: 20 additions & 2 deletions home/.config/nvim/lua/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@ local M = {}
M.get_capabilities = defer.lazy(function()
return defer.require("cmp_nvim_lsp").default_capabilities()
end)
M.keymaps = {}
M.keymaps.organize_imports = "gro"

--- setup organize_imports mappings and user command
--- @param organize_imports function
--- @param buffer integer
function M.organize_imports(organize_imports, buffer)
require("map").map("n", "gro", organize_imports, { buffer = buffer, desc = "lsp.organize_imports" })
vim.api.nvim_buf_create_user_command(buffer, "LspOrganizeImports", organize_imports, { nargs = 0 })
end

function M.hover()
vim.lsp.buf.hover({ border = require("config").border })
end

function M.signature_help()
vim.lsp.buf.signature_help({ border = require("config").border })
end

function M.list_workspace_folders()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end

return M
54 changes: 54 additions & 0 deletions home/.config/nvim/lua/map.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
local M = {}

local OPTS = { silent = true, noremap = true }
--- create a map function that has defaults across the repo
--- @param opts? {desc:string,desc_separator?:string,buffer?:integer|boolean,opts?:vim.keymap.set.Opts,mode?:string|string[],rhs?:fun(arg:any):function}
--- @return function
function M.create(opts)
opts = opts or {}
opts.opts = opts.opts or OPTS
opts.desc_separator = opts.desc_separator or "."

if opts.buffer ~= nil then
opts.opts = vim.tbl_extend("force", opts.opts, { buffer = opts.buffer })
end

local function map(mode, lhs, rhs, o)
o = o or {}
if type(o) == "string" then
o = { desc = o }
end

if not o.desc then
if type(rhs) == "string" then
o.desc = rhs
elseif type(rhs) == "table" and type(rhs[1]) == "string" then
o.desc = rhs[1]
else
o.desc = lhs
end
end

local desc = opts.desc and { desc = opts.desc .. opts.desc_separator .. o.desc } or {}

if opts.rhs then
rhs = opts.rhs(rhs)
end

vim.keymap.set(mode, lhs, rhs, vim.tbl_extend("force", opts.opts, o, desc))
end

if opts.mode then
return function(lhs, rhs, o)
map(opts.mode, lhs, rhs, o)
end
else
return function(mode, lhs, rhs, o)
map(mode, lhs, rhs, o)
end
end
end

M.map = M.create()

return M
30 changes: 13 additions & 17 deletions home/.config/nvim/lua/pickers.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
local defer = require("defer")
local utils = require("utils")

local M = {}

local with_telescope = defer.with("telescope")

-- gg would be nice but then you can't jump to the top of the file
M.prefix = "<leader><leader>"
local get_opts = utils.create_get_opts({ noremap = true, silent = true })
M.map = function(lhs, rhs, opts)
opts = opts or {}

if type(rhs) == "function" then
vim.keymap.set("n", lhs, with_telescope(rhs), get_opts({ desc = "telescope." .. opts.desc }))
else
vim.keymap.set(
"n",
lhs,
with_telescope(function()
--- map a new picker
M.map = require("map").create({
mode = "n",
desc = "telescope",
rhs = function(rhs)
if type(rhs) == "function" then
return with_telescope(rhs)
else
return with_telescope(function()
require("telescope.builtin")[rhs]()
end),
get_opts({ desc = "telescope." .. rhs })
)
end
end
end)
end
end,
})

M.project_files = with_telescope(function()
local opts = {} -- define here if you want to define something
Expand Down
18 changes: 0 additions & 18 deletions home/.config/nvim/lua/utils.lua

This file was deleted.

2 changes: 1 addition & 1 deletion home/.config/nvim/plugin/autocomplete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defer.on_load("cmp", function()
cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })
end)

local window_config = cmp.config.window.bordered({ border = "rounded" })
local window_config = cmp.config.window.bordered({ border = require("config").border })

cmp.setup({
snippet = {
Expand Down
20 changes: 11 additions & 9 deletions home/.config/nvim/plugin/buffers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ defer.cmd("BDelete", "close_buffers")
defer.cmd("BWipeout", "close_buffers")
defer.hook("close_buffers")

local utils = require("utils")
local opts = { silent = true, noremap = true }
local get_opts = utils.create_get_opts(opts)
local map = require("map").create({
mode = "n",
desc = "close_buffers",
rhs = function(type)
return function()
require("close_buffers").delete({ type = type })
end
end,
})

vim.keymap.set("n", "<leader><bs>", function()
require("close_buffers").delete({ type = "this" })
end, get_opts({ desc = "close_buffers.delete_this" }))
vim.keymap.set("n", "<leader><c-h>", function() -- <C-BS> sends <C-h>
require("close_buffers").delete({ type = "hidden" })
end, get_opts({ desc = "close_buffers.delete_hidden" }))
map("<leader><bs>", "this")
map("<leader><c-h>", "hidden") -- <C-BS> sends <C-h>
2 changes: 1 addition & 1 deletion home/.config/nvim/plugin/cellular_automata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ local fml = function()
local animations = get_animations()
require("cellular-automaton").start_animation(animations[math.random(1, #animations)])
end
vim.keymap.set("n", "<leader>fml", fml, { noremap = true, silent = true })
require("map").map("n", "<leader>fml", fml, "fml")
10 changes: 7 additions & 3 deletions home/.config/nvim/plugin/clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ local function create_osc52(mode)
end
end

local map = require("map").create({
desc = "OSC52",
desc_separator = " ",
})
-- The Mappings
vim.keymap.set("n", "<leader>c", create_osc52("op"), { expr = true, desc = "OSC52 Operator" })
vim.keymap.set("n", "<leader>cc", create_osc52("line"), { desc = "OSC52 Yank Line" })
vim.keymap.set("v", "<leader>c", create_osc52("visual"), { desc = "OSC52 Yank Visual" })
map("n", "<leader>c", create_osc52("op"), { expr = true, desc = "Operator" })
map("n", "<leader>cc", create_osc52("line"), "Yank Line")
map("v", "<leader>c", create_osc52("visual"), "Yank Visual")
4 changes: 2 additions & 2 deletions home/.config/nvim/plugin/cokeline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ local function setup()
},
})

vim.keymap.set("n", "<leader>p", function()
require("map").map("n", "<leader>p", function()
pick("focus")
end, { silent = true, noremap = true, desc = "cokeline.pick.focus" })
end, "cokeline.pick.focus")
end

local group = vim.api.nvim_create_augroup("LazyLoadCokeline", { clear = true })
Expand Down
10 changes: 4 additions & 6 deletions home/.config/nvim/plugin/conform.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local defer = require("defer")

defer.on_load("conform", function()
local conform = require("conform")
local utils = require("utils")

local json = { "prettierd", "prettier", stop_after_first = true }
local js = { "eslint_d" }
Expand Down Expand Up @@ -57,9 +56,8 @@ defer.on_load("conform", function()
end
end

local opts = { silent = true }
local get_opts = utils.create_get_opts(opts)
vim.keymap.set({ "n", "x" }, "<leader>ff", function()
local map = require("map").create({ desc = "conform" })
map({ "n", "x" }, "<leader>ff", function()
require("conform").format({}, function(err)
if not err then
local mode = vim.api.nvim_get_mode().mode
Expand All @@ -68,8 +66,8 @@ defer.on_load("conform", function()
end
end
end)
end, get_opts({ desc = "conform.format" }))
vim.keymap.set("n", "<leader>tf", toggle_autoformat, get_opts({ desc = "conform.toggle_autoformat" }))
end, "format")
map("n", "<leader>tf", toggle_autoformat, "toggle_autoformat")

vim.api.nvim_create_user_command("Format", function(args)
local range = nil
Expand Down
41 changes: 21 additions & 20 deletions home/.config/nvim/plugin/dap.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
local defer = require("defer")
local utils = require("utils")
local opts = { noremap = true, silent = true }
local get_opts = utils.create_get_opts(opts)

local function focus_repl()
for _, win in ipairs(vim.api.nvim_list_wins()) do
Expand Down Expand Up @@ -31,6 +28,20 @@ local with_dap = defer.with("dap")
local with_dapui = defer.with("dapui")
local call = defer.call

local map = require("map").create({
desc = "dap",
rhs = function(args)
local t = type(args)
if t == "function" then
return args
elseif t == "string" then
return with_dap(call(args))
elseif t == "table" then
return with_dap(call(unpack(args)))
end
end,
})

local debug_layer = defer.lazy(defer.with("layers")(function()
local layer = require("layers").mode.new()
layer:auto_show_help()
Expand Down Expand Up @@ -190,9 +201,9 @@ defer.on_load("dap", function()
group = vim.api.nvim_create_augroup("dap_float", { clear = true }),
pattern = "dap-float",
callback = function()
vim.keymap.set("n", "q", function()
map("n", "q", function()
vim.cmd("close!")
end, get_opts({ desc = "dap.close_float" }))
end, "close_float")
end,
})

Expand All @@ -216,16 +227,6 @@ defer.very_lazy("dap")

-- Mappings.
local prefix = "<leader>d"
local map = function(mode, lhs, rhs, desc)
local t = type(rhs)
if t == "function" then
vim.keymap.set(mode, lhs, rhs, get_opts({ desc = "dap." .. desc }))
elseif t == "string" then
vim.keymap.set(mode, lhs, with_dap(call(rhs)), get_opts({ desc = "dap." .. rhs }))
else -- table
vim.keymap.set(mode, lhs, with_dap(call(unpack(rhs))), get_opts({ desc = "dap." .. rhs[1] }))
end
end

local set_breakpoint = with_dap(function(dap)
dap.set_breakpoint(vim.fn.input("Breakpoint condition: "))
Expand Down Expand Up @@ -269,27 +270,27 @@ map("n", prefix .. "e", { "set_exception_breakpoints", { "all" } })
map("n", prefix .. "i", ui_widgets_hover, "ui.widgets.hover")
map("n", prefix .. "?", ui_widgets_scopes, "ui.widgets.scopes")

vim.keymap.set("n", prefix .. "u", with_dapui(call("toggle")), get_opts({ desc = "dapui.toggle" }))
require("map").map("n", prefix .. "u", with_dapui(call("toggle")), "dapui.toggle")

-- telescope-dap
local pickers = require("pickers")
pickers.map(pickers.prefix .. "dc", function(telescope)
with_dap(function()
telescope.extensions.dap.commands()
end)()
end, { prefix = false, desc = "dap.commands" })
end, "dap.commands")
pickers.map(pickers.prefix .. "db", function(telescope)
with_dap(function()
telescope.extensions.dap.list_breakpoints()
end)()
end, { prefix = false, desc = "dap.list_breakpoints" })
end, "dap.list_breakpoints")
pickers.map(pickers.prefix .. "dv", function(telescope)
with_dap(function()
telescope.extensions.dap.variables()
end)()
end, { prefix = false, desc = "dap.variables" })
end, "dap.variables")
pickers.map(pickers.prefix .. "df", function(telescope)
with_dap(function()
telescope.extensions.dap.frames()
end)()
end, { prefix = false, desc = "dap.frames" })
end, "dap.frames")
4 changes: 2 additions & 2 deletions home/.config/nvim/plugin/dashboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ defer.on_load("alpha", function()
pattern = "alpha",
group = vim.api.nvim_create_augroup("alpha_keymaps", { clear = true }),
callback = function(opts)
vim.keymap.set("n", "i", function()
require("map").map("n", "i", function()
vim.cmd.ene()
vim.cmd.startinsert()
end, { buffer = opts.buf, silent = true, noremap = true, desc = "alpha.exit_and_edit" })
end, { buffer = opts.buf, desc = "alpha.exit_and_edit" })
end,
})

Expand Down
Loading
Loading