breaking: Remove setup script and use chezmoi

This commit is contained in:
js0ny 2025-09-27 02:25:06 +01:00
parent 02bbb24cac
commit 0051a163c3
190 changed files with 118 additions and 3456 deletions

View file

@ -0,0 +1,37 @@
-- This file *currently* contains the colorscheme for lualine (status line)
local M = {}
-- TODO: Change the palatte when the colorscheme changes
if vim.g.colors_name == "catppuccin-latte" then
M.scheme = require("catppuccin.palettes.latte")
else
M.scheme = require("catppuccin.palettes.mocha")
end
M.accent = M.scheme.lavender
M.mode = {
n = M.scheme.sky,
i = M.scheme.green,
v = M.scheme.mauve,
[""] = M.scheme.mauve,
V = M.scheme.mauve,
c = M.scheme.mauve,
no = M.scheme.red,
s = M.scheme.orange,
S = M.scheme.orange,
[""] = M.scheme.orange,
ic = M.scheme.yellow,
R = M.scheme.violet,
Rv = M.scheme.violet,
cv = M.scheme.red,
ce = M.scheme.red,
r = M.scheme.cyan,
rm = M.scheme.cyan,
["r?"] = M.scheme.cyan,
["!"] = M.scheme.red,
t = M.scheme.red,
}
return M

View file

@ -0,0 +1,43 @@
-- Change the colorscheme here, use SPACE u i or :FzfLua colorscheme to change colorscheme
-- https://www.reddit.com/r/neovim/comments/1d3hk1t/automatic_dark_mode_following_system_theme_on/
local function get_system_theme()
-- Default value
local background = 'light'
-- First check whether we are on MacOS
if vim.loop.os_uname().sysname == "Darwin" then
-- Check if 'defaults' is executable
if vim.fn.executable('defaults') ~= 0 then
-- Execute command to check if the macOS appearance is set to Dark
local appleInterfaceStyle = vim.fn.system({ "defaults", "read", "-g", "AppleInterfaceStyle" })
if appleInterfaceStyle:find("Dark") then
background = 'dark'
end
end
-- Check if 'busctl' is executable (part of systemd)
elseif vim.fn.executable('busctl') ~= 0 then
-- Get the current color scheme from xdg-desktop-portal using busctl
local result = vim.fn.system({
"busctl", "--user", "call", "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop",
"org.freedesktop.portal.Settings", "ReadOne", "ss", "org.freedesktop.appearance", "color-scheme"
})
-- The result is in the form of "v u 0" for light and "v u 1" for dark
local color_scheme = result:match("u%s+(%d+)")
if color_scheme == '1' then
background = 'dark'
end
else
end
return background
end
if get_system_theme() == 'dark' then
vim.o.background = 'dark'
vim.cmd.colorscheme("catppuccin")
else
vim.o.background = 'light'
-- vim.cmd.colorscheme("rose-pine")
vim.cmd.colorscheme("catppuccin")
end

View file

@ -0,0 +1,7 @@
local signs = require("config.icons").diagnostics
-- This provides the diagnostics signs near the line numbers
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end

View file

@ -0,0 +1,51 @@
-- icons.lua
-- All icons used in the configuration are defined in this file.
-- Currently are only used in diagnostics, lualine, gitsigns
local M = {
diagnostics = {
Error = "",
Warning = "",
Hint = "",
Information = "",
},
lsp = "",
indent = "",
git = {
Change = "",
Add = "",
Delete = "",
Rename = "",
Branch = "",
},
lsp_kind = {
Text = "󰉿",
Method = "󰆧",
Function = "󰊕",
Constructor = "",
Field = "󰜢",
Variable = "󰀫",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "󰑭",
Value = "󰎠",
Enum = "",
Keyword = "󰌋",
Snippet = "",
Color = "󰏘",
File = "󰈙",
Reference = "󰈇",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "󰙅",
Event = "",
Operator = "󰆕",
TypeParameter = "󰅲",
Copilot = "",
},
telescope = "",
}
return M

View file

@ -0,0 +1,2 @@
-- Entry point of keymaps configuration
require("keymaps")

View file

@ -0,0 +1,31 @@
local nvim_version = vim.version()
if nvim_version.minor ~= 11 then
return
end
vim.diagnostic.config({
virtual_lines = true,
})
-- vim.lsp.enable({
-- "clangd",
-- "luals",
-- })
local lsp_configs = {}
for _, v in ipairs(vim.api.nvim_get_runtime_file('lsp/*', true)) do
local name = vim.fn.fnamemodify(v, ':t:r')
lsp_configs[name] = true
end
vim.lsp.enable(vim.tbl_keys(lsp_configs))
-- Delete 0.11 new gr- keymaps
vim.keymap.del({ "n" }, "grn")
vim.keymap.del({ "n", "x" }, "gra")
vim.keymap.del({ "n" }, "gri")

View file

@ -0,0 +1,86 @@
-- <leader> is space
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
-- Disable netrw (file explorer) use NvimTree instead
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- Disable Perl
vim.g.loaded_perl_provider = 0 -- Don't load Perl
-- Format on save
vim.g.autoformat = true
local opt = vim.opt
-- Clipboard
-- `unnamedplus` for system clipboard
opt.clipboard = vim.env.SSH_TTY and "" or "unnamedplus"
-- Line number
opt.number = true
opt.relativenumber = true
-- Confirm before dangerous operations
opt.confirm = true
-- Word wrap
opt.linebreak = true
-- Indentation
opt.expandtab = true
opt.shiftwidth = 4
opt.tabstop = 4
opt.shiftround = true
-- Case
opt.ignorecase = true
opt.smartcase = true
-- Highlight current line
opt.cursorline = true
-- opt.cursorcolumn = true -- Highlight current column
-- Terminal GUI
opt.termguicolors = true
--- Fold
opt.foldmethod = "expr"
-- Folding provided by treesitter
opt.foldexpr = "nvim_treesitter#foldexpr()"
-- Disable fold at start
opt.foldlevelstart = 99
opt.foldlevel = 99
opt.foldenable = false
opt.foldlevelstart = 1
-- Hide Command Line if empty
opt.cmdheight = 0
-- Scroll
opt.scrolloff = 5 -- Always show 5 lines above/below cursor
opt.sidescrolloff = 10 -- Always show 10 columns left/right of cursor
-- Conceal: Hide some characters, might be useful for markdown and LaTeX
opt.conceallevel = 2
-- `laststatus`
-- Disable status line: Use `lualine` instead
-- opt.laststatus = 0
-- 3: Global status line (always at the bottom)
opt.laststatus = 3
vim.o.sessionoptions = "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions"
-- hover.nvim
vim.o.mousemoveevent = true
-- Hide zero-width space
-- vim.api.nvim_create_autocmd("FileType", {
-- pattern = "*",
-- callback = function()
-- vim.opt_local.conceallevel = 2
-- vim.cmd([[
-- syntax match ZeroWidthSpace /\%u200b/ conceal
-- highlight link ZeroWidthSpace Conceal
-- ]])
-- end,
-- })
vim.fn.matchadd("Conceal", [[\%u200b]], 10, -1, { conceal = "" })

View file

@ -0,0 +1,2 @@
-- Entry point for all plugins
require("plugins")

View file

@ -0,0 +1,36 @@
--- Available LSP goes here
--- Check https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md
--- for available server and name
local M = {}
-- Ensure that the following servers are installed and set
-- Use :Mason to list all available servers
M.servers = {
"bashls", -- Bash
"clangd", -- C/C++
"gopls", -- Go
"html", -- HTML
"jsonls", -- JSON
"lua_ls", -- Lua
-- "markdown_oxide", -- Markdown
"pyright", -- Python
"rust_analyzer", -- Rust
"taplo", -- TOML
"ts_ls", -- TypeScript
"vimls", -- vimscript
"yamlls", -- YAML
"beancount", -- Beancount
}
-- Configuration for each server defines here
M.server_config = {
lua_ls = {
capabilities = vim.lsp.protocol.make_client_capabilities(),
settings = {
Lua = {
diagnostics = { globals = { "vim" } },
},
},
},
}
return M

View file

@ -0,0 +1,16 @@
require("plugins.lazy-nvim")
require("lazy").setup({
spec = {
-- import your plugins
-- { import = "plugins.completion" },
-- { import = "plugins.fileutils" },
-- { import = "plugins.lsp" },
-- { import = "plugins.edit" },
-- { 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 },
})

View 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

View 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)

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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",
})

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

View 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>",
}

View 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" },
-- },
-- })

View file

