mirror of
https://github.com/js0ny/dotfiles.git
synced 2025-12-21 08:43:00 +00:00
feat(nvim): Add support for which key
This commit is contained in:
parent
9b90b02442
commit
1b2fc3015b
21 changed files with 276 additions and 206 deletions
2
tools/nvim/.gitignore
vendored
2
tools/nvim/.gitignore
vendored
|
|
@ -1,2 +0,0 @@
|
|||
lazy-lock.json
|
||||
./lua/config/keymaps/obsidian-nvim.lua
|
||||
|
|
@ -21,13 +21,9 @@ vim.api.nvim_create_autocmd("FileType", {
|
|||
|
||||
-- 加载配置
|
||||
require("config.options")
|
||||
-- 加载键位映射
|
||||
require("config.keymaps")
|
||||
|
||||
-- 加载插件
|
||||
require("config.plugins")
|
||||
|
||||
-- 加载主题
|
||||
require("config.colorscheme")
|
||||
|
||||
-- vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
|
||||
-- 加载键位映射
|
||||
require("config.keymaps")
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ opt.linebreak = true
|
|||
-- Indentation
|
||||
opt.expandtab = true
|
||||
opt.shiftwidth = 4
|
||||
opt.tabstop = 4
|
||||
opt.shiftround = true
|
||||
|
||||
-- Case
|
||||
|
|
|
|||
|
|
@ -3,20 +3,14 @@
|
|||
--- for available server and name
|
||||
local M = {}
|
||||
M.servers = {
|
||||
"arduino_language_server", -- Arduino
|
||||
"bashls", -- Bash
|
||||
"clangd", -- C/C++
|
||||
-- "cmake", -- CMake
|
||||
"eslint", -- JavaScript
|
||||
"gopls", -- Go
|
||||
"html", -- HTML
|
||||
"julials", -- Julia
|
||||
"lua_ls", -- Lua
|
||||
"omnisharp", -- C# & F#
|
||||
"powershell_es", -- PowerShell
|
||||
"pyright", -- Python
|
||||
"rust_analyzer", -- Rust
|
||||
"taplo", -- TOML
|
||||
"vimls", -- vimscript
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,39 @@
|
|||
local mode_arrow = { "n", "v", "o", "s", "x" }
|
||||
|
||||
local keymaps_basic = { -- Modification of Original Keymap - Colemak
|
||||
{ mode = mode_arrow, keys = "n", cmd = "j", desc = "Down" },
|
||||
{ mode = mode_arrow, keys = "e", cmd = "k", desc = "Up" },
|
||||
{ mode = mode_arrow, keys = "i", cmd = "l", desc = "Right" },
|
||||
-- https://github.com/LazyVim/LazyVim/blob/d1529f650fdd89cb620258bdeca5ed7b558420c7/lua/lazyvim/config/keymaps.lua#L8
|
||||
{
|
||||
mode = mode_arrow,
|
||||
keys = "n",
|
||||
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 = "Up", expr = true, silent = true },
|
||||
},
|
||||
{
|
||||
mode = mode_arrow,
|
||||
keys = "e",
|
||||
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 = mode_arrow, keys = "h", cmd = "h", opts = { desc = "Left", silent = true } },
|
||||
{ mode = mode_arrow, keys = "i", cmd = "l", opts = { desc = "Right", silent = true } },
|
||||
{ keys = "H", cmd = ":bprevious<CR>" },
|
||||
{ keys = "N", cmd = "5j" },
|
||||
{ keys = "E", cmd = "5k" },
|
||||
{ keys = "I", cmd = ":bnext<CR>" },
|
||||
-- Text object implementation
|
||||
{ mode = { "n", "o", "x" }, keys = "l", cmd = "i", group = "inside" },
|
||||
{ mode = { "n", "o", "x" }, keys = "l", cmd = "i", opts = { desc = "inside" } },
|
||||
{ keys = "L", cmd = "I" },
|
||||
{ keys = "k", cmd = "n" },
|
||||
{ keys = "K", cmd = "N" },
|
||||
|
|
|
|||
|
|
@ -15,22 +15,24 @@ 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)
|
||||
|
||||
M.nvim_tree_keymaps = require("keymaps.nvim-tree").plugin
|
||||
|
||||
--- `map` default for `cmp.mapping`
|
||||
function M.cmp_nvim_keymaps(map)
|
||||
return {
|
||||
{ keys = "<C-n>", cmd = map.select_next_item(), desc = "Select next completion item" },
|
||||
{ keys = "<C-p>", cmd = map.select_prev_item(), desc = "Select previous completion item" },
|
||||
{ keys = "<C-y>", cmd = map.confirm({ select = true }), desc = "Confirm completion" },
|
||||
{ keys = "<Tab>", cmd = map.confirm({ select = true }), desc = "Confirm completion" },
|
||||
{ keys = "<C-Space>", cmd = map.complete(), desc = "Trigger completion" },
|
||||
{ keys = "<C-e>", cmd = map.abort(), desc = "Abort completion" },
|
||||
{ keys = "<C-n>", cmd = map.select_next_item(), opts = { desc = "Select next completion item" } },
|
||||
{ keys = "<C-p>", cmd = map.select_prev_item(), opts = { desc = "Select previous completion item" } },
|
||||
{ keys = "<C-y>", cmd = map.confirm({ select = true }), opts = { desc = "Confirm completion" } },
|
||||
{ keys = "<Tab>", cmd = map.confirm({ select = true }), opts = { desc = "Confirm completion" } },
|
||||
{ keys = "<C-Space>", cmd = map.complete(), opts = { desc = "Trigger completion" } },
|
||||
{ keys = "<C-e>", cmd = map.abort(), opts = { desc = "Abort completion" } },
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -46,6 +48,7 @@ vim.api.nvim_create_autocmd("FileType", {
|
|||
end,
|
||||
})
|
||||
|
||||
require("keymaps.language")
|
||||
-- which-key.nvim
|
||||
require("keymaps.which")
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -25,4 +25,27 @@ 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
|
||||
|
|
|
|||
|
|
@ -27,139 +27,107 @@ local renameCurrentBuffer = function()
|
|||
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_general = {
|
||||
{ keys = "<space>", cmd = ":Telescope find_files<CR>", desc = "Find Files" },
|
||||
{ keys = "/", cmd = ":Telescope live_grep<CR>", desc = "Grep Files" },
|
||||
{ keys = "-", cmd = ":split<CR>", desc = "Split to down" },
|
||||
{ keys = "\\", cmd = ":vsplit<CR>", desc = "Split to right" },
|
||||
{ keys = "|", cmd = ":vsplit<CR>", desc = "Split to right" },
|
||||
{ keys = "h", cmd = "<C-w>h", desc = "Left Window" },
|
||||
{ keys = "n", cmd = "<C-w>j", desc = "Down Window" },
|
||||
{ keys = "e", cmd = "<C-w>k", desc = "Up Window" },
|
||||
{ keys = "i", cmd = "<C-w>l", desc = "Right Window" },
|
||||
local leader_mappings = {
|
||||
general = {
|
||||
{ keys = "<space>", 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" } },
|
||||
},
|
||||
b = { -- +buffer
|
||||
{ keys = "a", cmd = ":Alpha<CR>", opts = { desc = "Dashboard" } },
|
||||
{ keys = "b", cmd = ":Telescope buffers<CR>", opts = { desc = "List Buffers" } },
|
||||
{ keys = "d", cmd = ":bdelete<CR>", opts = { desc = "Delete Buffer" } },
|
||||
{ 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 = ":Telescope buffers<CR>", opts = { desc = "Search buffers" } },
|
||||
},
|
||||
c = { -- +code/compile
|
||||
{ keys = "r", cmd = ":RunCode<CR>", opts = { desc = "Run code" } },
|
||||
{ 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 = "s", cmd = ":Telescope live_grep<CR>", opts = { desc = "Grep Files" } },
|
||||
{ keys = "b", cmd = ":Telescope buffers<CR>", opts = { desc = "List Buffers" } },
|
||||
{ keys = "e", cmd = ":NvimTreeToggle<CR>", opts = { desc = "Toggle File Explorer" } },
|
||||
{ keys = "t", cmd = ":FloatermToggle<CR>", opts = { desc = "toggle visibility of the float terminal" } },
|
||||
{ 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 %", opts = { desc = "Open file in default program" } },
|
||||
{ keys = "R", cmd = renameCurrentBuffer, opts = { desc = "Rename current file" } },
|
||||
},
|
||||
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
|
||||
{ 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" } },
|
||||
},
|
||||
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 = "-", cmd = ":split<CR>", opts = { desc = "Split to down" } },
|
||||
{ keys = "|", cmd = ":vsplit<CR>", opts = { desc = "Split to right" } },
|
||||
{ keys = "c", cmd = "<C-w>c", opts = { desc = "Close Window" } },
|
||||
{ keys = "o", 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 = "H", cmd = ":vertical resize -5<CR>", opts = { desc = "Decrease Window Height" } },
|
||||
{ keys = "N", cmd = ":resize +5<CR>", opts = { desc = "Increase Window Height" } },
|
||||
{ keys = "E", cmd = ":vertical resize +5<CR>", opts = { desc = "Increase Window Width" } },
|
||||
{ keys = "I", cmd = ":resize -5<CR>", opts = { desc = "Decrease Window Width" } },
|
||||
},
|
||||
}
|
||||
|
||||
for _, map in ipairs(leader_general) do
|
||||
map.keys = "<leader>" .. map.keys
|
||||
table.insert(M, map)
|
||||
end
|
||||
|
||||
local leader_q = { -- leader q: Quit
|
||||
{ keys = "q", cmd = ":q<CR>", desc = "Quit" },
|
||||
{ keys = "Q", cmd = ":qa!<CR>", desc = "Force Quit" },
|
||||
{ keys = "w", cmd = ":wq<CR>", desc = "Write and Quit" },
|
||||
{ keys = "W", cmd = ":wall<CR>:qa!<CR>", desc = "Write all and Force Quit" },
|
||||
}
|
||||
|
||||
local leader_w = { -- leader w: Windows Management
|
||||
{ keys = "h", cmd = "<C-w>h", desc = "Left Window" },
|
||||
{ keys = "n", cmd = "<C-w>j", desc = "Down Window" },
|
||||
{ keys = "e", cmd = "<C-w>k", desc = "Up Window" },
|
||||
{ keys = "i", cmd = "<C-w>l", desc = "Right Window" },
|
||||
{ keys = "-", cmd = ":split<CR>", desc = "Split to down" },
|
||||
{ keys = "|", cmd = ":vsplit<CR>", desc = "Split to right" },
|
||||
{ keys = "c", cmd = "<C-w>c", desc = "Close Window" },
|
||||
{ keys = "o", cmd = "<C-w>o", desc = "Close Other Windows" },
|
||||
{ keys = "r", cmd = "<C-w>r", desc = "Rotate Windows" },
|
||||
{ keys = "R", cmd = "<C-w>R", desc = "Reverse Rotate Windows" },
|
||||
{ keys = "t", cmd = "<C-w>T", desc = "Move Window to New Tab" },
|
||||
{ keys = "H", cmd = ":vertical resize -5<CR>", desc = "Decrease Window Height" },
|
||||
{ keys = "N", cmd = ":resize +5<CR>", desc = "Increase Window Height" },
|
||||
{ keys = "E", cmd = ":vertical resize +5<CR>", desc = "Increase Window Width" },
|
||||
{ keys = "I", cmd = ":resize -5<CR>", desc = "Decrease Window Width" },
|
||||
}
|
||||
|
||||
local leader_f = { -- <leader>f: +files/find
|
||||
{ keys = "f", cmd = ":Telescope fd<CR>", desc = "Find Files" },
|
||||
{ keys = "s", cmd = ":Telescope live_grep<CR>", desc = "Grep Files" },
|
||||
{ keys = "b", cmd = ":Telescope buffers<CR>", desc = "List Buffers" },
|
||||
{ keys = "e", cmd = ":NvimTreeToggle<CR>", desc = "Toggle File Explorer" },
|
||||
{ keys = "t", cmd = ":FloatermToggle<CR>", desc = "toggle visibility of the float terminal" },
|
||||
{ keys = "T", cmd = ":FloatermNew<CR>", desc = "Spawn a float terminal" },
|
||||
{ keys = "h", cmd = ":Telescope oldfiles<CR>", desc = "Search history files" },
|
||||
{ keys = "c", cmd = ":Telescope find_files cwd=~/.config/nvim<CR>", desc = "Search Config" },
|
||||
{ keys = "o", cmd = ":!open %", desc = "Open file in default program" },
|
||||
{ keys = "R", cmd = renameCurrentBuffer, desc = "Rename current file" },
|
||||
}
|
||||
|
||||
local leader_p = { -- leader p: Project
|
||||
{ keys = "p", cmd = ":Telescope projects<CR>", desc = "List all Projects" },
|
||||
{ keys = "g", cmd = ":Telescope projects<CR>", desc = "List all Git Projects" },
|
||||
{ keys = "s", cmd = ":Telescope session-lens<CR>", desc = "List all sessions" },
|
||||
}
|
||||
|
||||
local leader_b = { -- <leader>b: +buffer
|
||||
{ keys = "a", cmd = ":Alpha<CR>", desc = "Dashboard" },
|
||||
{ keys = "b", cmd = ":Telescope buffers<CR>", desc = "List Buffers" },
|
||||
{ keys = "d", cmd = ":bdelete<CR>", desc = "Delete Buffer" },
|
||||
{ keys = "h", cmd = ":bprevious<CR>", desc = "Previous Buffer" },
|
||||
{ keys = "i", cmd = ":bnext<CR>", desc = "Next Buffer" },
|
||||
{ keys = "H", cmd = ":bfirst<CR>", desc = "First Buffer" },
|
||||
{ keys = "I", cmd = ":blast<CR>", desc = "Last Buffer" },
|
||||
{ keys = "0", cmd = ":bfirst<CR>", desc = "First Buffer" },
|
||||
{ keys = "^", cmd = ":bfirst<CR>", desc = "First Buffer" },
|
||||
{ keys = "$", cmd = ":blast<CR>", desc = "Last Buffer" },
|
||||
-- { keys = "s", cmd = ":Telescope buffers<CR>", desc = "Search buffers" },
|
||||
}
|
||||
|
||||
local leader_t = { -- <leader>t: +toggle/test
|
||||
{ keys = "f", cmd = ":NvimTreeToggle", desc = "Toggle File Explorer" },
|
||||
{ keys = "F", cmd = ":FormatToggle<CR>", desc = "Toggle autoformat-on-save" },
|
||||
{ keys = "t", cmd = ":FloatermToggle<CR>", desc = "toggle visibility of the float terminal" },
|
||||
}
|
||||
|
||||
local leader_c = { -- <leader>c: +code/compile
|
||||
{ keys = "r", cmd = ":RunCode<CR>", desc = "Run code" },
|
||||
{ keys = "e", cmd = ":Telescope diagnostics<CR>", desc = "Navigate errors/warnings" },
|
||||
{ keys = "f", cmd = formatFx, desc = "Format buffer" },
|
||||
{ keys = "s", cmd = ":Telescope treesitter<CR>", desc = "Search symbols" },
|
||||
{ keys = "S", cmd = ":Telescope grep_string<CR>", desc = "Search current symbol" },
|
||||
}
|
||||
|
||||
local leader_u = { -- <leader>u: +ui
|
||||
{ keys = "i", cmd = ":Telescope colorscheme<CR>", desc = "Change colorscheme" },
|
||||
}
|
||||
|
||||
for _, map in ipairs(leader_q) do
|
||||
map.keys = "<leader>q" .. map.keys
|
||||
table.insert(M, map)
|
||||
end
|
||||
|
||||
for _, map in ipairs(leader_w) do
|
||||
map.keys = "<leader>w" .. map.keys
|
||||
table.insert(M, map)
|
||||
end
|
||||
|
||||
for _, map in ipairs(leader_f) do
|
||||
map.keys = "<leader>f" .. map.keys
|
||||
table.insert(M, map)
|
||||
end
|
||||
|
||||
for _, map in ipairs(leader_b) do
|
||||
map.keys = "<leader>b" .. map.keys
|
||||
table.insert(M, map)
|
||||
end
|
||||
|
||||
for _, map in ipairs(leader_c) do
|
||||
map.keys = "<leader>c" .. map.keys
|
||||
table.insert(M, map)
|
||||
end
|
||||
|
||||
for _, map in ipairs(leader_t) do
|
||||
map.keys = "<leader>t" .. map.keys
|
||||
table.insert(M, map)
|
||||
end
|
||||
|
||||
for _, map in ipairs(leader_u) do
|
||||
map.keys = "<leader>u" .. map.keys
|
||||
table.insert(M, map)
|
||||
end
|
||||
|
||||
for _, map in ipairs(leader_p) do
|
||||
map.keys = "<leader>p" .. map.keys
|
||||
table.insert(M, map)
|
||||
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
|
||||
|
|
|
|||
8
tools/nvim/lua/keymaps/lspkeys.lua
Normal file
8
tools/nvim/lua/keymaps/lspkeys.lua
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
local M = {
|
||||
{ keys = "gd", 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" } },
|
||||
}
|
||||
|
||||
return M
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
local M = {}
|
||||
|
||||
M.global = {
|
||||
{ mode = "n", keys = "<leader>e", cmd = ":NvimTreeToggle<CR>" },
|
||||
{ mode = "n", keys = "<leader>E", cmd = ":NvimTreeToggle<CR>" },
|
||||
{ mode = "n", keys = "<A-0>", cmd = ":NvimTreeFocus<CR>" },
|
||||
}
|
||||
|
||||
|
|
|
|||
23
tools/nvim/lua/keymaps/which.lua
Normal file
23
tools/nvim/lua/keymaps/which.lua
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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" },
|
||||
{ "<leader>q", group = "Quit" },
|
||||
{ "<leader>t", group = "Toggle" },
|
||||
{ "<leader>u", group = "UI" },
|
||||
{ "<leader>w", group = "Window" },
|
||||
},
|
||||
{
|
||||
"l",
|
||||
mode = { "o", "x" },
|
||||
group = "inside",
|
||||
},
|
||||
})
|
||||
|
|
@ -15,7 +15,7 @@ return {
|
|||
-- require('hover.providers.jira')
|
||||
-- require('hover.providers.dap')
|
||||
-- require('hover.providers.fold_preview')
|
||||
-- require('hover.providers.diagnostic')
|
||||
require("hover.providers.diagnostic")
|
||||
-- require('hover.providers.man')
|
||||
-- require('hover.providers.dictionary')
|
||||
end,
|
||||
|
|
@ -46,4 +46,10 @@ return {
|
|||
vim.o.mousemoveevent = true
|
||||
end,
|
||||
},
|
||||
{
|
||||
"lewis6991/gitsigns.nvim",
|
||||
config = function()
|
||||
require("gitsigns").setup()
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,2 @@
|
|||
-- Entry point of the plugin manager
|
||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
|
||||
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
|
||||
if vim.v.shell_error ~= 0 then
|
||||
vim.api.nvim_echo({
|
||||
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
|
||||
{ out, "WarningMsg" },
|
||||
{ "\nPress any key to exit..." },
|
||||
}, true, {})
|
||||
vim.fn.getchar()
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
require("lazy").setup({
|
||||
{ import = "plugins.appearance" },
|
||||
{ import = "plugins.completion" },
|
||||
{ import = "plugins.fileutils" },
|
||||
{ import = "plugins.lsp" },
|
||||
{ import = "plugins.syntax" },
|
||||
{ import = "plugins.misc" },
|
||||
})
|
||||
require("plugins.lazy-nvim")
|
||||
|
|
|
|||
39
tools/nvim/lua/plugins/lazy-nvim.lua
Normal file
39
tools/nvim/lua/plugins/lazy-nvim.lua
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
-- Bootstrap lazy.nvim
|
||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
|
||||
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
|
||||
if vim.v.shell_error ~= 0 then
|
||||
vim.api.nvim_echo({
|
||||
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
|
||||
{ out, "WarningMsg" },
|
||||
{ "\nPress any key to exit..." },
|
||||
}, true, {})
|
||||
vim.fn.getchar()
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
-- Make sure to setup `mapleader` and `maplocalleader` before
|
||||
-- loading lazy.nvim so that mappings are correct.
|
||||
-- This is also a good place to setup other settings (vim.opt)
|
||||
vim.g.mapleader = " "
|
||||
vim.g.maplocalleader = "\\"
|
||||
|
||||
-- Setup lazy.nvim
|
||||
require("lazy").setup({
|
||||
spec = {
|
||||
-- import your plugins
|
||||
{ import = "plugins.appearance" },
|
||||
{ import = "plugins.completion" },
|
||||
{ import = "plugins.fileutils" },
|
||||
{ import = "plugins.lsp" },
|
||||
{ import = "plugins.syntax" },
|
||||
{ import = "plugins.misc" },
|
||||
},
|
||||
-- Configure any other settings here. See the documentation for more details.
|
||||
-- colorscheme that will be used when installing plugins.
|
||||
-- automatically check for plugin updates
|
||||
checker = { enabled = true },
|
||||
})
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
return {
|
||||
{ import = "plugins.mod.lspconfig" },
|
||||
{
|
||||
"NoahTheDuke/vim-just",
|
||||
ft = { "just" },
|
||||
"neovim/nvim-lspconfig",
|
||||
lazy = false,
|
||||
},
|
||||
{ import = "plugins.mod.render-markdown" },
|
||||
-- { import = "plugins.mod.markview" },
|
||||
|
|
@ -63,4 +62,8 @@ return {
|
|||
},
|
||||
{ import = "plugins.mod.conform-nvim" },
|
||||
{ "nvim-treesitter/nvim-treesitter-context" },
|
||||
{
|
||||
"NoahTheDuke/vim-just",
|
||||
ft = { "just" },
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,25 +7,7 @@ return {
|
|||
} },
|
||||
{ "CRAG666/code_runner.nvim", config = true },
|
||||
{ import = "plugins.mod.obsidian-nvim" },
|
||||
{
|
||||
|
||||
"folke/which-key.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = {
|
||||
-- your configuration comes here
|
||||
-- or leave it empty to use the default settings
|
||||
-- refer to the configuration section below
|
||||
},
|
||||
keys = {
|
||||
{
|
||||
"<leader>?",
|
||||
function()
|
||||
require("which-key").show({ global = false })
|
||||
end,
|
||||
desc = "Buffer Local Keymaps (which-key)",
|
||||
},
|
||||
},
|
||||
},
|
||||
{ import = "plugins.mod.which-keys-nvim" },
|
||||
{
|
||||
"github/copilot.vim",
|
||||
lazy = false,
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ ins_left({
|
|||
ins_left({
|
||||
-- mode component
|
||||
function()
|
||||
return ""
|
||||
return ""
|
||||
end,
|
||||
color = function()
|
||||
-- auto change color according to neovims mode
|
||||
|
|
|
|||
18
tools/nvim/lua/plugins/mod/which-keys-nvim.lua
Normal file
18
tools/nvim/lua/plugins/mod/which-keys-nvim.lua
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
return {
|
||||
"folke/which-key.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = {
|
||||
-- your configuration comes here
|
||||
-- or leave it empty to use the default settings
|
||||
-- refer to the configuration section below
|
||||
},
|
||||
keys = {
|
||||
{
|
||||
"<leader>?",
|
||||
function()
|
||||
require("which-key").show({ global = false })
|
||||
end,
|
||||
desc = "Buffer Local Keymaps (which-key)",
|
||||
},
|
||||
},
|
||||
}
|
||||
4
tools/nvim/playground.txt
Normal file
4
tools/nvim/playground.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(((
|
||||
This is a playground file.
|
||||
{(1 + 2) * 3}
|
||||
)))
|
||||
|
|
@ -17,6 +17,7 @@ noremap N 5j
|
|||
noremap E 5k
|
||||
|
||||
" Similar position to i
|
||||
" The `noremap` implements text-object-like behavior in VSCodeVim
|
||||
noremap l i
|
||||
noremap L I
|
||||
" ne[k]st
|
||||
|
|
@ -29,9 +30,10 @@ noremap J E
|
|||
" Y to yank to end of line
|
||||
noremap Y y$
|
||||
|
||||
noremap <esc> :nohlsearch<CR>
|
||||
|
||||
" 分词版本的w和b,支持中文,需要插件
|
||||
" 为了保证递归解析,而不是打断,使用 `nmap` 而不是 `nnoremap`
|
||||
" 由于 VSCode Vim 的限制,递归解析存在缺陷,目前这种情况,2w 符合预期,但 dw 不符合预期
|
||||
" Comment if you don't use cjk or the plugin
|
||||
nmap w cjkWordHandler.cursorWordEndRight
|
||||
nmap b cjkWordHandler.cursorWordStartLeft
|
||||
|
|
@ -92,7 +94,8 @@ noremap <leader>fC workbench.action.openFolderSettingsFile
|
|||
noremap <leader>fe workbench.view.explorer
|
||||
noremap <leader>fo openInExternalApp.open
|
||||
noremap <leader>fr workbench.action.showAllEditorsByMostRecentlyUsed
|
||||
noremap <leader>fR git.rename " Rename file
|
||||
" Can only rename tracked files
|
||||
noremap <leader>fR git.rename
|
||||
" noremap <leader>fs workbench.action.search.toggleQueryDetails
|
||||
noremap <leader>ft workbench.action.terminal.toggleTerminal
|
||||
noremap <leader>fx workbench.view.extensions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue