implements multiple todos

This commit is contained in:
js0ny 2025-01-15 15:13:02 +00:00
parent ef7b5680fb
commit 2aee2088c4
24 changed files with 355 additions and 331 deletions

View file

@ -0,0 +1,55 @@
local M = {}
--- buffer that doesn't act as an editor or common buffer.
--- Use `q` to close the buffer.
local tmp_buf = {
"qf", -- quickfix
"crunner", -- code runner
}
local term_buf = {
"floaterm",
"term",
}
local term_mode = {
"n",
"i",
"t",
}
local term_keymaps = {
{ mode = term_mode, keys = "<C-q>", cmd = ":FloatermToggle", desc = "Exit terminal mode" },
}
M.tmp_buf_keymaps = {
{ mode = "n", keys = "q", cmd = "<Cmd>q<CR>", desc = "Close buffer" },
}
for _, buf in ipairs(tmp_buf) do
vim.api.nvim_create_autocmd("FileType", {
pattern = buf,
callback = function()
for _, map in ipairs(M.tmp_buf_keymaps) do
local opts = vim.tbl_extend("force", { buffer = 0 }, map.opts or {})
vim.keymap.set(map.mode, map.keys, map.cmd, opts)
end
end,
})
end
vim.api.nvim_create_autocmd("BufEnter", {
pattern = "*",
callback = function()
-- 检查当前 buffer 的 buftype
local buftype = vim.bo.buftype
if buftype == "terminal" then
for _, map in ipairs(term_keymaps) do
local opts = vim.tbl_extend("force", { buffer = 0 }, map.opts or {})
vim.keymap.set(map.mode, map.keys, map.cmd, opts)
end
end
end,
})
return M

View file

@ -1,26 +1,20 @@
local M = {}
local keymaps_user_command = require("keymaps.user-command")
local global_default_opts = { noremap = true, silent = true }
local global_default_mode = { "n" }
-- local mode_arrow = { "n", "v", "o", "s", "x" }
local utils = require("keymaps.utils")
local function set_keymaps(maps, default_opts, default_mode)
for _, map in ipairs(maps) do
local opts = vim.tbl_extend("force", default_opts, map.opts or {})
local mode = map.mode or default_mode
vim.keymap.set(mode, map.keys, map.cmd, opts)
end
end
local keymaps_basic = require("keymaps.basic")
local keymaps_nvim_tree_general = require("keymaps.nvim-tree").global
local keymaps_leader = require("keymaps.leaders")
local keymaps_lsp = require("keymaps.lspkeys")
set_keymaps(keymaps_basic, global_default_opts, global_default_mode)
set_keymaps(keymaps_nvim_tree_general, global_default_opts, global_default_mode)
set_keymaps(keymaps_leader, global_default_opts, global_default_mode)
set_keymaps(keymaps_lsp, global_default_opts, global_default_mode)
local keymaps_general = vim.tbl_extend("force", {}, require("keymaps.leaders"), require("keymaps.lspkeys"))
-- Tables cannot be merged since `mode` are set in some keymaps of `keymaps_basic`
local keymaps_basic = require("keymaps.basic")
local keymaps_buffer = require("keymaps.buffer")
-- local keymaps_leader = require("keymaps.leaders")
-- local keymaps_lsp = require("keymaps.lspkeys")
utils.set_keymaps(keymaps_general)
utils.set_keymaps(keymaps_basic)
utils.set_keymaps(keymaps_nvim_tree_general)
utils.set_keymaps(keymaps_buffer)
M.nvim_tree_keymaps = require("keymaps.nvim-tree").plugin
@ -36,17 +30,17 @@ function M.cmp_nvim_keymaps(map)
}
end
local function set_markdown_keymaps(bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set("v", "`", 'c`<C-r>"`<Esc>', opts)
end
-- local function set_markdown_keymaps(bufnr)
-- local opts = { noremap = true, silent = true, buffer = bufnr }
-- vim.keymap.set("v", "`", 'c`<C-r>"`<Esc>', opts)
-- end
vim.api.nvim_create_autocmd("FileType", {
pattern = "markdown",
callback = function()
set_markdown_keymaps(0)
end,
})
-- vim.api.nvim_create_autocmd("FileType", {
-- pattern = "markdown",
-- callback = function()
-- set_markdown_keymaps(0)
-- end,
-- })
-- which-key.nvim
require("keymaps.which")

View file

@ -25,27 +25,4 @@ vim.api.nvim_create_autocmd("FileType", {
end,
})
--- buffer that doesn't act as an editor or common buffer.
--- Use `q` to close the buffer.
local tmp_buf = {
"qf", -- quickfix
"crunner", -- code runner
}
M.tmp_buf_keymaps = {
{ mode = "n", keys = "q", cmd = "<Cmd>q<CR>", desc = "Close buffer" },
}
for _, buf in ipairs(tmp_buf) do
vim.api.nvim_create_autocmd("FileType", {
pattern = buf,
callback = function()
for _, map in ipairs(M.tmp_buf_keymaps) do
local opts = vim.tbl_extend("force", { buffer = 0 }, map.opts or {})
vim.keymap.set(map.mode, map.keys, map.cmd, opts)
end
end,
})
end
return M

View file

@ -42,7 +42,7 @@ vim.api.nvim_create_user_command("Rename", renameCurrentBuffer, {})
local leader_mappings = {
general = {
{ keys = "<space>", cmd = ":Telescope find_files<CR>", opts = { desc = "Find Files" } },
{ keys = "<leader>", cmd = ":Telescope find_files<CR>", opts = { desc = "Find Files" } },
{ keys = "/", cmd = ":Telescope live_grep<CR>", opts = { desc = "Grep Files" } },
{ keys = "-", cmd = ":split<CR>", opts = { desc = "Split to down" } },
{ keys = "\\", cmd = ":vsplit<CR>", opts = { desc = "Split to right" } },
@ -51,6 +51,8 @@ local leader_mappings = {
{ keys = "n", cmd = "<C-w>j", opts = { desc = "Down Window" } },
{ keys = "e", cmd = "<C-w>k", opts = { desc = "Up Window" } },
{ keys = "i", cmd = "<C-w>l", opts = { desc = "Right Window" } },
{ keys = "<Tab>", cmd = "<Cmd>b#<CR>", opts = { desc = "Switch to last buffer" } },
{ keys = "!", cmd = ":FloatermToggle<CR>", opts = { desc = "" } },
},
b = { -- +buffer
{ keys = "a", cmd = ":Alpha<CR>", opts = { desc = "Dashboard" } },

View file

@ -0,0 +1,33 @@
local M = {}
-- local mode_arrow = { "n", "v", "o", "s", "x" }
local default_opts = { noremap = true, silent = true }
local default_mode = { "n" }
M.set_keymaps = function(maps)
for _, map in ipairs(maps) do
local opts = vim.tbl_extend("force", default_opts, map.opts or {})
local mode = map.mode or default_mode
vim.keymap.set(mode, map.keys, map.cmd, opts)
end
end
M.set_lang_keymaps = function(maps)
vim.api.create_autocmd("FileType", {
pattern = maps.filetype,
callback = function()
M.set_keymaps(maps.keymaps)
end,
})
end
M.set_buf_keymaps = function(maps)
vim.api.create_autocmd("BufEnter", {
pattern = maps.filetype,
callback = function()
M.set_keymaps(maps.keymaps)
end,
})
end
return M