@ -0,0 +1,100 @@
-- https://stackoverflow.com/a/73365602
vim.api.nvim_create_autocmd("TextYankPost", {
group = vim.api.nvim_create_augroup("highlight_yank", {}),
desc = "Hightlight selection on yank",
pattern = "*",
callback = function()
vim.highlight.on_yank({ higroup = "IncSearch", timeout = 500 })
end,
})
return {
-- Colorschemes
{
"catppuccin/nvim",
name = "catppuccin",
lazy = true,
opts = {
flavor = "auto",
background = {
light = "latte",
dark = "mocha",
},
integrations = {
-- lualine = true,
"lualine",
"blink_cmp"
},
},
},
{
"rose-pine/neovim",
name = "rose-pine",
opts = {
variant = "dawn",
},
cmd = "FzfLua colorschemes",
},
{ "rebelot/kanagawa.nvim", cmd = "FzfLua colorschemes" },
{ -- Modern Status Line
"nvim-lualine/lualine.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
event = "VeryLazy",
config = function()
require("plugins.mod.lualine")
end,
},
-- { -- Breadcrumb
-- "Bekaboo/dropbar.nvim",
-- dependencies = {
-- "nvim-telescope/telescope-fzf-native.nvim",
-- build = "make",
-- },
-- opts = {},
-- keys = {
-- {
-- "<Leader>+",
-- function()
-- require("dropbar.api").pick()
-- end,
-- desc = "Pick symbols in winbar",
-- },
-- {
-- "[;",
-- function()
-- require("dropbar.api").goto_context_start()
-- end,
-- desc = "Go to start of current context",
-- },
-- {
-- "];",
-- function()
-- require("dropbar.api").select_next_context()
-- end,
-- desc = "Select next context",
-- },
-- },
-- },
{ import = "plugins.mod.bufferline" }, -- Buffer Top Bar
{ -- Git Blames, Changes
"lewis6991/gitsigns.nvim",
opts = {
current_line_blame = true,
},
event = "BufReadPre",
keys = {
{ "<leader>gb", "<cmd>Gitsigns blame<CR>", desc = "Blame file" },
{ "<leader>gd", "<cmd>Gitsigns diffthis<CR>", desc = "Diff file" },
{ "<leader>gB", "<cmd>Gitsigns toggle_current_line_blame<CR>", desc = "Toggle line blame" },
{ "[g", "<cmd>Gitsigns prev_hunk<CR>", desc = "Prev hunk" },
{ "]g", "<cmd>Gitsigns next_hunk<CR>", desc = "Next hunk" },
},
},
-- { -- Highlight and navigate between TODOs
-- "folke/todo-comments.nvim",
-- cmd = { "TodoTelescope" },
-- event = "BufRead",
-- opts = {},
-- dependencies = { "nvim-lua/plenary.nvim" },
-- },
}

View file

@ -0,0 +1,24 @@
return {
{ import = "plugins.mod.blink-cmp" },
-- { import = "plugins.mod.nvim-cmp" },
{
"L3MON4D3/LuaSnip",
build = "make install_jsregexp",
event = "InsertEnter",
config = function()
require("luasnip.loaders.from_vscode").lazy_load({ paths = "~/.config/lsp-snippets" })
require("luasnip").setup({
history = true,
enable_autosnippets = true,
})
end,
},
{
"js0ny/luasnip-latex-snippets.nvim",
dependencies = { "L3MON4D3/LuaSnip", "lervag/vimtex" },
ft = { "tex", "latex", "markdown", "org" },
opts = {},
-- dev = true,
-- dir = "~/Source/Forks/luasnip-latex-snippets.nvim/"
}
}

View file

@ -0,0 +1,43 @@
-- Debugger setups
return {
{
"mfussenegger/nvim-dap",
event = "BufReadPre",
config = function()
local dap = require("dap")
dap.adapters.codelldb = {
type = "executable",
command = "codelldb",
}
dap.configurations.cpp = {
{
name = "Launch file",
type = "codelldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
end,
cwd = "${workspaceFolder}",
stopOnEntry = false,
},
}
dap.configurations.c = dap.configurations.cpp
dap.configurations.rust = dap.configurations.cpp
end,
},
{
"rcarriga/nvim-dap-ui",
opts = {},
dependencies = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio" },
cmd = "DapNew",
},
{ "theHamsta/nvim-dap-virtual-text", opts = {}, cmd = "DapNew" },
{
"mfussenegger/nvim-dap-python",
event = "BufReadPost",
ft = "python",
config = function()
require("dap-python").setup("uv")
end,
},
}

View file

@ -0,0 +1,46 @@
return {
{
"folke/flash.nvim",
event = "BufEnter",
opts = {},
-- stylua: ignore
keys = {
{ "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" },
{ "S", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" },
{ "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" },
{ "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" },
{ "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" },
},
},
{ import = "plugins.mod.img-clip" },
{ import = "plugins.mod.mc" }, -- Multiple-cursors
{ import = "plugins.mod.autopairs" },
{
"kylechui/nvim-surround",
version = "*", -- Use for stability; omit to use `main` branch for the latest features
event = "BufEnter",
opts = {},
},
{
"MagicDuck/grug-far.nvim",
opts = { headerMaxWidth = 80 },
cmd = "GrugFar",
keys = {
{
"<leader>fF",
function()
local grug = require("grug-far")
local ext = vim.bo.buftype == "" and vim.fn.expand("%:e")
grug.open({
transient = true,
prefills = {
filesFilter = ext and ext ~= "" and "*." .. ext or nil,
},
})
end,
mode = { "n", "v" },
desc = "Search and Replace",
},
},
},
}

View file

@ -0,0 +1,39 @@
return {
{
"rmagatti/auto-session",
event = "BufReadPre",
cmd = {
"SessionSearch",
"SessionSave",
},
opts = {
suppressed_dirs = { "~/", "~/Projects", "~/Downloads", "/" },
},
},
-- { import = "plugins.mod.nvim-tree" },
-- { import = "plugins.mod.telescope" },
{ import = "plugins.mod.fzf" },
-- {
-- "ahmedkhalf/project.nvim",
-- event = "VeryLazy",
-- opts = {
-- detection_methods = { "lsp", "pattern" },
-- patterns = { ".git", "Makefile", "package.json" },
-- sync_root_with_cwd = true,
-- silent_chdir = true,
-- scope_chdir = "global",
-- },
-- config = function()
-- require("telescope").load_extension("projects")
-- end,
-- dependencies = { "nvim-telescope/telescope.nvim" },
-- },
-- {
-- "NeogitOrg/neogit",
-- config = true,
-- cmd = {
-- "Neogit",
-- },
-- },
{ import = "plugins.mod.neo-tree" }
}

View file

@ -0,0 +1,15 @@
require("plugins.lazy-nvim")
-- Setup lazy.nvim
require("lazy").setup({
spec = {
{ import = "plugins.appearance" },
{ import = "plugins.completion" },
{ import = "plugins.fileutils" },
{ import = "plugins.lang" },
{ import = "plugins.dap" },
{ import = "plugins.edit" },
{ import = "plugins.misc" },
},
checker = { enabled = false },
})

View file

@ -0,0 +1,12 @@
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
pattern = "*.bean",
callback = function()
vim.bo.filetype = "beancount"
end,
})
return {
"nathangrigg/vim-beancount",
ft = "beancount",
}

View file

@ -0,0 +1,22 @@
return {
{ import = "plugins.lang.org" },
{ import = "plugins.lang.markdown" },
{ import = "plugins.lang.just" },
{ import = "plugins.lang.typst" },
{ import = "plugins.lang.beancount" },
{ import = "plugins.lang.tex" },
{ import = "plugins.lang.lua" },
{ import = "plugins.lang.treesitter" },
{ import = "plugins.mod.trouble-nvim" },
-- Remove mason and use system package manager
-- {
-- "williamboman/mason.nvim",
-- cmd = "Mason",
-- build = ":MasonUpdate",
-- -- opts_extend = { "ensure_installed" },
-- opts = {
-- -- ensure_installed = require("config.servers").servers,
-- },
-- },
{ import = "plugins.mod.conform-nvim" },
}

View file

@ -0,0 +1,4 @@
return {
"NoahTheDuke/vim-just",
ft = { "just" },
}

View file

@ -0,0 +1,9 @@
return {
"folke/lazydev.nvim",
ft = "lua", -- only load on lua files
opts = {
library = {
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
},
},
}

View file

@ -0,0 +1,6 @@
return {
{ import = "plugins.lang.markdown.render-markdown" },
-- { import = "plugins.mod.lang.markdown.markview" },
{ import = "plugins.lang.markdown.obsidian-nvim" },
{ "bullets-vim/bullets.vim", ft = "markdown" },
}

View file

