mirror of
https://github.com/js0ny/dotfiles.git
synced 2025-12-21 08:43:00 +00:00
chezmoi: reorganise repo
This commit is contained in:
parent
b391e03c87
commit
67a78879db
278 changed files with 102 additions and 182 deletions
76
home/dot_config/nvim/lua/keymaps/basic.lua
Normal file
76
home/dot_config/nvim/lua/keymaps/basic.lua
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
local mode_arrow = { "n", "v", "s", "x", "o" }
|
||||
|
||||
local keymaps_basic = { -- Modification of Original Keymap - Colemak
|
||||
-- https://github.com/LazyVim/LazyVim/blob/d1529f650fdd89cb620258bdeca5ed7b558420c7/lua/lazyvim/config/keymaps.lua#L8
|
||||
{
|
||||
mode = mode_arrow,
|
||||
keys = "j",
|
||||
cmd = "v:count == 0 ? 'gj' : 'j'",
|
||||
opts = { desc = "Down", expr = true, silent = true },
|
||||
},
|
||||
{
|
||||
mode = mode_arrow,
|
||||
keys = "<Down>",
|
||||
cmd = "v:count == 0 ? 'gj' : 'j'",
|
||||
opts = { desc = "Down", expr = true, silent = true },
|
||||
},
|
||||
{
|
||||
mode = mode_arrow,
|
||||
keys = "k",
|
||||
cmd = "v:count == 0 ? 'gk' : 'k'",
|
||||
opts = { desc = "Up", expr = true, silent = true },
|
||||
},
|
||||
{
|
||||
mode = mode_arrow,
|
||||
keys = "<Up>",
|
||||
cmd = "v:count == 0 ? 'gk' : 'k'",
|
||||
opts = { desc = "Up", expr = true, silent = true },
|
||||
},
|
||||
|
||||
{
|
||||
mode = "o",
|
||||
keys = "j",
|
||||
cmd = "j",
|
||||
opts = { desc = "Down", silent = true },
|
||||
},
|
||||
{
|
||||
mode = "o",
|
||||
keys = "<Down>",
|
||||
cmd = "j",
|
||||
opts = { desc = "Down", silent = true },
|
||||
},
|
||||
{
|
||||
mode = "o",
|
||||
keys = "k",
|
||||
cmd = "k",
|
||||
opts = { desc = "Up", silent = true },
|
||||
},
|
||||
{
|
||||
mode = "o",
|
||||
keys = "<Up>",
|
||||
cmd = "k",
|
||||
opts = { desc = "Up", silent = true },
|
||||
},
|
||||
|
||||
{ mode = mode_arrow, keys = "h", cmd = "h", opts = { desc = "Left", silent = true } },
|
||||
-- { mode = mode_arrow, keys = "i", cmd = "l", opts = { desc = "Right", silent = true } },
|
||||
{ mode = { "n" }, keys = "H", cmd = "<cmd>bprevious<CR>", opts = { desc = "Previous Buffer" } },
|
||||
{ mode = { "n" }, keys = "L", cmd = "<cmd>bnext<CR>", opts = { desc = "Next Buffer" } },
|
||||
{ mode = { "v", "o", "x" }, keys = "H", cmd = "^", opts = { desc = "Start of Line" } },
|
||||
{ mode = { "v", "o", "x" }, keys = "L", cmd = "$", opts = { desc = "End of Line" } },
|
||||
{ mode = mode_arrow, keys = "J", cmd = "5j", opts = { desc = "Up 5 Lines" } },
|
||||
{ mode = mode_arrow, keys = "K", cmd = "5e", opts = { desc = "Down 5 Lines" } },
|
||||
{ keys = "Y", cmd = "y$", opts = { desc = "Yank to End of Line" } },
|
||||
{ mode = mode_arrow, keys = "J", cmd = "5j" },
|
||||
{ mode = mode_arrow, keys = "K", cmd = "5k" },
|
||||
-- { mode = { "n", "o", "x" }, keys = "l", cmd = "i", opts = { desc = "Insert" } },
|
||||
-- { keys = "L", cmd = "I", opts = { desc = "Insert at Start of Line" } },
|
||||
-- { mode = mode_arrow, keys = "k", cmd = "n", opts = { desc = "Next Search" } },
|
||||
-- { mode = mode_arrow, keys = "K", cmd = "N", opts = { desc = "Previous Search" } },
|
||||
-- { mode = mode_arrow, keys = "j", cmd = "e", opts = { desc = "jump to end of word" } },
|
||||
-- { mode = mode_arrow, keys = "J", cmd = "E", opts = { desc = "jump to end of WORD" } },
|
||||
-- https://github.com/LazyVim/LazyVim/blob/d1529f650fdd89cb620258bdeca5ed7b558420c7/lua/lazyvim/config/keymaps.lua#L60
|
||||
{ keys = "<Esc>", cmd = "<Cmd>nohlsearch<Bar>diffupdate<CR>", opts = { desc = "Clear Search Highlight" } },
|
||||
}
|
||||
|
||||
return keymaps_basic
|
||||
71
home/dot_config/nvim/lua/keymaps/buffer.lua
Normal file
71
home/dot_config/nvim/lua/keymaps/buffer.lua
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
local bufmap = {
|
||||
markdown = {
|
||||
{ mode = "x", keys = "i", cmd = 'c*<C-r>"*', opt = { desc = "Add italic to selected text" } },
|
||||
{ mode = "x", keys = "b", cmd = 'c**<C-r>"**', opt = { desc = "Add bold to selected text" } },
|
||||
{ mode = "x", keys = "c", cmd = 'c`<CR><C-r>"<CR>`', opt = { desc = "Add code block to selected text" } },
|
||||
{ mode = "x", keys = "d", cmd = 'c~~<C-r>"~~', opt = { desc = "Add strikethrough to selected text" } },
|
||||
{ mode = "x", keys = "h", cmd = 'c==<C-r>"==', opt = { desc = "Add highlight to selected text" } },
|
||||
},
|
||||
tex = {
|
||||
{ mode = "x", keys = "i", cmd = 'c\\textit{<C-r>"}', opt = { desc = "Add italic to selected text" } },
|
||||
{ mode = "x", keys = "b", cmd = 'c\\textbf{<C-r>"}', opt = { desc = "Add bold to selected text" } },
|
||||
{
|
||||
mode = "x",
|
||||
keys = "c",
|
||||
cmd = 'c\\begin{verbatim}<CR><C-r>"<CR>\\end{verbatim}',
|
||||
opt = { desc = "Add code block to selected text" },
|
||||
},
|
||||
{ mode = "x", keys = "d", cmd = 'c\\sout{<C-r>"}', opt = { desc = "Add strikethrough to selected text" } },
|
||||
{ mode = "x", keys = "h", cmd = 'c\\hl{<C-r>"}', opt = { desc = "Add highlight to selected text" } },
|
||||
{ mode = "n", keys = "<leader>cc", cmd = "<cmd>w<CR>", opt = { desc = "Save and compile tex file" } },
|
||||
-- { mode = "i", keys = "<C-m><C-m>", cmd = "<cmd>w<CR>", opt = { desc = "Save and compile tex file" } },
|
||||
},
|
||||
org = {
|
||||
{ mode = "x", keys = "i", cmd = 'c/<C-r>/"', opt = { desc = "Add italic to selected text" } },
|
||||
{ mode = "x", keys = "b", cmd = 'c*<C-r>"*', opt = { desc = "Add bold to selected text" } },
|
||||
-- {
|
||||
-- mode = "x",
|
||||
-- keys = "c",
|
||||
-- cmd = 'c#+BEGIN_SRC<CR><C-r>"<CR>#+END_SRC',
|
||||
-- opt = { desc = "Add code block to selected text" },
|
||||
-- },
|
||||
{ mode = "x", keys = "d", cmd = 'c+<C-r>"+', opt = { desc = "Add strikethrough to selected text" } },
|
||||
{ mode = "x", keys = "h", cmd = 'c~<C-r>"~', opt = { desc = "Add highlight to selected text" } },
|
||||
},
|
||||
}
|
||||
|
||||
local function setup_buffer_maps(buffer_map)
|
||||
-- 遍历 buffer_map 中的每个文件类型
|
||||
for ft, mappings in pairs(buffer_map) do
|
||||
-- 1. 为现有缓冲区设置键位映射
|
||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if vim.api.nvim_buf_get_option(buf, "filetype") == ft then
|
||||
for _, mapping in ipairs(mappings) do
|
||||
-- 合并选项,添加 buffer 以确保映射是缓冲区局部的
|
||||
if mapping.mode ~= "n" then
|
||||
mapping.keys = "<C-m>" .. mapping.keys
|
||||
end
|
||||
local opts = vim.tbl_extend("force", mapping.opt, { buffer = buf })
|
||||
vim.keymap.set(mapping.mode, mapping.keys, mapping.cmd, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 2. 为未来缓冲区设置自动命令
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = ft, -- 匹配文件类型,例如 "markdown"
|
||||
callback = function(args)
|
||||
local buf = args.buf -- 获取触发事件的缓冲区号
|
||||
for _, mapping in ipairs(mappings) do
|
||||
local opts = vim.tbl_extend("force", mapping.opt, { buffer = buf })
|
||||
if mapping.mode ~= "n" then
|
||||
mapping.keys = "<C-m>" .. mapping.keys
|
||||
end
|
||||
vim.keymap.set(mapping.mode, mapping.keys, mapping.cmd, opts)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
setup_buffer_maps(bufmap)
|
||||
40
home/dot_config/nvim/lua/keymaps/init.lua
Normal file
40
home/dot_config/nvim/lua/keymaps/init.lua
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
local M = {}
|
||||
-- local keymaps_user_command = require("keymaps.user-command")
|
||||
require("keymaps.user-command")
|
||||
local utils = require("keymaps.utils")
|
||||
|
||||
local keymaps_nvim_tree_general = require("keymaps.nvim-tree").global
|
||||
|
||||
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_modifier = require("keymaps.modifier")
|
||||
|
||||
require("keymaps.buffer")
|
||||
|
||||
utils.set_keymaps(keymaps_general)
|
||||
utils.set_keymaps(keymaps_basic)
|
||||
utils.set_keymaps(keymaps_nvim_tree_general)
|
||||
utils.set_keymaps(keymaps_modifier)
|
||||
|
||||
M.nvim_tree_keymaps = require("keymaps.nvim-tree").plugin
|
||||
|
||||
-- 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,
|
||||
-- })
|
||||
|
||||
-- which-key.nvim
|
||||
if vim.g.loaded_which_key then
|
||||
require("keymaps.which")
|
||||
end
|
||||
require("keymaps.visual-multi")
|
||||
|
||||
return M
|
||||
28
home/dot_config/nvim/lua/keymaps/language.lua
Normal file
28
home/dot_config/nvim/lua/keymaps/language.lua
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
local M = {}
|
||||
|
||||
-- Markdown
|
||||
|
||||
local function set_markdown_keymaps(bufnr)
|
||||
local markdown_opt = { noremap = true, silent = true, buffer = bufnr }
|
||||
for _, map in ipairs(M.markdown) do
|
||||
local opts = vim.tbl_extend("force", markdown_opt, map.opts or {})
|
||||
vim.keymap.set(map.mode, map.keys, map.cmd, opts)
|
||||
end
|
||||
end
|
||||
|
||||
M.markdown = {
|
||||
{ mode = "v", keys = "`", cmd = "c`<Esc>pi`<Esc>", desc = "Wrap selection in ` for inline code" },
|
||||
{ mode = "v", keys = "*", cmd = "c**<Esc>pi**<Esc>", desc = "Wrap selection in ** for bold" },
|
||||
{ mode = "v", keys = "_", cmd = "c*<Esc>pi*<Esc>", desc = "Wrap selection in * for italic" },
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "markdown",
|
||||
callback = function()
|
||||
set_markdown_keymaps(0)
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.tabstop = 2
|
||||
end,
|
||||
})
|
||||
|
||||
return M
|
||||
194
home/dot_config/nvim/lua/keymaps/leaders.bak
Normal file
194
home/dot_config/nvim/lua/keymaps/leaders.bak
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
local M = {}
|
||||
|
||||
local formatFx = function()
|
||||
require("conform").format({ async = true })
|
||||
end
|
||||
|
||||
local renameCurrentBuffer = function()
|
||||
local old_name = vim.fn.expand("%:p")
|
||||
local new_name = vim.fn.input("New name: ", vim.fn.expand("%:p:h") .. "/")
|
||||
|
||||
if new_name == "" then
|
||||
print("No new name provided")
|
||||
return
|
||||
elseif new_name == old_name then
|
||||
return
|
||||
end
|
||||
|
||||
vim.cmd("write")
|
||||
|
||||
local success, err = os.rename(old_name, new_name)
|
||||
if not success then
|
||||
print("Error renaming file: " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
vim.cmd("edit " .. new_name)
|
||||
vim.cmd("bdelete " .. old_name)
|
||||
end
|
||||
|
||||
-- 通用映射函数
|
||||
local function apply_mappings(maps, prefix)
|
||||
for _, map in ipairs(maps) do
|
||||
local new_map = {
|
||||
keys = prefix .. map.keys,
|
||||
cmd = map.cmd,
|
||||
opts = map.opts,
|
||||
}
|
||||
table.insert(M, new_map)
|
||||
end
|
||||
end
|
||||
vim.api.nvim_create_user_command("Rename", renameCurrentBuffer, {})
|
||||
|
||||
local leader_mappings = {
|
||||
general = {
|
||||
{ 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" } },
|
||||
{ keys = "|", cmd = ":vsplit<CR>", opts = { desc = "Split to right" } },
|
||||
{ keys = "h", cmd = "<C-w>h", opts = { desc = "Left Window" } },
|
||||
{ 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 = "F", cmd = ":NvimTreeFindFileToggle<CR>", opts = { desc = "Toggle File Explorer" } },
|
||||
{ keys = "<Tab>", cmd = "<Cmd>b#<CR>", opts = { desc = "Switch to last buffer" } },
|
||||
{ keys = "!", cmd = ":FloatermToggle<CR>", opts = { desc = "Toggle Terminal" } },
|
||||
{ keys = '"', cmd = ":!wezterm-gui &<CR>", pots = { desc = "Open External Terminal(wezterm)" } },
|
||||
{ keys = ";", cmd = ":Telescope<CR>", pots = { desc = "Show Telescope Commands" } },
|
||||
},
|
||||
b = { -- +buffer
|
||||
{ keys = "0", cmd = "<Cmd>b#<CR>", opts = { desc = "Switch to last buffer" } },
|
||||
{ keys = "1", cmd = ":BufferLineGotoBuffer 1<CR>", opts = { desc = "Switch to Buffer #1" } },
|
||||
{ keys = "2", cmd = ":BufferLineGotoBuffer 2<CR>", opts = { desc = "Switch to Buffer #2" } },
|
||||
{ keys = "3", cmd = ":BufferLineGotoBuffer 3<CR>", opts = { desc = "Switch to Buffer #3" } },
|
||||
{ keys = "4", cmd = ":BufferLineGotoBuffer 4<CR>", opts = { desc = "Switch to Buffer #4" } },
|
||||
{ keys = "5", cmd = ":BufferLineGotoBuffer 5<CR>", opts = { desc = "Switch to Buffer #5" } },
|
||||
{ keys = "6", cmd = ":BufferLineGotoBuffer 6<CR>", opts = { desc = "Switch to Buffer #6" } },
|
||||
{ keys = "7", cmd = ":BufferLineGotoBuffer 7<CR>", opts = { desc = "Switch to Buffer #7" } },
|
||||
{ keys = "8", cmd = ":BufferLineGotoBuffer 8<CR>", opts = { desc = "Switch to Buffer #8" } },
|
||||
{ keys = "9", cmd = ":BufferLineGotoBuffer 9<CR>", opts = { desc = "Switch to Buffer #9" } },
|
||||
{ keys = "a", cmd = ":Alpha<CR>", opts = { desc = "Dashboard" } },
|
||||
{ keys = "b", cmd = ":BufferLinePick<CR>", opts = { desc = "Quick Switch Buffers" } },
|
||||
{ keys = "B", cmd = ":Telescope buffers<CR>", opts = { desc = "List Buffers" } },
|
||||
{ keys = "d", cmd = ":bdelete<CR>", opts = { desc = "Delete Buffer" } },
|
||||
{ keys = "D", cmd = ":BufferLineCloseOthers<CR>", opts = { desc = "Delete Other Buffers" } },
|
||||
{ keys = "xx", cmd = ":BufferLineCloseOthers<CR>", opts = { desc = "Delete Other Buffers" } },
|
||||
{ keys = "xh", cmd = ":BufferLineCloseLeft<CR>", opts = { desc = "Delete Buffers Left" } },
|
||||
{ keys = "xi", cmd = ":BufferLineCloseRight<CR>", opts = { desc = "Delete Buffers Right" } },
|
||||
{ keys = "X", cmd = ":BufferLineCloseOthers<CR>", opts = { desc = "Delete Other Buffers" } },
|
||||
{ keys = "h", cmd = ":bprevious<CR>", opts = { desc = "Previous Buffer" } },
|
||||
{ keys = "i", cmd = ":bnext<CR>", opts = { desc = "Next Buffer" } },
|
||||
{ keys = "H", cmd = ":bfirst<CR>", opts = { desc = "First Buffer" } },
|
||||
{ keys = "I", cmd = ":blast<CR>", opts = { desc = "Last Buffer" } },
|
||||
{ keys = "0", cmd = ":bfirst<CR>", opts = { desc = "First Buffer" } },
|
||||
{ keys = "^", cmd = ":bfirst<CR>", opts = { desc = "First Buffer" } },
|
||||
{ keys = "$", cmd = ":blast<CR>", opts = { desc = "Last Buffer" } },
|
||||
{ keys = "s", cmd = ":new<CR>", opts = { desc = "Scratch buffers" } },
|
||||
{ keys = "t", cmd = ":BufferLineTogglePin<CR>", opts = { desc = "Pin Buffer" } },
|
||||
{ keys = "y", cmd = ":%y+<CR>", opts = { desc = "Copy Buffer to Clipboard" } },
|
||||
},
|
||||
c = { -- +code/compile
|
||||
{ keys = "r", cmd = ":RunCode<CR>", opts = { desc = "Run code" } },
|
||||
{ keys = "R", cmd = vim.lsp.buf.rename, opts = { desc = "Rename symbol under cursor" } },
|
||||
{ keys = "e", cmd = ":Telescope diagnostics<CR>", opts = { desc = "Navigate errors/warnings" } },
|
||||
{ keys = "f", cmd = formatFx, opts = { desc = "Format buffer" } },
|
||||
{ keys = "s", cmd = ":Telescope treesitter<CR>", opts = { desc = "Search symbols" } },
|
||||
{ keys = "S", cmd = ":Telescope grep_string<CR>", opts = { desc = "Search current symbol" } },
|
||||
},
|
||||
f = { -- +file/find
|
||||
{ keys = "f", cmd = ":Telescope fd<CR>", opts = { desc = "Find Files" } },
|
||||
{ keys = "F", cmd = ":GrugFar<CR>", opts = { desc = "Search & Replace" } },
|
||||
{ keys = "l", cmd = ":set filetype=", opts = { desc = "Set Filetype to ..." } },
|
||||
{ keys = "n", cmd = ":new<CR>", opts = { desc = "New File" } },
|
||||
{ keys = "s", cmd = ":write<CR>", opts = { desc = "Save File" } },
|
||||
{ keys = "S", cmd = ":wall<CR>", opts = { desc = "Save All Files" } },
|
||||
{ keys = "b", cmd = ":Telescope buffers<CR>", opts = { desc = "List Buffers" } },
|
||||
{ keys = "D", cmd = "!trash-rm %<CR>", opts = { desc = "Delete current file" } },
|
||||
{ keys = "t", cmd = ":NvimTreeFindFileToggle<CR>", opts = { desc = "Toggle File Tree" } },
|
||||
{ keys = "T", cmd = ":FloatermNew<CR>", opts = { desc = "Spawn a float terminal" } },
|
||||
{ keys = "h", cmd = ":Telescope oldfiles<CR>", opts = { desc = "Search history files" } },
|
||||
{ keys = "c", cmd = ":Telescope find_files cwd=~/.config/nvim<CR>", opts = { desc = "Search Config" } },
|
||||
{ keys = "o", cmd = ":!open %<CR>", opts = { desc = "Open file in default program" } },
|
||||
{ keys = "R", cmd = renameCurrentBuffer, opts = { desc = "Rename current file" } },
|
||||
{ keys = "x", cmd = ":Lazy<CR>", opts = { desc = "Open extension view" } },
|
||||
{ keys = "yy", cmd = ":let @+ = expand('%:p')<CR>", opts = { desc = "Copy file path" } },
|
||||
{ keys = "yY", cmd = ":let @+ = expand('%')<CR>", opts = { desc = "Copy relative file path" } },
|
||||
{ keys = "yn", cmd = ":let @+ = expand('%:t')<CR>", opts = { desc = "Copy file name" } },
|
||||
{ keys = "yN", cmd = ":let @+ = expand('%:t:r')<CR>", opts = { desc = "Copy file name without extension" } },
|
||||
{ keys = "yd", cmd = ":let @+ = expand('%:p:h')<CR>", opts = { desc = "Copy directory path" } },
|
||||
{
|
||||
keys = "yl",
|
||||
cmd = ":let @+ = expand('%:p') . ':' . line('.')<CR>",
|
||||
opts = { desc = "Copy file path with line number" },
|
||||
},
|
||||
{
|
||||
keys = "yL",
|
||||
cmd = ":let @+ = expand('%') . ':' . line('.')<CR>",
|
||||
opts = { desc = "Copy relative file path with line number" },
|
||||
},
|
||||
},
|
||||
g = { -- +git/version control
|
||||
{ keys = "g", cmd = ":LazyGit<CR>", opts = { desc = "Toggle LazyGit" } },
|
||||
{ keys = "c", cmd = ":Telescope git_commits<CR>", opts = { desc = "Show commits" } },
|
||||
{ keys = "b", cmd = ":Gitsigns blame<CR>", opts = { desc = "Blame file" } },
|
||||
{ keys = "d", cmd = ":Gitsigns diffthis<CR>", opts = { desc = "Diff file" } },
|
||||
{ keys = "B", cmd = ":Gitsigns toggle_current_line_blame<CR>", opts = { desc = "Toggle line blame" } },
|
||||
{ keys = "s", cmd = ":Telescope git_status<CR>", opts = { desc = "Git Status" } },
|
||||
{ keys = "t", cmd = ":Telescope git_branches<CR>", opts = { desc = "Git Branches" } },
|
||||
},
|
||||
j = { -- +lsp
|
||||
{ keys = "r", cmd = vim.lsp.buf.references, opts = { desc = "Show current reference" } },
|
||||
},
|
||||
p = { -- +project
|
||||
{ keys = "p", cmd = ":Telescope projects<CR>", opts = { desc = "List all Projects" } },
|
||||
{ keys = "g", cmd = ":Telescope projects<CR>", opts = { desc = "List all Git Projects" } },
|
||||
{ keys = "s", cmd = ":Telescope session-lens<CR>", opts = { desc = "List all sessions" } },
|
||||
},
|
||||
q = { -- +quit
|
||||
{ keys = "q", cmd = ":q<CR>", opts = { desc = "Quit" } },
|
||||
{ keys = "Q", cmd = ":qa!<CR>", opts = { desc = "Force Quit" } },
|
||||
{ keys = "w", cmd = ":wq<CR>", opts = { desc = "Write and Quit" } },
|
||||
{ keys = "W", cmd = ":wall<CR>:qa!<CR>", opts = { desc = "Write all and Force Quit" } },
|
||||
},
|
||||
t = { -- +toggle/test
|
||||
{ keys = "f", cmd = ":NvimTreeToggle", opts = { desc = "Toggle File Explorer" } },
|
||||
{ keys = "F", cmd = ":FormatToggle<CR>", opts = { desc = "Toggle autoformat-on-save" } },
|
||||
{ keys = "t", cmd = ":FloatermToggle<CR>", opts = { desc = "toggle visibility of the float terminal" } },
|
||||
},
|
||||
u = { -- +ui
|
||||
{ keys = "i", cmd = ":Telescope colorscheme<CR>", opts = { desc = "Change colorscheme" } },
|
||||
{ keys = " ", cmd = ":set list!", opts = { desc = "Toggle show all symbols" } },
|
||||
},
|
||||
w = { -- +window
|
||||
{ keys = "h", cmd = "<C-w>h", opts = { desc = "Left Window" } },
|
||||
{ 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 = "H", cmd = "<C-w>H", opts = { desc = "Move Window Left" } },
|
||||
{ keys = "N", cmd = "<C-w>J", opts = { desc = "Move Window Down" } },
|
||||
{ keys = "E", cmd = "<C-w>K", opts = { desc = "Move Window Up" } },
|
||||
{ keys = "I", cmd = "<C-w>L", opts = { desc = "Move Window Right" } },
|
||||
{ keys = "-", cmd = ":split<CR>", opts = { desc = "Split to down" } },
|
||||
{ keys = "|", cmd = ":vsplit<CR>", opts = { desc = "Split to right" } },
|
||||
{ keys = "/", cmd = ":vsplit<CR>", opts = { desc = "Split to right" } },
|
||||
{ keys = "d", cmd = "<C-w>c", opts = { desc = "Close Window" } },
|
||||
{ keys = "D", cmd = "<C-w>o", opts = { desc = "Close Other Windows" } },
|
||||
{ keys = "r", cmd = "<C-w>r", opts = { desc = "Rotate Windows" } },
|
||||
{ keys = "R", cmd = "<C-w>R", opts = { desc = "Reverse Rotate Windows" } },
|
||||
{ keys = "t", cmd = "<C-w>T", opts = { desc = "Move Window to New Tab" } },
|
||||
{ keys = "]", cmd = ":resize +5<CR>", opts = { desc = "Increase Window Size" } },
|
||||
{ keys = "[", cmd = ":resize -5<CR>", opts = { desc = "Decrease Window Size" } },
|
||||
{ keys = "M", cmd = ":resize<CR>:vertical resize<CR>", opts = { desc = "Maximize window size" } },
|
||||
},
|
||||
}
|
||||
|
||||
for key, maps in pairs(leader_mappings) do
|
||||
if key == "general" then
|
||||
apply_mappings(maps, "<leader>")
|
||||
else
|
||||
apply_mappings(maps, "<leader>" .. key)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
164
home/dot_config/nvim/lua/keymaps/leaders.lua
Normal file
164
home/dot_config/nvim/lua/keymaps/leaders.lua
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
local M = {}
|
||||
|
||||
local formatFx = function()
|
||||
require("conform").format({ async = true })
|
||||
end
|
||||
|
||||
local renameCurrentBuffer = function()
|
||||
local old_name = vim.fn.expand("%:p")
|
||||
local new_name = vim.fn.input("New name: ", vim.fn.expand("%:p:h") .. "/")
|
||||
|
||||
if new_name == "" then
|
||||
print("No new name provided")
|
||||
return
|
||||
elseif new_name == old_name then
|
||||
return
|
||||
end
|
||||
|
||||
vim.cmd("write")
|
||||
|
||||
local success, err = os.rename(old_name, new_name)
|
||||
if not success then
|
||||
print("Error renaming file: " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
vim.cmd("edit " .. new_name)
|
||||
vim.cmd("bdelete " .. old_name)
|
||||
end
|
||||
|
||||
-- 通用映射函数
|
||||
local function apply_mappings(maps, prefix)
|
||||
for _, map in ipairs(maps) do
|
||||
local new_map = {
|
||||
keys = prefix .. map.keys,
|
||||
cmd = map.cmd,
|
||||
opts = map.opts,
|
||||
}
|
||||
table.insert(M, new_map)
|
||||
end
|
||||
end
|
||||
vim.api.nvim_create_user_command("Rename", renameCurrentBuffer, {})
|
||||
|
||||
local leader_mappings = {
|
||||
general = {
|
||||
{ keys = "-", cmd = ":split<CR>", opts = { desc = "Split to down" } },
|
||||
{ keys = "\\", cmd = ":vsplit<CR>", opts = { desc = "Split to right" } },
|
||||
{ keys = "|", cmd = ":vsplit<CR>", opts = { desc = "Split to right" } },
|
||||
{ keys = "h", cmd = "<C-w>h", opts = { desc = "Left Window" } },
|
||||
{ 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 = ":!wezterm-gui &<CR>", pots = { desc = "Open External Terminal(wezterm)" } },
|
||||
},
|
||||
b = { -- +buffer
|
||||
{ keys = "0", cmd = "<Cmd>b#<CR>", opts = { desc = "Switch to last buffer" } },
|
||||
{ keys = "1", cmd = ":BufferLineGotoBuffer 1<CR>", opts = { desc = "Switch to Buffer #1" } },
|
||||
{ keys = "2", cmd = ":BufferLineGotoBuffer 2<CR>", opts = { desc = "Switch to Buffer #2" } },
|
||||
{ keys = "3", cmd = ":BufferLineGotoBuffer 3<CR>", opts = { desc = "Switch to Buffer #3" } },
|
||||
{ keys = "4", cmd = ":BufferLineGotoBuffer 4<CR>", opts = { desc = "Switch to Buffer #4" } },
|
||||
{ keys = "5", cmd = ":BufferLineGotoBuffer 5<CR>", opts = { desc = "Switch to Buffer #5" } },
|
||||
{ keys = "6", cmd = ":BufferLineGotoBuffer 6<CR>", opts = { desc = "Switch to Buffer #6" } },
|
||||
{ keys = "7", cmd = ":BufferLineGotoBuffer 7<CR>", opts = { desc = "Switch to Buffer #7" } },
|
||||
{ keys = "8", cmd = ":BufferLineGotoBuffer 8<CR>", opts = { desc = "Switch to Buffer #8" } },
|
||||
{ keys = "9", cmd = ":BufferLineGotoBuffer 9<CR>", opts = { desc = "Switch to Buffer #9" } },
|
||||
{ keys = "b", cmd = ":BufferLinePick<CR>", opts = { desc = "Quick Switch Buffers" } },
|
||||
{ keys = "d", cmd = ":bdelete<CR>", opts = { desc = "Delete Buffer" } },
|
||||
{ keys = "D", cmd = ":BufferLineCloseOthers<CR>", opts = { desc = "Delete Other Buffers" } },
|
||||
{ keys = "xx", cmd = ":BufferLineCloseOthers<CR>", opts = { desc = "Delete Other Buffers" } },
|
||||
{ keys = "xh", cmd = ":BufferLineCloseLeft<CR>", opts = { desc = "Delete Buffers Left" } },
|
||||
{ keys = "xi", cmd = ":BufferLineCloseRight<CR>", opts = { desc = "Delete Buffers Right" } },
|
||||
{ keys = "X", cmd = ":BufferLineCloseOthers<CR>", opts = { desc = "Delete Other Buffers" } },
|
||||
{ keys = "h", cmd = ":bprevious<CR>", opts = { desc = "Previous Buffer" } },
|
||||
{ keys = "i", cmd = ":bnext<CR>", opts = { desc = "Next Buffer" } },
|
||||
{ keys = "H", cmd = ":bfirst<CR>", opts = { desc = "First Buffer" } },
|
||||
{ keys = "I", cmd = ":blast<CR>", opts = { desc = "Last Buffer" } },
|
||||
{ keys = "0", cmd = ":bfirst<CR>", opts = { desc = "First Buffer" } },
|
||||
{ keys = "^", cmd = ":bfirst<CR>", opts = { desc = "First Buffer" } },
|
||||
{ keys = "$", cmd = ":blast<CR>", opts = { desc = "Last Buffer" } },
|
||||
{ keys = "s", cmd = ":new<CR>", opts = { desc = "Scratch buffers" } },
|
||||
{ keys = "t", cmd = ":BufferLineTogglePin<CR>", opts = { desc = "Pin Buffer" } },
|
||||
{ keys = "y", cmd = ":%y+<CR>", opts = { desc = "Copy Buffer to Clipboard" } },
|
||||
},
|
||||
c = { -- +code/compile
|
||||
{ keys = "R", cmd = vim.lsp.buf.rename, opts = { desc = "Rename symbol under cursor" } },
|
||||
{ keys = "f", cmd = formatFx, opts = { desc = "Format buffer" } },
|
||||
},
|
||||
f = { -- +file/find
|
||||
{ keys = "n", cmd = ":new<CR>", opts = { desc = "New File" } },
|
||||
{ keys = "s", cmd = ":write<CR>", opts = { desc = "Save File" } },
|
||||
{ keys = "S", cmd = ":wall<CR>", opts = { desc = "Save All Files" } },
|
||||
{ keys = "D", cmd = "!trash-rm %<CR>", opts = { desc = "Delete current file" } },
|
||||
-- { keys = "t", cmd = ":NvimTreeFindFileToggle<CR>", opts = { desc = "Toggle File Tree" } },
|
||||
-- { keys = "o", cmd = ":!open %<CR>", opts = { desc = "Open file in default program" } },
|
||||
{ keys = "R", cmd = renameCurrentBuffer, opts = { desc = "Rename current file" } },
|
||||
{ keys = "x", cmd = ":Lazy<CR>", opts = { desc = "Open extension view" } },
|
||||
{ keys = "yy", cmd = ":let @+ = expand('%:p')<CR>", opts = { desc = "Copy file path" } },
|
||||
{ keys = "yY", cmd = ":let @+ = expand('%')<CR>", opts = { desc = "Copy relative file path" } },
|
||||
{ keys = "yn", cmd = ":let @+ = expand('%:t')<CR>", opts = { desc = "Copy file name" } },
|
||||
{ keys = "yN", cmd = ":let @+ = expand('%:t:r')<CR>", opts = { desc = "Copy file name without extension" } },
|
||||
{ keys = "yd", cmd = ":let @+ = expand('%:p:h')<CR>", opts = { desc = "Copy directory path" } },
|
||||
{
|
||||
keys = "yl",
|
||||
cmd = ":let @+ = expand('%:p') . ':' . line('.')<CR>",
|
||||
opts = { desc = "Copy file path with line number" },
|
||||
},
|
||||
{
|
||||
keys = "yL",
|
||||
cmd = ":let @+ = expand('%') . ':' . line('.')<CR>",
|
||||
opts = { desc = "Copy relative file path with line number" },
|
||||
},
|
||||
},
|
||||
g = { -- +git/version control
|
||||
},
|
||||
j = { -- +lsp
|
||||
{ keys = "r", cmd = vim.lsp.buf.references, opts = { desc = "Show current reference" } },
|
||||
},
|
||||
p = { -- +project
|
||||
},
|
||||
q = { -- +quit
|
||||
{ keys = "q", cmd = ":q<CR>", opts = { desc = "Quit" } },
|
||||
{ keys = "Q", cmd = ":qa!<CR>", opts = { desc = "Force Quit" } },
|
||||
{ keys = "w", cmd = ":wq<CR>", opts = { desc = "Write and Quit" } },
|
||||
{ keys = "W", cmd = ":wall<CR>:qa!<CR>", opts = { desc = "Write all and Force Quit" } },
|
||||
},
|
||||
t = { -- +toggle/test
|
||||
{ keys = "f", cmd = ":NvimTreeToggle", opts = { desc = "Toggle File Explorer" } },
|
||||
{ keys = "F", cmd = ":FormatToggle<CR>", opts = { desc = "Toggle autoformat-on-save" } },
|
||||
},
|
||||
u = { -- +ui
|
||||
{ keys = " ", cmd = ":set list!", opts = { desc = "Toggle show all symbols" } },
|
||||
},
|
||||
w = { -- +window
|
||||
{ keys = "h", cmd = "<C-w>h", opts = { desc = "Left Window" } },
|
||||
{ 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 = "H", cmd = "<C-w>H", opts = { desc = "Move Window Left" } },
|
||||
{ keys = "N", cmd = "<C-w>J", opts = { desc = "Move Window Down" } },
|
||||
{ keys = "E", cmd = "<C-w>K", opts = { desc = "Move Window Up" } },
|
||||
{ keys = "I", cmd = "<C-w>L", opts = { desc = "Move Window Right" } },
|
||||
{ keys = "-", cmd = ":split<CR>", opts = { desc = "Split to down" } },
|
||||
{ keys = "|", cmd = ":vsplit<CR>", opts = { desc = "Split to right" } },
|
||||
{ keys = "/", cmd = ":vsplit<CR>", opts = { desc = "Split to right" } },
|
||||
{ keys = "d", cmd = "<C-w>c", opts = { desc = "Close Window" } },
|
||||
{ keys = "D", cmd = "<C-w>o", opts = { desc = "Close Other Windows" } },
|
||||
{ keys = "r", cmd = "<C-w>r", opts = { desc = "Rotate Windows" } },
|
||||
{ keys = "R", cmd = "<C-w>R", opts = { desc = "Reverse Rotate Windows" } },
|
||||
{ keys = "t", cmd = "<C-w>T", opts = { desc = "Move Window to New Tab" } },
|
||||
{ keys = "]", cmd = ":resize +5<CR>", opts = { desc = "Increase Window Size" } },
|
||||
{ keys = "[", cmd = ":resize -5<CR>", opts = { desc = "Decrease Window Size" } },
|
||||
{ keys = "M", cmd = ":resize<CR>:vertical resize<CR>", opts = { desc = "Maximize window size" } },
|
||||
},
|
||||
}
|
||||
|
||||
for key, maps in pairs(leader_mappings) do
|
||||
if key == "general" then
|
||||
apply_mappings(maps, "<leader>")
|
||||
else
|
||||
apply_mappings(maps, "<leader>" .. key)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
43
home/dot_config/nvim/lua/keymaps/lspkeys.lua
Normal file
43
home/dot_config/nvim/lua/keymaps/lspkeys.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
local M = {
|
||||
{ keys = "gd", cmd = vim.lsp.buf.definition, opts = { desc = "Goto Definition" } },
|
||||
{ keys = "<C-CR>", cmd = vim.lsp.buf.definition, opts = { desc = "Goto Definition" } },
|
||||
{ keys = "gD", cmd = vim.lsp.buf.declaration, opts = { desc = "Goto Declaration" } },
|
||||
{ keys = "gr", cmd = vim.lsp.buf.references, opts = { desc = "Goto References" } },
|
||||
{ keys = "gi", cmd = vim.lsp.buf.implementation, opts = { desc = "Goto Implementation" } },
|
||||
{ keys = "<leader>,", cmd = vim.lsp.buf.code_action, opts = { desc = "Code Action" } },
|
||||
{ keys = "ga", cmd = vim.lsp.buf.code_action, opts = { desc = "Code Action" } },
|
||||
{ keys = "gh", cmd = vim.lsp.buf.hover, opts = { desc = "Show hover" } },
|
||||
-- [c]hange [d]efinition
|
||||
{ keys = "cd", cmd = vim.lsp.buf.rename, opts = { desc = "Rename symbol under cursor" } },
|
||||
}
|
||||
|
||||
-- local function smart_split_definition()
|
||||
-- local width = vim.api.nvim_win_get_width(0)
|
||||
-- if width > 80 then -- Adjust 80 to your preference
|
||||
-- vim.api.nvim_command("vsp")
|
||||
-- else
|
||||
-- vim.api.nvim_command("sp")
|
||||
-- end
|
||||
-- vim.lsp.buf.definition()
|
||||
-- end
|
||||
-- vim.keymap.set("n", "<C-w>d", smart_split_definition, { desc = "Go to Definition (Smart Split)" })
|
||||
|
||||
local function smart_split(func)
|
||||
local width = vim.api.nvim_win_get_width(0)
|
||||
if width > 80 then
|
||||
vim.api.nvim_command("vsp")
|
||||
else
|
||||
vim.api.nvim_command("sp")
|
||||
end
|
||||
func()
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<C-w>d", function()
|
||||
smart_split(vim.lsp.buf.definition)
|
||||
end, { desc = "Go to Definition (Smart Split)" })
|
||||
|
||||
vim.keymap.set("n", "<C-w>D", function()
|
||||
smart_split(vim.lsp.buf.declaration)
|
||||
end, { desc = "Go to Declaration (Smart Split)" })
|
||||
|
||||
return M
|
||||
10
home/dot_config/nvim/lua/keymaps/modifier.lua
Normal file
10
home/dot_config/nvim/lua/keymaps/modifier.lua
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
local keymaps_modifier = {
|
||||
-- Use C-w to move between windows
|
||||
-- { keys = "<C-w>h", cmd = "<C-w>h", opts = { desc = "left Window" } },
|
||||
-- { keys = "<C-w>n", cmd = "<C-w>j", opts = { desc = "Down Window" } },
|
||||
-- { keys = "<C-w>e", cmd = "<C-w>k", opts = { desc = "Up Window" } },
|
||||
-- { keys = "<C-w>i", cmd = "<C-w>l", opts = { desc = "Right Window" } },
|
||||
{ keys = "<A-x>", cmd = "<Cmd>FzfLua commands<CR>", opts = { desc = "Commands" } },
|
||||
}
|
||||
|
||||
return keymaps_modifier
|
||||
87
home/dot_config/nvim/lua/keymaps/nvim-tree.lua
Normal file
87
home/dot_config/nvim/lua/keymaps/nvim-tree.lua
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
local M = {}
|
||||
|
||||
M.event = "BufEnter"
|
||||
|
||||
M.global = {
|
||||
{ mode = "n", keys = "<leader>E", cmd = ":NvimTreeToggle<CR>" },
|
||||
{ mode = "n", keys = "<A-0>", cmd = ":NvimTreeFindFileToggle<CR>" },
|
||||
}
|
||||
|
||||
function M.plugin(api, opts)
|
||||
-- mode is set to "n" by default, in `./lua/plugins/nvim-tree.lua`
|
||||
return {
|
||||
-- Toggle
|
||||
{ keys = "<leader>e", cmd = ":NvimTreeToggle<CR>", opts = opts("Toggle") },
|
||||
-- Arrow 箭头 hnei
|
||||
{ keys = "h", cmd = api.node.navigate.parent_close, opts = opts("Close node") },
|
||||
{ keys = "i", cmd = api.node.open.edit, opts = opts("Open") },
|
||||
{ keys = "H", cmd = api.tree.toggle_hidden_filter, opts = opts("Toggle Dotfiles") },
|
||||
{ keys = "N", cmd = api.node.navigate.sibling.next, opts = opts("Next Sibling") },
|
||||
{ keys = "E", cmd = api.node.navigate.sibling.prev, opts = opts("Previous Sibling") },
|
||||
{ keys = "I", cmd = api.tree.toggle_gitignore_filter, opts = opts("Toggle GitIgnored") },
|
||||
-- CONTROL KEYS 控制键
|
||||
{ keys = "<BS>", cmd = api.node.navigate.parent_close, opts = opts("Close node") },
|
||||
{ keys = "<CR>", cmd = api.node.open.edit, opts = opts("Open") },
|
||||
{ keys = "<Tab>", cmd = api.node.open.preview, opts = opts("Open Preview") },
|
||||
-- Alpha 字母键
|
||||
{ keys = "a", cmd = api.fs.create, opts = opts("Create") },
|
||||
{ keys = "A", cmd = api.fs.create, opts = opts("Create") },
|
||||
{ keys = "bd", cmd = api.marks.bulk.delete, opts = opts("Delete Bookmarked") },
|
||||
{ keys = "bt", cmd = api.marks.bulk.trash, opts = opts("Trash Bookmarked") },
|
||||
{ keys = "bmv", cmd = api.marks.bulk.move, opts = opts("Move Bookmarked") },
|
||||
{ keys = "B", cmd = api.tree.toggle_no_buffer_filter, opts = opts("Toggle Filter: No Buffer") },
|
||||
{ keys = "c", cmd = api.fs.copy.node, opts = opts("Copy") },
|
||||
{ keys = "C", cmd = api.fs.copy.filename, opts = opts("Copy") },
|
||||
{ keys = "d", cmd = api.fs.remove, opts = opts("Delete") },
|
||||
{ keys = "D", cmd = api.fs.trash, opts = opts("Trash") },
|
||||
{ keys = "]e", cmd = api.node.navigate.diagnostics.next, opts = opts("Next Diagnostic") },
|
||||
{ keys = "[e", cmd = api.node.navigate.diagnostics.prev, opts = opts("Prev Diagnostic") },
|
||||
{ keys = "F", cmd = api.live_filter.clear, opts = opts("Live Filter: Clear") },
|
||||
{ keys = "f", cmd = api.live_filter.start, opts = opts("Live Filter: Start") },
|
||||
{ keys = "[g", cmd = api.node.navigate.git.prev, opts = opts("Prev Git") },
|
||||
{ keys = "]g", cmd = api.node.navigate.git.next, opts = opts("Next Git") },
|
||||
{ keys = "L", cmd = api.node.open.toggle_group_empty, opts = opts("Toggle Group Empty") },
|
||||
{ keys = "M", cmd = api.tree.toggle_no_bookmark_filter, opts = opts("Toggle Filter: No Bookmark") },
|
||||
{ keys = "m", cmd = api.marks.toggle, opts = opts("Toggle Bookmark") },
|
||||
{ keys = "o", cmd = api.node.open.edit, opts = opts("Open") },
|
||||
{ keys = "O", cmd = api.node.open.no_window_picker, opts = opts("Open: No Window Picker") },
|
||||
{ keys = "p", cmd = api.fs.paste, opts = opts("Paste") },
|
||||
{ keys = "P", cmd = api.node.navigate.parent, opts = opts("Parent Directory") },
|
||||
{ keys = "q", cmd = api.tree.close, opts = opts("Close") },
|
||||
{ keys = "r", cmd = api.fs.rename, opts = opts("Rename") },
|
||||
{ keys = "R", cmd = api.tree.reload, opts = opts("Refresh") },
|
||||
{ keys = "s", cmd = api.node.run.system, opts = opts("Run System") },
|
||||
{ keys = "S", cmd = api.tree.search_node, opts = opts("Search") },
|
||||
{ keys = "u", cmd = api.fs.rename_full, opts = opts("Rename: Full Path") },
|
||||
{ keys = "U", cmd = api.tree.toggle_custom_filter, opts = opts("Toggle Filter: Hidden") },
|
||||
{ keys = "W", cmd = api.tree.collapse_all, opts = opts("Collapse") },
|
||||
{ keys = "x", cmd = api.fs.cut, opts = opts("Cut") },
|
||||
{ keys = "y", cmd = api.fs.copy.relative_path, opts = opts("Copy Relative Path") },
|
||||
{ keys = "Y", cmd = api.fs.copy.absolute_path, opts = opts("Copy Absolute Path") },
|
||||
-- From Directory Opus
|
||||
{ keys = "#", cmd = "<Cmd>set relativenumber!<CR>", opts = opts("Toggle Relative Number") },
|
||||
-- Numeric 数字键
|
||||
{ keys = "!", cmd = api.node.run.cmd, opts = opts("Run Command") },
|
||||
-- Non-Alphanumeric 非字母数字键
|
||||
{ keys = "?", cmd = api.tree.toggle_help, opts = opts("Help") },
|
||||
{ keys = ">", cmd = api.node.navigate.sibling.next, opts = opts("Next Sibling") },
|
||||
{ keys = "<", cmd = api.node.navigate.sibling.prev, opts = opts("Previous Sibling") },
|
||||
{ keys = ".", cmd = api.node.run.cmd, opts = opts("Run Command") },
|
||||
{ keys = ";", cmd = api.node.run.cmd, opts = opts("Run Command") },
|
||||
{ keys = "-", cmd = api.tree.change_root_to_parent, opts = opts("Up") },
|
||||
-- MOD KEYS Ctrl+
|
||||
{ keys = "<C-]>", cmd = api.tree.change_root_to_node, opts = opts("CD") },
|
||||
{ keys = "<C-e>", cmd = api.node.open.replace_tree_buffer, opts = opts("Open: In Place") },
|
||||
{ keys = "<C-k>", cmd = api.node.show_info_popup, opts = opts("Info") },
|
||||
{ keys = "<C-r>", cmd = api.fs.rename_sub, opts = opts("Rename: Omit Filename") },
|
||||
{ keys = "<C-t>", cmd = api.node.open.tab, opts = opts("Open: New Tab") },
|
||||
{ keys = "<C-v>", cmd = api.node.open.vertical, opts = opts("Open: Vertical Split") },
|
||||
{ keys = "<C-h>", cmd = api.node.open.horizontal, opts = opts("Open: Horizontal Split") },
|
||||
{ keys = "<A-0>", cmd = ":b#<CR>", opts = opts("Focus to previous buffer") },
|
||||
-- Mouse 鼠标键
|
||||
{ keys = "<2-LeftMouse>", cmd = api.node.open.edit, opts = opts("Open") },
|
||||
{ keys = "<2-RightMouse>", cmd = api.tree.change_root_to_node, opts = opts("CD") },
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
36
home/dot_config/nvim/lua/keymaps/user-command.lua
Normal file
36
home/dot_config/nvim/lua/keymaps/user-command.lua
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
vim.api.nvim_create_user_command("Format", function(args)
|
||||
local range = nil
|
||||
if args.count ~= -1 then
|
||||
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
|
||||
range = {
|
||||
start = { args.line1, 0 },
|
||||
["end"] = { args.line2, end_line:len() },
|
||||
}
|
||||
end
|
||||
require("conform").format({ async = true, lsp_format = "fallback", range = range })
|
||||
end, { range = true })
|
||||
|
||||
vim.api.nvim_create_user_command("FormatToggle", function(args)
|
||||
local buffer_local = args.bang
|
||||
if buffer_local then
|
||||
-- Toggle buffer-local formatting
|
||||
vim.b.disable_autoformat = not vim.b.disable_autoformat
|
||||
else
|
||||
-- Toggle global formatting
|
||||
vim.g.disable_autoformat = not vim.g.disable_autoformat
|
||||
end
|
||||
|
||||
-- Print current status
|
||||
local scope = buffer_local and "buffer" or "global"
|
||||
local status = buffer_local and vim.b.disable_autoformat or vim.g.disable_autoformat
|
||||
print(string.format("Format-on-save %s: %s", scope, status and "disabled" or "enabled"))
|
||||
end, {
|
||||
desc = "Toggle autoformat-on-save (use ! for buffer-local)",
|
||||
bang = true,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command("Reload", function()
|
||||
vim.cmd("luafile ~/.config/nvim/init.lua")
|
||||
end, {
|
||||
desc = "Reload Neovim configuration",
|
||||
})
|
||||
33
home/dot_config/nvim/lua/keymaps/utils.lua
Normal file
33
home/dot_config/nvim/lua/keymaps/utils.lua
Normal 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
|
||||
9
home/dot_config/nvim/lua/keymaps/visual-multi.lua
Normal file
9
home/dot_config/nvim/lua/keymaps/visual-multi.lua
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
-- Note that this plugin is a fork for colemak
|
||||
-- Use mouse to select multiple cursors
|
||||
vim.g.VM_mouse_mappings = 1
|
||||
-- Disable default mappings
|
||||
|
||||
vim.g.VM_maps = {
|
||||
["Add Cursor Down"] = "<A-n>",
|
||||
["Add Cursor Up"] = "<A-e>",
|
||||
}
|
||||
42
home/dot_config/nvim/lua/keymaps/which.lua
Normal file
42
home/dot_config/nvim/lua/keymaps/which.lua
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
-- local wk = require("which-key")
|
||||
-- wk.add({
|
||||
-- -- https://github.com/folke/which-key.nvim/tree/main?tab=readme-ov-file#%EF%B8%8F-mappings
|
||||
-- {
|
||||
-- -- Nested mappings are allowed and can be added in any order
|
||||
-- -- Most attributes can be inherited or overridden on any level
|
||||
-- -- There's no limit to the depth of nesting
|
||||
-- mode = { "n" },
|
||||
-- { "<leader>b", group = "Buffer" }, -- no need to specify mode since it's inherited
|
||||
-- { "<leader>c", group = "Code/Compile" },
|
||||
-- { "<leader>f", group = "File" },
|
||||
-- { "<leader>p", group = "Project", icon = "" },
|
||||
-- { "<leader>q", group = "Quit" },
|
||||
-- { "<leader>t", group = "Toggle" },
|
||||
-- { "<leader>u", group = "UI" },
|
||||
-- { "<leader>w", group = "Window" },
|
||||
-- },
|
||||
-- { -- https://github.com/folke/which-key.nvim/blob/1f8d414f61e0b05958c342df9b6a4c89ce268766/lua/which-key/plugins/presets.lua#L57-L98
|
||||
-- -- text objects
|
||||
-- mode = { "o", "x" },
|
||||
-- { "l", group = "inside" },
|
||||
-- { 'l"', desc = 'inner " string' },
|
||||
-- { "l'", desc = "inner ' string" },
|
||||
-- { "l(", desc = "inner [(])" },
|
||||
-- { "l)", desc = "inner [(])" },
|
||||
-- { "l<", desc = "inner <>" },
|
||||
-- { "l>", desc = "inner <>" },
|
||||
-- { "lB", desc = "inner [{]}" },
|
||||
-- { "lW", desc = "inner WORD" },
|
||||
-- { "l[", desc = "inner []" },
|
||||
-- { "l]", desc = "inner []" },
|
||||
-- { "l`", desc = "inner ` string" },
|
||||
-- { "lb", desc = "inner [(])" },
|
||||
-- { "lp", desc = "inner paragraph" },
|
||||
-- { "ls", desc = "inner sentence" },
|
||||
-- { "lt", desc = "inner tag block" },
|
||||
-- { "lw", desc = "inner word" },
|
||||
-- { "l{", desc = "inner [{]}" },
|
||||
-- { "l}", desc = "inner [{]}" },
|
||||
-- { "i", desc = "Right" },
|
||||
-- },
|
||||
-- })
|
||||
Loading…
Add table
Add a link
Reference in a new issue