@ -0,0 +1,29 @@
-- This won't be loaded
-- I keep this since render-markdown sometimes buggy
return {
{
"OXY2DEV/markview.nvim",
lazy = false,
dependencies = {
"nvim-treesitter/nvim-treesitter",
"nvim-tree/nvim-web-devicons",
},
opts = {
checkboxes = require("markview-presets").checkboxes.nerd,
headings = {
enable = true,
shift_width = 1,
heading_1 = {
style = "label",
hl = "MarkviewH1",
},
},
code_blocks = {
style = "language",
language_direction = "right",
hl = "MarkviewCode",
info_hl = "MarkviewCodeInfo",
},
},
},
}

View file

@ -0,0 +1,145 @@
local uuid = function()
local template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return string.gsub(template, '[xy]', function(c)
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
return string.format('%x', v)
end)
end
return {
"obsidian-nvim/obsidian.nvim",
version = "*", -- recommended, use latest release instead of latest commit
-- lazy = false,
ft = "markdown",
cmd = {
"ObsidianNewFromTemplate",
"ObsidianToggleCheckbox",
"ObsidianQuickSwitch",
"ObsidianExtractNote",
"ObsidianFollowLink",
"ObsidianBacklinks",
"ObsidianWorkspace",
"ObsidianYesterday",
"ObsidianPasteImg",
"ObsidianTomorrow",
"ObsidianTemplate",
"ObsidianDailies",
"ObsidianLinkNew",
"ObsidianRename",
"ObsidianSearch",
"ObsidianCheck",
"ObsidianLinks",
"ObsidianToday",
"ObsidianDebug",
"ObsidianOpen",
"ObsidianTags",
"ObsidianLink",
"ObsidianNew",
"ObsidianTOC",
},
-- Replace the above line with this if you only want to load obsidian.nvim for markdown files in your vault:
-- event = {
-- -- If you want to use the home shortcut '~' here you need to call 'vim.fn.expand'.
-- -- E.g. "BufReadPre " .. vim.fn.expand "~" .. "/my-vault/*.md"
-- -- refer to `:h file-pattern` for more examples
-- "BufReadPre path/to/my-vault/*.md",
-- "BufNewFile path/to/my-vault/*.md",
-- },
keys = {
{ "<leader>fo", "<cmd>ObsidianQuickSwitch<CR>", desc = "Obsidian: Quick Switch" },
},
dependencies = {
-- Required.
"nvim-lua/plenary.nvim",
-- see below for full list of optional dependencies 👇
"ibhagwan/fzf-lua",
},
opts = {
workspaces = {
{
name = "personal",
path = "~/Obsidian",
},
},
completion = {
nvim_cmp = false,
blink = true,
min_chars = 2,
},
ui = {
enable = false,
},
templates = {
folder = "_Global/LuaTemplates",
date_format = "%Y-%m-%d",
time_format = "%H:%M",
substitutions = {
yesterday = function()
return os.date("%Y-%m-%d", os.time() - 86400)
end,
uuid = uuid()
},
},
---@return table
note_frontmatter_func = function(note)
-- Add the title of the note as an alias.
if note.title then
note:add_alias(note.title)
end
-- Force to use UUID as the note id.
local note_id
if note.metadata then
note_id = note.id
else
note_id = uuid()
end
local out = {
id = note_id,
aliases = note.aliases,
tags = note.tags,
title = note.id,
date = os.date(
"%Y-%m-%dT00:00:00"),
}
-- `note.metadata` contains any manually added fields in the frontmatter.
-- So here we just make sure those fields are kept in the frontmatter.
if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then
for k, v in pairs(note.metadata) do
out[k] = v
end
end
-- Force to update mtime.
out.mtime = os.date("%Y-%m-%dT%H:%M:%S")
return out
end,
daily_notes = {
folder = "_Global/Periodic",
date_format = "%Y-%m-%d",
default_tags = { "daily" },
template = nil,
},
-- see below for full list of options 👇
attachments = {
img_folder = "_Global/Assets",
img_name_func = function()
return string.format("%s-", os.time())
end,
},
mappings = {
["<cr>"] = {
action = function()
require("obsidian").util.smart_action()
end,
opts = { buffer = true, expr = true },
},
},
new_notes_location = "current_dir",
},
}

View file

@ -0,0 +1,74 @@
return {
{
"MeanderingProgrammer/render-markdown.nvim",
event = "BufRead",
ft = { "markdown", "Avante" },
opts = {
file_types = { "markdown", "Avante" },
render_modes = { "n", "c", "t" },
latex = {
-- enabled = true,
enabled = false,
converter = "latex2text",
highlight = "RenderMarkdownMath",
top_pad = 0,
bottom_pad = 0,
},
-- heading = {
-- position = "overlay",
-- width = "block",
-- left_margin = 0.5,
-- left_pad = 0.2,
-- right_pad = 0.2,
-- },
link = {
custom = {
python = { pattern = "%.py", icon = "" },
lua = { pattern = "%.lua", icon = "" },
markdown = { pattern = "%.md", icon = "" },
},
},
bullet = {
icons = { "󰮯 ", "", "", "", "" },
},
checkbox = {
checked = { scope_highlight = "@markup.strikethrough" },
unchecked = { scope_highlight = "@comment.todo" },
},
code = {
position = "right",
width = "block",
right_pad = 10,
},
callout = {
note = { raw = "[!NOTE]", rendered = "󰋽 Note", highlight = "RenderMarkdownInfo" },
tip = { raw = "[!TIP]", rendered = "󰌶 Tip", highlight = "RenderMarkdownSuccess" },
important = { raw = "[!IMPORTANT]", rendered = "󰅾 Important", highlight = "RenderMarkdownHint" },
warning = { raw = "[!WARNING]", rendered = "󰀪 Warning", highlight = "RenderMarkdownWarn" },
caution = { raw = "[!CAUTION]", rendered = "󰳦 Caution", highlight = "RenderMarkdownError" },
abstract = { raw = "[!ABSTRACT]", rendered = "󰨸 Abstract", highlight = "RenderMarkdownInfo" },
summary = { raw = "[!SUMMARY]", rendered = "󰨸 Summary", highlight = "RenderMarkdownInfo" },
tldr = { raw = "[!TLDR]", rendered = "󰨸 Tldr", highlight = "RenderMarkdownInfo" },
info = { raw = "[!INFO]", rendered = "󰋽 Info", highlight = "RenderMarkdownInfo" },
todo = { raw = "[!TODO]", rendered = "󰗡 Todo", highlight = "RenderMarkdownInfo" },
hint = { raw = "[!HINT]", rendered = "󰌶 Hint", highlight = "RenderMarkdownSuccess" },
success = { raw = "[!SUCCESS]", rendered = "󰄬 Success", highlight = "RenderMarkdownSuccess" },
check = { raw = "[!CHECK]", rendered = "󰄬 Check", highlight = "RenderMarkdownSuccess" },
done = { raw = "[!DONE]", rendered = "󰄬 Done", highlight = "RenderMarkdownSuccess" },
question = { raw = "[!QUESTION]", rendered = "󰘥 Question", highlight = "RenderMarkdownWarn" },
help = { raw = "[!HELP]", rendered = "󰘥 Help", highlight = "RenderMarkdownWarn" },
faq = { raw = "[!FAQ]", rendered = "󰘥 Faq", highlight = "RenderMarkdownWarn" },
attention = { raw = "[!ATTENTION]", rendered = "󰀪 Attention", highlight = "RenderMarkdownWarn" },
failure = { raw = "[!FAILURE]", rendered = "󰅖 Failure", highlight = "RenderMarkdownError" },
fail = { raw = "[!FAIL]", rendered = "󰅖 Fail", highlight = "RenderMarkdownError" },
missing = { raw = "[!MISSING]", rendered = "󰅖 Missing", highlight = "RenderMarkdownError" },
danger = { raw = "[!DANGER]", rendered = "󱐌 Danger", highlight = "RenderMarkdownError" },
error = { raw = "[!ERROR]", rendered = "󱐌 Error", highlight = "RenderMarkdownError" },
bug = { raw = "[!BUG]", rendered = "󰨰 Bug", highlight = "RenderMarkdownError" },
example = { raw = "[!EXAMPLE]", rendered = "󰉹 Example", highlight = "RenderMarkdownHint" },
quote = { raw = "[!QUOTE]", rendered = "󱆨 Quote", highlight = "RenderMarkdownQuote" },
cite = { raw = "[!CITE]", rendered = "󱆨 Cite", highlight = "RenderMarkdownQuote" },
},
},
},
}

View file

@ -0,0 +1,88 @@
return {
{
"nvim-orgmode/orgmode",
dependencies = {
-- "nvim-telescope/telescope.nvim",
-- "nvim-orgmode/telescope-orgmode.nvim",
"nvim-orgmode/org-bullets.nvim",
"Saghen/blink.cmp",
},
cmd = {
"Org",
},
ft = {
"org",
"orgagenda",
},
keys = {
{ "<leader>A", "<cmd>Org agenda<CR>", desc = "Org Agenda" },
},
event = "BufEnter *.org",
config = function()
require("orgmode").setup({
org_agenda_files = "~/OrgFiles/tasks/*",
org_default_notes_file = "~/OrgFiles/tasks/inbox.org",
org_archive_location = "~/OrgFiles/.archive/%s_archive::",
org_todo_keywords = { "TODO(t)", "NEXT(n)", "WAIT(w)", "|", "DONE(d)", "CANCELLED(c)" },
org_hide_leading_stars = true,
org_hide_emphasis_markers = true,
org_log_into_drawer = "LOGBOOK",
org_highlight_latex_and_related = "native",
org_startup_indented = true,
org_deadline_warning_days = 10,
mappings = {
agenda = {
org_agenda_schedule = "<C-c><C-s>",
org_agenda_deadline = "<C-c><C-d>",
org_agenda_todo = "<C-c><C-t>",
org_agenda_set_tags = "<C-c><C-c>",
org_agenda_earlier = { "[[", "<" },
org_agenda_later = { "]]", ">" },
org_agenda_archive = "$",
},
org = {
org_deadline = "<C-c><C-d>",
org_schedule = "<C-c><C-s>",
org_todo = "<C-c><C-t>",
org_set_tags_command = "<C-c><C-c>",
org_archive_subtree = "<C-c>$",
},
},
})
require("org-bullets").setup()
require("blink.cmp").setup({
sources = {
per_filetype = {
org = { "orgmode" },
},
providers = {
orgmode = {
name = "Orgmode",
module = "orgmode.org.autocompletion.blink",
fallbacks = { "buffer" },
},
},
},
})
-- require("telescope").setup()
-- require("telescope").load_extension("orgmode")
-- vim.keymap.set("n", "<leader>r", require("telescope").extensions.orgmode.refile_heading)
-- vim.keymap.set("n", "<leader>oP", require("telescope").extensions.orgmode.search_headings)
vim.keymap.set("n", "<leader>op", "<cmd>FzfLua files cwd=~/OrgFiles<CR>")
-- vim.keymap.set("n", "<leader>li", require("telescope").extensions.orgmode.insert_link)
end,
},
-- {
-- dir = "~/Source/org-pomodoro.nvim",
-- name = "org-pomodoro.nvim",
-- lazy = false,
-- opts = {},
-- dependencies = {
-- "nvim-orgmode/orgmode",
-- },
-- cmd = {
-- "OrgPomodoro",
-- },
-- },
}

View file

@ -0,0 +1,7 @@
return {
"lervag/vimtex",
ft = { "tex", "bib" },
init = function()
vim.g.vimtex_view_method = "okular"
end,
}

View file

@ -0,0 +1,23 @@
return {
{ "nvim-treesitter/nvim-treesitter-context", lazy = true },
{
"nvim-treesitter/nvim-treesitter",
run = ":TSUpdate",
cmd = {
"TSInstall",
"TSUpdate",
"TSUpdateSync",
},
event = {
"BufReadPre",
},
opts = {
ensure_installed = { "c", "lua", "vim", "vimdoc", "markdown", "markdown_inline", "latex" },
highlight = { enable = true },
indent = { enable = true },
},
config = function()
require('nvim-treesitter.configs').setup({ highlight = { enable = true } })
end
},
}

View file

@ -0,0 +1,6 @@
return {
'chomosuke/typst-preview.nvim',
ft = { 'typst' },
version = '1.*',
opts = {}, -- lazy.nvim will implicitly calls `setup {}`
}

View file

@ -0,0 +1,22 @@
-- 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 = "\\"

View file

@ -0,0 +1,28 @@
return {
{ "nvim-lua/plenary.nvim", lazy = true },
{ "wakatime/vim-wakatime", lazy = false },
{ import = "plugins.mod.toggleterm" },
{ import = "plugins.mod.which-keys-nvim" },
{ import = "plugins.mod.copilot-lua" },
{ import = "plugins.mod.avante-nvim" },
{
"kawre/leetcode.nvim",
build = ":TSUpdate html", -- if you have `nvim-treesitter` installed
cmd = {
"Leet",
},
lazy = true,
-- event = "VeryLazy",
dependencies = {
-- "nvim-telescope/telescope.nvim",
"ibhagwan/fzf-lua",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
},
opts = {
-- configuration goes here
},
},
{ import = "plugins.mod.image-nvim" },
{ import = "plugins.mod.snacks-nvim" },
}

View file

@ -0,0 +1,56 @@
-- alpha-nvim.lua
return {
{
"goolord/alpha-nvim",
dependencies = {},
keys = {
{ "<leader>ba", "<cmd>Alpha<CR>", desc = "Toggle Alpha Dashboard" },
},
cmd = {
"Alpha",
},
config = function()
local alpha = require("alpha")
local dashboard = require("alpha.themes.dashboard")
dashboard.section.header.val = {
" ",
"================= =============== =============== ======== ========",
"\\\\ . . . . . . .\\\\ //. . . . . . .\\\\ //. . . . . . .\\\\ \\\\. . .\\\\// . . //",
"||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\\/ . . .||",
"|| . .|| ||. . || || . .|| ||. . || || . .|| ||. . || ||. . . . . . . ||",
"||. . || || . .|| ||. . || || . .|| ||. . || || . .|| || . | . . . . .||",
"|| . .|| ||. _-|| ||-_ .|| ||. . || || . .|| ||. _-|| ||-_.|\\ . . . . ||",
"||. . || ||-' || || `-|| || . .|| ||. . || ||-' || || `|\\_ . .|. .||",
"|| . _|| || || || || ||_ . || || . _|| || || || |\\ `-_/| . ||",
"||_-' || .|/ || || \\|. || `-_|| ||_-' || .|/ || || | \\ / |-_.||",
"|| ||_-' || || `-_|| || || ||_-' || || | \\ / | `||",
"|| `' || || `' || || `' || || | \\ / | ||",
"|| .===' `===. .==='.`===. .===' /==. | \\/ | ||",
"|| .==' \\_|-_ `===. .===' _|_ `===. .===' _-|/ `== \\/ | ||",
"|| .==' _-' `-_ `=' _-' `-_ `=' _-' `-_ /| \\/ | ||",
"|| .==' _-' `-__\\._-' `-_./__-' `' |. /| | ||",
"||.==' _-' `' | /==.||",
"==' _-' j s 0 n y N E O V I M \\/ `==",
"\\ _-' `-_ /",
" `'' ``' ",
}
dashboard.section.buttons.val.leader = "SPC"
dashboard.section.buttons.val = {
-- leader = "SPC",
dashboard.button("p", "󰈞 查找项目", "<cmd>Telescope projects<CR>"),
dashboard.button("h", " 历史文件", "<cmd>Telescope oldfiles<CR>"),
dashboard.button("l", " 加载会话", "<cmd>SessionSearch<CR>"),
-- FIXME: This does not work on Windows - Make it more portable
dashboard.button("c", " 转到设置", "<cmd>Telescope find_files cwd=~/.config/nvim<CR>"),
dashboard.button("SPC q", "󱊷 退出", "<cmd>qa<CR>"),
}
dashboard.section.footer.val = "今日 " .. os.date("%Y-%m-%d %A") .. " "
dashboard.config.opts.noautocmd = true
-- vim.cmd[[autocmd User AlphaReady echo 'Alpha ready!']]
alpha.setup(dashboard.config)
end,
},
}

View file

@ -0,0 +1,21 @@
return {
"windwp/nvim-autopairs",
event = "InsertEnter",
config = function()
local npairs = require("nvim-autopairs")
local Rule = require("nvim-autopairs.rule")
npairs.setup()
npairs.add_rule(Rule("$", "$", "markdown"))
npairs.add_rule(Rule("\\(", "\\)", "tex"))
npairs.add_rule(Rule("\\[", "\\]", "tex"))
npairs.add_rules({
Rule("%(", "%)", "cmd"):with_pair(function(opts)
if vim.fn.getcmdtype() == ":" then
return true
end
end),
})
end,
}

View file

@ -0,0 +1,35 @@
return {
"yetone/avante.nvim",
event = "BufRead",
-- lazy = false,
version = false, -- Set this to "*" to always pull the latest release version, or set it to false to update to the latest code changes.
opts = {
-- add any opts here
-- for example
provider = "openai",
openai = {
endpoint = "https://aihubmix.com/v1",
model = "claude-3-7-sonnet-20250219", -- your desired model (or use gpt-4o, etc.)
timeout = 30000, -- timeout in milliseconds
temperature = 0, -- adjust if needed
max_tokens = 4096,
-- reasoning_effort = "high" -- only supported for "o" models
},
},
-- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
build = "make",
-- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
dependencies = {
"nvim-treesitter/nvim-treesitter",
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
--- The below dependencies are optional,
-- "nvim-telescope/telescope.nvim", -- for file_selector provider telescope
"ibhagwan/fzf-lua",
"hrsh7th/nvim-cmp", -- autocompletion for avante commands and mentions
"nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
"zbirenbaum/copilot.lua", -- for providers='copilot'
"HakonHarnes/img-clip.nvim",
},
}

View file

@ -0,0 +1,79 @@
return {
"saghen/blink.cmp",
-- optional: provides snippets for the snippet source
-- dependencies = { "L3MON4D3/LuaSnip", version = "v2.*" },
-- use a release tag to download pre-built binaries
version = "*",
event = "InsertEnter",
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
enabled = function()
if vim.fn.getcmdtype() ~= "" then
return true
end
return not vim.tbl_contains({ "TelescopePrompt", "dap-repl", "snacks_picker_list" }, vim.bo.filetype)
end,
keymap = {
preset = "default",
["<Tab>"] = {
function(cmp)
if cmp.snippet_active() then
return cmp.accept()
else
return cmp.select_and_accept()
end
end,
"snippet_forward",
"fallback",
},
["<C-f>"] = { "select_and_accept" },
["<C-b>"] = { "hide", "fallback" },
["<CR>"] = { "accept", "fallback" },
},
completion = {
menu = { border = "single" },
documentation = { window = { border = "single" } },
},
signature = { window = { border = "single" } },
appearance = {
-- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
-- Adjusts spacing to ensure icons are aligned
nerd_font_variant = "normal",
},
snippets = {
preset = "luasnip",
},
sources = {
default = { "lazydev", "lsp", "path", "snippets", "buffer" },
per_filetype = {
org = { "orgmode" },
},
providers = {
lazydev = {
name = "LazyDev",
module = "lazydev.integrations.blink",
score_offset = 100,
},
orgmode = {
name = "Orgmode",
module = "orgmode.org.autocompletion.blink",
fallbacks = { "buffer" },
},
},
},
-- (Default) Rust fuzzy matcher for typo resistance and significantly better performance
-- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation,
-- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"`
--
-- See the fuzzy documentation for more information
fuzzy = { implementation = "prefer_rust_with_warning" },
},
opts_extend = { "sources.default" },
}

View file

@ -0,0 +1,55 @@
local function get_highlight()
if vim.g.colors_name == "catppuccin" then
return require("catppuccin.groups.integrations.bufferline").get()
elseif vim.g.colors_name == "rose-pine" then
return require("rose-pine.plugins.bufferline")
end
end
return {
"akinsho/bufferline.nvim",
dependencies = "nvim-tree/nvim-web-devicons", -- 图标支持
after = "catppuccin",
event = "VeryLazy",
keys = {
{ "<leader>b1", "<cmd>BufferLineGotoBuffer 1<CR>", desc = "Switch to Buffer #1" },
{ "<leader>b2", "<cmd>BufferLineGotoBuffer 2<CR>", desc = "Switch to Buffer #2" },
{ "<leader>b3", "<cmd>BufferLineGotoBuffer 3<CR>", desc = "Switch to Buffer #3" },
{ "<leader>b4", "<cmd>BufferLineGotoBuffer 4<CR>", desc = "Switch to Buffer #4" },
{ "<leader>b5", "<cmd>BufferLineGotoBuffer 5<CR>", desc = "Switch to Buffer #5" },
{ "<leader>b6", "<cmd>BufferLineGotoBuffer 6<CR>", desc = "Switch to Buffer #6" },
{ "<leader>b7", "<cmd>BufferLineGotoBuffer 7<CR>", desc = "Switch to Buffer #7" },
{ "<leader>b8", "<cmd>BufferLineGotoBuffer 8<CR>", desc = "Switch to Buffer #8" },
{ "<leader>b9", "<cmd>BufferLineGotoBuffer 9<CR>", desc = "Switch to Buffer #9" },
{ "<leader>bb", "<cmd>BufferLinePick<CR>", desc = "Quick Switch Buffers" },
{ "<leader>bD", "<cmd>BufferLineCloseOthers<CR>", desc = "Delete Other Buffers" },
{ "<leader>bxx", "<cmd>BufferLineCloseOthers<CR>", desc = "Delete Other Buffers" },
{ "<leader>bxh", "<cmd>BufferLineCloseLeft<CR>", desc = "Delete Buffers Left" },
{ "<leader>bxi", "<cmd>BufferLineCloseRight<CR>", desc = "Delete Buffers Right" },
{ "<leader>bX", "<cmd>BufferLineCloseOthers<CR>", desc = "Delete Other Buffers" },
{ "<leader>bt", "<cmd>BufferLineTogglePin<CR>", desc = "Pin Buffer" },
},
opts = {
options = {
indicator = {
icon = "", -- this should be omitted if indicator style is not 'icon'
style = "icon",
},
diagnostics = "nvim_lsp",
diagnostics_indicator = function(count, level, diagnostics_dict, context)
local icon = level:match("error") and "" or ""
return " " .. icon .. count
end,
show_buffer_icons = true,
numbers = "ordinal", -- 显示 buffer 序号
close_command = "bdelete! %d", -- 关闭 buffer 的命令
right_mouse_command = "bdelete! %d", -- 右键关闭
offsets = {
{ filetype = "NvimTree", text = "资源管理器", text_align = "center" },
},
separator_style = "thin",
},
highlights = get_highlight(),
},
}

View file

@ -0,0 +1,38 @@
return {
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
-- This will provide type hinting with LuaLS
---@module "conform"
---@type conform.setupOpts
opts = {
-- Define your formatters
formatters_by_ft = {
lua = { "stylua" },
python = { "isort", "black" },
javascript = { "prettierd", "prettier", stop_after_first = true },
},
-- Set default options
default_format_opts = {
lsp_format = "fallback",
},
-- Set up format-on-save
format_on_save = function(bufnr)
-- Disable with a global or buffer-local variable
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
return { timeout_ms = 500, lsp_format = "fallback" }
end,
-- Customize formatters
formatters = {
shfmt = {
prepend_args = { "-i", "2" },
},
},
},
init = function()
-- If you want the formatexpr, here is the place to set it
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}

View file

@ -0,0 +1,23 @@
return {
"zbirenbaum/copilot.lua",
cmd = "Copilot",
build = ":Copilot auth",
event = "BufReadPost",
opts = {
suggestion = {
enabled = not vim.g.ai_cmp,
auto_trigger = true,
hide_during_completion = vim.g.ai_cmp,
keymap = {
accept = "<M-f>",
next = "<M-]>",
prev = "<M-[>",
},
},
panel = { enabled = false },
filetypes = {
markdown = true,
help = true,
},
},
}

View file

@ -0,0 +1,30 @@
return {
"ibhagwan/fzf-lua",
-- optional for icon support
dependencies = { "nvim-tree/nvim-web-devicons" },
cmd = "FzfLua",
keys = {
{ "<leader><leader>", "<cmd>FzfLua files<CR>", desc = "Find Files" },
{ "<leader>fc", "<cmd>FzfLua files cwd=~/.config/nvim<CR>", desc = "Edit configs" },
{ "<leader>/", "<cmd>FzfLua live_grep<CR>", desc = "Grep Files" },
{ "<leader>;", "<cmd>FzfLua<CR>", desc = "Show Telescope Commands" },
{ "<leader>ui", "<cmd>FzfLua colorschemes<CR>", desc = "Change colorscheme" },
-- find_files { "<leader>pp", "<cmd>FzfLua projects<CR>", desc = "Listfind_files all Projects" },
{ "<leader>pd", "<cmd>FzfLua zoxide<CR>", desc = "List recent directories" },
-- { "<leader>pg", "<cmd>FzfLua projects<CR>", desc = "List all Git Projects" },
{ "<leader>ps", "<cmd>FzfLua session-lens<CR>", desc = "List all sessions" },
{ "<leader>gs", "<cmd>FzfLua git_status<CR>", desc = "Git Status" },
{ "<leader>gt", "<cmd>FzfLua git_branches<CR>", desc = "Git Branches" },
{ "<leader>gc", "<cmd>FzfLua git_commits<CR>", desc = "Show commits" },
{ "<leader>fb", "<cmd>FzfLua buffers<CR>", desc = "List Buffers" },
{ "<leader>ff", "<cmd>FzfLua fd<CR>", desc = "Find Files" },
{ "<leader>fh", "<cmd>FzfLua oldfiles<CR>", desc = "Recent Files" },
{ "<leader>ce", "<cmd>FzfLua diagnostics<CR>", desc = "Navigate errors/warnings" },
{ "<leader>cs", "<cmd>FzfLua treesitter<CR>", desc = "Search symbols" },
{ "<leader>cS", "<cmd>FzfLua grep_string<CR>", desc = "Search current symbol" },
{ "<leader>bB", "<cmd>FzfLua buffers<CR>", desc = "List Buffers" },
{ "<leader>fl", "<cmd>FzfLua filetypes<CR>", desc = "Set Filetype/Lang to ..." },
{ "<leader>R", "<cmd>FzfLua resume<CR>", desc = "Resume FzfLua" },
},
opts = {},
}

View file

@ -0,0 +1,58 @@
return {
"lewis6991/hover.nvim",
opts = {
init = function()
-- Require providers
require("hover.providers.lsp")
-- require('hover.providers.gh')
-- require('hover.providers.gh_user')
-- require('hover.providers.jira')
-- require('hover.providers.dap')
-- require('hover.providers.fold_preview')
require("hover.providers.diagnostic")
-- require('hover.providers.man')
-- require('hover.providers.dictionary')
end,
preview_opts = {
border = "single",
},
-- Whether the contents of a currently open hover window should be moved
-- to a :h preview-window when pressing the hover keymap.
preview_window = false,
title = true,
mouse_providers = {
"LSP",
},
mouse_delay = 1000,
},
keys = {
{
"gE",
function()
require("hover").hover_select()
end,
desc = "hover.nvim (select)",
},
{
"<C-p>",
function()
require("hover").hover_switch("previous")
end,
desc = "hover.nvim (previous source)",
},
{
"<C-n>",
function()
require("hover").hover_switch("next")
end,
desc = "hover.nvim (next source)",
},
{
"<MouseMove>",
function()
require("hover").hover_mouse()
end,
desc = "hover.nvim (mouse)",
},
},
}

View file

@ -0,0 +1,18 @@
-- 2025-03-03
-- If current session is not spawn by neovide, do not load image.nvim
-- neovide did not support image viewer yet
-- https://github.com/neovide/neovide/issues/2088
-- Disable on: Neovide, alacritty and windows
if vim.g.neovide then
return {}
elseif vim.env.TERM_PROGRAM == "alacritty" then
return {}
elseif vim.loop.os_uname().sysname:lower() == "windows_nt" then
return {}
else
return {
"3rd/image.nvim",
opts = {},
event = "BufReadPre",
}
end

View file

@ -0,0 +1,30 @@
return {
{
-- support for image pasting
"HakonHarnes/img-clip.nvim",
event = "VeryLazy",
ft = { "avante", "markdown", "typst", "org", "tex" },
cmd = "PasteImage",
keys = {
{
"<localleader>p",
function()
require("img-clip").paste_image()
end,
desc = "Paste Image",
}
},
opts = {
-- recommended settings
default = {
embed_image_as_base64 = false,
prompt_for_file_name = false,
drag_and_drop = {
insert_mode = true,
},
-- required for Windows users
use_absolute_path = true,
},
}
}
}

View file

@ -0,0 +1,141 @@
local M = {}
local colors = require("config.colors")
local icons = require("config.icons")
local function diff_source()
local gitsigns = vim.b.gitsigns_status_dict
if gitsigns then
return {
added = gitsigns.added,
modified = gitsigns.changed,
removed = gitsigns.removed,
}
end
end
M.mode = {
function()
return ""
end,
-- color = mode_color_bg,
}
M.git = {
"branch",
icon = icons.git.Branch,
color = { fg = colors.scheme.violet, gui = "bold" },
}
M.diagnostics = {
"diagnostics",
sources = { "nvim_diagnostic" },
symbols = {
error = icons.diagnostics.Error .. " ",
warn = icons.diagnostics.Warning .. " ",
info = icons.diagnostics.Information .. " ",
hint = icons.diagnostics.Hint .. " ",
},
}
M.lsp = {
-- Lsp server name .
function()
local msg = "LSP Inactive"
local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = 0 })
local clients = vim.lsp.get_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end,
icon = icons.lsp,
color = { fg = colors.scheme.yellow, gui = "italic" },
}
M.filetype = {
function()
return vim.bo.filetype
end,
color = { fg = colors.scheme.blue, gui = "bold" },
}
M.eol = {
function()
return vim.bo.eol == true and icons.eol or ""
end,
color = { fg = colors.scheme.red },
}
M.command = {
"command",
color = { fg = colors.scheme.green, gui = "bold" },
}
M.encoding = {
"o:encoding",
color = { fg = colors.scheme.green, gui = "bold" },
}
M.indent = {
function()
local shiftwidth = vim.api.nvim_get_option_value("shiftwidth", { buf = 0 })
return icons.indent .. " " .. shiftwidth
end,
padding = 1,
}
M.diff = {
"diff",
source = diff_source,
-- symbols = { added = " ", modified = "󰝤 ", removed = " " },
symbols = {
added = icons.git.Add .. " ",
modified = icons.git.Change .. " ",
removed = icons.git.Delete .. " ",
},
padding = { left = 2, right = 1 },
diff_color = {
added = { fg = colors.scheme.green },
modified = { fg = colors.scheme.yellow },
removed = { fg = colors.scheme.red },
},
cond = nil,
}
M.progress = {
"progress",
}
-- TODO: Implement orgmode
M.orgmode = {
function()
return _G.orgmode.statusline()
end,
}
-- local conditions = {
-- buffer_not_empty = function()
-- return vim.fn.empty(vim.fn.expand("%:t")) ~= 1
-- end,
-- hide_in_width = function()
-- return vim.fn.winwidth(0) > 80
-- end,
-- check_git_workspace = function()
-- local filepath = vim.fn.expand("%:p:h")
-- local gitdir = vim.fn.finddir(".git", filepath .. ";")
-- return gitdir and #gitdir > 0 and #gitdir < #filepath
-- end,
-- }
-- local mode_color = colors.mode
--
-- local mode_color_bg = function()
-- return { fg = colors.mantle, bg = mode_color[vim.fn.mode()] }
-- end
return M

View file

@ -0,0 +1,63 @@
local lualine = require("lualine")
-- Color table for highlights
-- local colors = require("config.colors")
local components = require("plugins.mod.lualine.components")
--[[
VSCode Style:
Remote | Git Branch | Diagnostics | Command | | MID | | Line:Column | Indent | Encoding | EOL | File Type LSP | Notifications
--]]
-- Config
local config = {
options = {
disabled_filetypes = {
statusline = { "NvimTree", "alpha", "grug-far", "snacks_dashboard" },
},
-- Disable sections and component separators
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
-- theme = "catppuccin",
theme = vim.g.colors_name,
-- IDE-like Global Status
globalstaus = true,
},
sections = {
-- these are to remove the defaults
lualine_a = {
components.mode,
},
lualine_b = {
components.diff,
},
lualine_c = {
components.diagnostics,
},
lualine_x = {
components.orgmode,
components.indent,
components.encoding,
components.eol,
},
lualine_y = {
components.filetype,
components.lsp,
},
lualine_z = {
components.progress,
},
},
inactive_sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
lualine_c = {},
lualine_x = {},
},
}
lualine.setup(config)

View file

@ -0,0 +1,47 @@
return {
"brenton-leighton/multiple-cursors.nvim",
version = "*", -- Use the latest tagged version
-- opts = , -- This causes the plugin setup function to be called
keys = {
{ "<A-n>", "<Cmd>MultipleCursorsAddDown<CR>", mode = { "n", "x" }, desc = "Add cursor and move down" },
{ "<A-e>", "<Cmd>MultipleCursorsAddUp<CR>", mode = { "n", "x" }, desc = "Add cursor and move up" },
{ "<C-Up>", "<Cmd>MultipleCursorsAddUp<CR>", mode = { "n", "i", "x" }, desc = "Add cursor and move up" },
{ "<C-Down>", "<Cmd>MultipleCursorsAddDown<CR>", mode = { "n", "i", "x" }, desc = "Add cursor and move down" },
{ "<A-LeftMouse>", "<Cmd>MultipleCursorsMouseAddDelete<CR>", mode = { "n", "i" }, desc = "Add or remove cursor" },
},
config = function()
local normal_mode_motion = require("multiple-cursors.normal_mode.motion")
local normal_mode_edit = require("multiple-cursors.normal_mode.edit")
local visual_mode_edit = require("multiple-cursors.visual_mode.edit")
local normal_mode_mode_change = require("multiple-cursors.normal_mode.mode_change")
local visual_mode_modify_area = require("multiple-cursors.visual_mode.modify_area")
require("multiple-cursors").setup({
pre_hook = function()
require("nvim-autopairs").disable()
end,
post_hook = function()
require("nvim-autopairs").enable()
end,
custom_key_maps = {
{ { "n", "x" }, { "e", "<Up>" }, normal_mode_motion.k, "nowrap" },
{ { "n", "x" }, { "n", "<Down>" }, normal_mode_motion.j, "nowrap" },
{ { "n", "x" }, { "i", "<Right>", "<Space>" }, normal_mode_motion.l, "nowrap" },
{ { "n", "x" }, "j", normal_mode_motion.e, "nowrap" },
{ { "n", "x" }, "J", normal_mode_motion.E, "nowrap" },
{ { "n", "x" }, "gj", normal_mode_motion.ge, "nowrap" },
{ { "n", "x" }, "gJ", normal_mode_motion.gE, "nowrap" },
{ "n", "E", normal_mode_edit.J, "nowrap" },
{ "n", "gE", normal_mode_edit.gJ, "nowrap" },
{ "n", { "l", "<Insert>" }, normal_mode_mode_change.i, "nowrap" },
{ "n", "L", normal_mode_mode_change.I, "nowrap" },
{ "x", "l", visual_mode_modify_area.i, "nowrap" },
{ "x", "E", visual_mode_edit.J, "nowrap" },
{ "x", "gE", visual_mode_edit.gJ, "nowrap" },
},
})
end,
}

View file

@ -0,0 +1,89 @@
return {
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
"MunifTanjim/nui.nvim",
-- {"3rd/image.nvim", opts = {}}, -- Optional image support in preview window: See `# Preview Mode` for more information
},
lazy = false, -- neo-tree will lazily load itself
---@module "neo-tree"
---@type neotree.Config?
opts = {
window = {
mappings = {
["<space>"] = "noop",
["e"] = "noop",
["<2-LeftMouse>"] = "open",
["<cr>"] = "open",
["i"] = "open",
["<esc>"] = "cancel", -- close preview or floating neo-tree window
["P"] = { "toggle_preview", config = { use_float = true, use_image_nvim = true } },
-- Read `# Preview Mode` for more information
-- ["i"] = "focus_preview",
["S"] = "open_split",
["s"] = "open_vsplit",
-- ["S"] = "split_with_window_picker",
-- ["s"] = "vsplit_with_window_picker",
["t"] = "open_tabnew",
-- ["<cr>"] = "open_drop",
-- ["t"] = "open_tab_drop",
["w"] = "open_with_window_picker",
--["P"] = "toggle_preview", -- enter preview mode, which shows the current node without focusing
["C"] = "close_node",
-- ['C'] = 'close_all_subnodes',
["z"] = "close_all_nodes",
--["Z"] = "expand_all_nodes",
["a"] = {
"add",
-- this command supports BASH style brace expansion ("x{a,b,c}" -> xa,xb,xc). see `:h neo-tree-file-actions` for details
-- some commands may take optional config options, see `:h neo-tree-mappings` for details
config = {
show_path = "none", -- "none", "relative", "absolute"
},
},
["A"] = "add_directory", -- also accepts the optional config.show_path option like "add". this also supports BASH style brace expansion.
["d"] = "delete",
["r"] = "rename",
["b"] = "rename_basename",
["y"] = "copy_to_clipboard",
["x"] = "cut_to_clipboard",
["p"] = "paste_from_clipboard",
["c"] = "copy", -- takes text input for destination, also accepts the optional config.show_path option like "add":
-- ["c"] = {
-- "copy",
-- config = {
-- show_path = "none" -- "none", "relative", "absolute"
-- }
--}
["m"] = "move", -- takes text input for destination, also accepts the optional config.show_path option like "add".
["q"] = "close_window",
["R"] = "refresh",
["?"] = "show_help",
["<"] = "prev_source",
[">"] = "next_source",
["l"] = "show_file_details",
-- ["i"] = {
-- "show_file_details",
-- -- format strings of the timestamps shown for date created and last modified (see `:h os.date()`)
-- -- both options accept a string or a function that takes in the date in seconds and returns a string to display
-- -- config = {
-- -- created_format = "%Y-%m-%d %I:%M %p",
-- -- modified_format = "relative", -- equivalent to the line below
-- -- modified_format = function(seconds) return require('neo-tree.utils').relative_date(seconds) end
-- -- }
-- },
}
}
-- fill any relevant options here
},
keys = {
{
"<leader>ft",
"<cmd>Neotree toggle<CR>",
desc = "Toggle File Explorer",
}
}
}

View file

@ -0,0 +1,111 @@
return {
"hrsh7th/nvim-cmp",
-- lazy = false,
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
},
config = function()
local cmp = require("cmp")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local servers_module = require("config.servers")
local luasnip = require("luasnip")
local servers = servers_module.servers
local servers_config = servers_module.server_config
-- 默认 LSP 配置
local default_server_config = {
capabilities = capabilities,
}
-- local raw_keymaps = require("keymaps.cmp_map")(cmp.mapping) -- require("keymaps").cmp_nvim_keymaps(cmp.mapping)
-- local mapped = set_keymaps(raw_keymaps)
local kind_icons = require("config.icons").lsp_kind
-- 配置 nvim-cmp
cmp.setup({
formatting = {
format = function(entry, vim_item)
vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind] or "", vim_item.kind)
return vim_item
end,
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = {
-- cmp.mapping.preset.insert(mapped),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-f>"] = cmp.mapping.confirm({ select = true }),
["<C-b>"] = cmp.mapping.abort(),
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping(function(fallback)
if cmp.visible() then
if luasnip.expandable() then
luasnip.expand()
else
cmp.confirm({
select = true,
})
end
else
fallback()
end
end),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.confirm({ select = true })
elseif luasnip.locally_jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}, -- cmp.mapping.preset.insert(mapped),
sources = cmp.config.sources({
{ name = "copilot", priority = 10 },
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "lazydev", group_index = 0 },
}, {
{ name = "buffer" },
{ name = "path" },
}),
})
cmp.setup.cmdline({ "/", "?" }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
},
})
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
matching = { disallow_symbol_nonprefix_matching = false },
})
end,
}

View file

@ -0,0 +1,40 @@
return {
"neovim/nvim-lspconfig",
dependencies = { "saghen/blink.cmp" },
event = {
"BufReadPost",
"BufWritePost",
"BufNewFile",
},
-- example using `opts` for defining servers
opts = {
servers = {
lua_ls = {},
bashls = {},
clangd = {},
eslint = {}, -- JavaScript
gopls = {}, -- Go
jsonls = {}, -- JSON
markdown_oxide = {}, -- Markdown
omnisharp = {}, -- C# & F#
powershell_es = {}, -- PowerShell
pyright = {}, -- Python
taplo = {}, -- TOML
rust_analyzer = {}, -- Rust
ts_ls = {}, -- TypeScript
vimls = {}, -- vimscript
yamlls = {}, -- YAML
beancount = {}, -- Beancount
},
},
config = function(_, opts)
local lspconfig = require("lspconfig")
for server, config in pairs(opts.servers) do
-- passing config.capabilities to blink.cmp merges with the capabilities in your
-- `opts[server].capabilities, if you've defined it
config.capabilities = require("blink.cmp").get_lsp_capabilities(config.capabilities)
lspconfig[server].setup(config)
end
end,

View file

@ -0,0 +1,53 @@
local function my_on_attach(bufnr)
-- local keymaps = require("config.keymaps")
local api = require("nvim-tree.api")
local default_mode = { "n" }
local keymaps = require("keymaps")
local function opts(desc)
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
local function set_keymaps(maps)
for _, map in ipairs(maps) do
local mode = map.mode or default_mode
vim.keymap.set(mode, map.keys, map.cmd, map.opts)
end
end
local raw_keymaps = require("keymaps.nvim-tree").plugin(api, opts)
set_keymaps(raw_keymaps)
end
return {
"nvim-tree/nvim-tree.lua",
version = "*",
lazy = false,
keys = {
{ "<leader>ft", "<cmd>NvimTreeToggle<CR>", desc = "Toggle File Explorer" },
},
dependencies = {
"nvim-tree/nvim-web-devicons",
},
opts = {
on_attach = my_on_attach,
sync_root_with_cwd = true,
respect_buf_cwd = true,
disable_netrw = true,
renderer = {
icons = {
glyphs = {
git = { -- https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt#L1077C1-L1077C29
unmerged = "",
renamed = "",
deleted = "",
untracked = "",
ignored = "",
unstaged = "󰄱",
staged = "",
},
},
},
},
},
}

View file

@ -0,0 +1,96 @@
-- Welcome to nvim's systemd :D
return {
"folke/snacks.nvim",
priority = 1000,
lazy = false,
---@type snacks.Config
opts = {
bigfile = { enabled = true },
dashboard = {
enabled = true,
preset = {
keys = {
-- { key = "p", icon = "󰈞 ", desc = "查找项目", action = "<cmd>Telescope projects<CR>" },
{ key = "h", icon = "", desc = "历史文件", action = "<cmd>FzfLua oldfiles<CR>" },
{ key = "l", icon = "", desc = "加载会话", action = "<cmd>SessionSearch<CR>" },
{
key = "c",
icon = "",
desc = "转到设置",
action = "<cmd>FzfLua files cwd=~/.config/nvim<CR>",
},
{ key = "q", icon = "󱊷 ", desc = "退出", action = "<cmd>qa<CR>" },
},
header = [[
================= =============== =============== ======== ========
\\ . . . . . . .\\ //. . . . . . .\\ //. . . . . . .\\ \\. . .\\// . . //
||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\/ . . .||
|| . .|| ||. . || || . .|| ||. . || || . .|| ||. . || ||. . . . . . . ||
||. . || || . .|| ||. . || || . .|| ||. . || || . .|| || . | . . . . .||
|| . .|| ||. _-|| ||-_ .|| ||. . || || . .|| ||. _-|| ||-_.|\ . . . . ||
||. . || ||-' || || `-|| || . .|| ||. . || ||-' || || `|\_ . .|. .||
|| . _|| || || || || ||_ . || || . _|| || || || |\ `-_/| . ||
||_-' || .|/ || || \|. || `-_|| ||_-' || .|/ || || | \ / |-_.||
|| ||_-' || || `-_|| || || ||_-' || || | \ / | `||
|| `' || || `' || || `' || || | \ / | ||
|| .===' `===. .==='.`===. .===' /==. | \/ | ||
|| .==' \_|-_ `===. .===' _|_ `===. .===' _-|/ `== \/ | ||
|| .==' _-' `-_ `=' _-' `-_ `=' _-' `-_ /| \/ | ||
|| .==' _-' '-__\._-' '-_./__-' `' |. /| | ||
||.==' _-' `' | /==.||
==' _-' N E O V I M \/ `==
\ _-' `-_ /
`'' ``'
]],
--[[header = [[
--]]
},
sections = {
{ section = "header" },
{ icon = "", title = "Keymaps", section = "keys", indent = 2, padding = 1 },
{ icon = "", title = "Recent Files", section = "recent_files", indent = 2, padding = 1 },
{ icon = "", title = "Projects", section = "projects", indent = 2, padding = 1 },
{ section = "startup" },
},
},
-- explorer = {
-- },
indent = { enabled = true },
-- input = { enabled = true },
notifier = { enabled = true },
-- quickfile = { enabled = true },
scope = { enabled = true },
-- scroll = { enabled = true },
statuscolumn = { enabled = true },
-- words = { enabled = true },
image = {
enabled = true,
img_dirs = { "_Global/Assets" }
},
},
keys = {
-- {
-- "<leader>ft",
-- function()
-- require("snacks").explorer()
-- end,
-- desc = "Toggle File Explorer",
-- },
},
}

View file

@ -0,0 +1,52 @@
return {
"nvim-telescope/telescope.nvim",
cmd = "Telescope",
opts = {
defaults = {
prompt_prefix = require("config.icons").telescope,
selection_caret = " ",
entry_prefix = " ",
layout_config = { -- https://github.com/NvChad/NvChad/blob/v2.5/lua/nvchad/configs/telescope.lua
horizontal = {
prompt_position = "top",
preview_width = 0.55,
},
width = 0.87,
height = 0.80,
},
mappings = {
n = {
["n"] = "move_selection_next",
["e"] = "move_selection_previous",
["w"] = "preview_scrolling_up",
["r"] = "preview_scrolling_down",
["a"] = "preview_scrolling_left",
["s"] = "preview_scrolling_right",
["q"] = require("telescope.actions").close,
},
},
},
},
dependencies = { "nvim-lua/plenary.nvim" },
keys = {
{ "<leader><leader>", "<cmd>Telescope find_files<CR>", desc = "Find Files" },
{ "<leader>fc", "<cmd>Telescope find_files cwd=~/.config/nvim<CR>", desc = "Edit configs" },
{ "<leader>/", "<cmd>Telescope live_grep<CR>", desc = "Grep Files" },
{ "<leader>;", "<cmd>Telescope<CR>", desc = "Show Telescope Commands" },
{ "<leader>ui", "<cmd>FzfLua colorscheme<CR>", desc = "Change colorscheme" },
{ "<leader>pp", "<cmd>Telescope projects<CR>", desc = "List all Projects" },
{ "<leader>pg", "<cmd>Telescope projects<CR>", desc = "List all Git Projects" },
{ "<leader>ps", "<cmd>Telescope session-lens<CR>", desc = "List all sessions" },
{ "<leader>gs", "<cmd>Telescope git_status<CR>", desc = "Git Status" },
{ "<leader>gt", "<cmd>Telescope git_branches<CR>", desc = "Git Branches" },
{ "<leader>gc", "<cmd>Telescope git_commits<CR>", desc = "Show commits" },
{ "<leader>fb", "<cmd>Telescope buffers<CR>", desc = "List Buffers" },
{ "<leader>ff", "<cmd>Telescope fd<CR>", desc = "Find Files" },
{ "<leader>fh", "<cmd>Telescope oldfiles<CR>", desc = "Recent Files" },
{ "<leader>ce", "<cmd>Telescope diagnostics<CR>", desc = "Navigate errors/warnings" },
{ "<leader>cs", "<cmd>Telescope treesitter<CR>", desc = "Search symbols" },
{ "<leader>cS", "<cmd>Telescope grep_string<CR>", desc = "Search current symbol" },
{ "<leader>bB", "<cmd>Telescope buffers<CR>", desc = "List Buffers" },
{ "<leader>fl", "<cmd>Telescope filetypes", desc = "Set Filetype/Lang to ..." },
},
}

View file

@ -0,0 +1,26 @@
local function get_highlight()
if vim.g.colors_name == "catppuccin" then
-- NOTE: This won't work since no integration is available
return require("catppuccin.groups.integrations.bufferline").get()
-- return require("rose-pine.plugins.toggleterm")
elseif vim.g.colors_name == "rose-pine" then
return require("rose-pine.plugins.toggleterm")
end
end
return {
"akinsho/toggleterm.nvim",
keys = {
{ "<leader>!", "<cmd>ToggleTerm direction=float<CR>", desc = "Toggle Terminal" },
{ "<leader>tf", "<cmd>ToggleTerm direction=float<CR>", desc = "Toggle Terminal" },
{ "<leader>tt", "<cmd>ToggleTerm<CR>", desc = "Spawn a float terminal" },
},
event = "ColorScheme",
opts = {
highlights = get_highlight(),
},
cmd = {
"ToggleTerm",
"LazyGit",
},
}

View file

@ -0,0 +1,37 @@
return {
"folke/trouble.nvim",
opts = {}, -- for default options, refer to the configuration section for custom setup.
cmd = "Trouble",
keys = {
{
"<leader>eE",
"<cmd>Trouble diagnostics toggle<cr>",
desc = "Diagnostics (Trouble)",
},
{
"<leader>ee",
"<cmd>Trouble diagnostics toggle filter.buf=0<cr>",
desc = "Buffer Diagnostics (Trouble)",
},
{
"<leader>es",
"<cmd>Trouble symbols toggle focus=false<cr>",
desc = "Symbols (Trouble)",
},
{
"<leader>el",
"<cmd>Trouble lsp toggle focus=false win.position=right<cr>",
desc = "LSP Definitions / references / ... (Trouble)",
},
{
"<leader>eL",
"<cmd>Trouble loclist toggle<cr>",
desc = "Location List (Trouble)",
},
{
"<leader>ef",
"<cmd>Trouble qflist toggle<cr>",
desc = "Quickfix List (Trouble)",
},
},
}

View file

@ -0,0 +1,16 @@
return {
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
preset = "modern",
},
keys = {
{
"<leader>?",
function()
require("which-key").show({ global = false })
end,
desc = "Buffer Local Keymaps (which-key)",
},
},
}