diff --git a/home/dot_config/nvim/ftplugin/json.lua b/home/dot_config/nvim/ftplugin/json.lua index 33def5f..1c3e755 100644 --- a/home/dot_config/nvim/ftplugin/json.lua +++ b/home/dot_config/nvim/ftplugin/json.lua @@ -1,8 +1,8 @@ -vim.keymap.set("n", "mp", '!jq', { - desc = "Pretiffy json", - buffer = true -}) -vim.keymap.set("i", "p", '%!jq', { - desc = "Pretiffy json", - buffer = true -}) +local prefmap = { + { keys = "p", cmd = "%!jq", opts = { desc = "Mark the file as executable" } }, +} + +local set_buf_keymaps_prefix = require("keymaps.utils").set_buf_keymaps_prefix +-- local set_buf_keymaps = require("keymaps.utils").set_buf_keymaps + +set_buf_keymaps_prefix(prefmap) diff --git a/home/dot_config/nvim/ftplugin/jsonc.lua b/home/dot_config/nvim/ftplugin/jsonc.lua index 33def5f..1c3e755 100644 --- a/home/dot_config/nvim/ftplugin/jsonc.lua +++ b/home/dot_config/nvim/ftplugin/jsonc.lua @@ -1,8 +1,8 @@ -vim.keymap.set("n", "mp", '!jq', { - desc = "Pretiffy json", - buffer = true -}) -vim.keymap.set("i", "p", '%!jq', { - desc = "Pretiffy json", - buffer = true -}) +local prefmap = { + { keys = "p", cmd = "%!jq", opts = { desc = "Mark the file as executable" } }, +} + +local set_buf_keymaps_prefix = require("keymaps.utils").set_buf_keymaps_prefix +-- local set_buf_keymaps = require("keymaps.utils").set_buf_keymaps + +set_buf_keymaps_prefix(prefmap) diff --git a/home/dot_config/nvim/ftplugin/markdown.lua b/home/dot_config/nvim/ftplugin/markdown.lua index 6af5a0a..f3610cf 100644 --- a/home/dot_config/nvim/ftplugin/markdown.lua +++ b/home/dot_config/nvim/ftplugin/markdown.lua @@ -1,3 +1,16 @@ vim.bo.shiftwidth = 2 vim.bo.softtabstop = 2 vim.bo.expandtab = true + +local bufmap = { + { mode = "x", keys = "i", cmd = 'c*"*', opt = { desc = "Add italic to selected text" } }, + { mode = "x", keys = "b", cmd = 'c**"**', opt = { desc = "Add bold to selected text" } }, + { mode = "x", keys = "c", cmd = 'c`"`', opt = { desc = "Add code block to selected text" } }, + { mode = "x", keys = "d", cmd = 'c~~"~~', opt = { desc = "Add strikethrough to selected text" } }, + { mode = "x", keys = "h", cmd = 'c=="==', opt = { desc = "Add highlight to selected text" } }, +} + +-- local set_buf_keymaps_prefix = require("keymaps.utils").set_buf_keymaps_prefix +local set_buf_keymaps = require("keymaps.utils").set_buf_keymaps + +set_buf_keymaps(bufmap) diff --git a/home/dot_config/nvim/ftplugin/org.lua b/home/dot_config/nvim/ftplugin/org.lua new file mode 100644 index 0000000..85e624a --- /dev/null +++ b/home/dot_config/nvim/ftplugin/org.lua @@ -0,0 +1,11 @@ +local prefmap = { + { mode = "x", keys = "i", cmd = 'c//"', opt = { desc = "Add italic to selected text" } }, + { mode = "x", keys = "b", cmd = 'c*"*', opt = { desc = "Add bold to selected text" } }, + { mode = "x", keys = "d", cmd = 'c+"+', opt = { desc = "Add strikethrough to selected text" } }, + { mode = "x", keys = "h", cmd = 'c~"~', opt = { desc = "Add highlight to selected text" } }, +} + +local set_buf_keymaps_prefix = require("keymaps.utils").set_buf_keymaps_prefix +-- local set_buf_keymaps = require("keymaps.utils").set_buf_keymaps + +set_buf_keymaps_prefix(prefmap) diff --git a/home/dot_config/nvim/ftplugin/sh.lua b/home/dot_config/nvim/ftplugin/sh.lua index 4d1cafd..4132674 100644 --- a/home/dot_config/nvim/ftplugin/sh.lua +++ b/home/dot_config/nvim/ftplugin/sh.lua @@ -1,16 +1,9 @@ -vim.keymap.set("n", "mx", '!chmod +x "%"', { - desc = "Mark the file as executable", - buffer = true -}) -vim.keymap.set("i", "x", '!chmod +x "%"', { - desc = "Mark the file as executable", - buffer = true -}) -vim.keymap.set("n", "mX", '!chmod u+x "%"', { - desc = "Mark the file as executable (current user only)", - buffer = true -}) -vim.keymap.set("i", "X", '!chmod u+x "%"', { - desc = "Mark the file as executable (current user only)", - buffer = true -}) +local prefmap = { + { keys = "x", cmd = '!chmod +x "%"', opts = { desc = "Mark the file as executable" } }, + { keys = "X", cmd = '!chmod u+x "%"', opts = { desc = "Mark the file as executable (current user only)" } }, +} + +local set_buf_keymaps_prefix = require("keymaps.utils").set_buf_keymaps_prefix +-- local set_buf_keymaps = require("keymaps.utils").set_buf_keymaps + +set_buf_keymaps_prefix(prefmap) diff --git a/home/dot_config/nvim/ftplugin/tex.lua b/home/dot_config/nvim/ftplugin/tex.lua new file mode 100644 index 0000000..d0aeafc --- /dev/null +++ b/home/dot_config/nvim/ftplugin/tex.lua @@ -0,0 +1,17 @@ +local bufmap = { + { mode = "x", keys = "i", cmd = 'c\\textit{"}', opt = { desc = "Add italic to selected text" } }, + { mode = "x", keys = "b", cmd = 'c\\textbf{"}', opt = { desc = "Add bold to selected text" } }, + { + mode = "x", + keys = "c", + cmd = 'c\\begin{verbatim}"\\end{verbatim}', + opt = { desc = "Add code block to selected text" }, + }, + { mode = "x", keys = "d", cmd = 'c\\sout{"}', opt = { desc = "Add strikethrough to selected text" } }, + { mode = "x", keys = "h", cmd = 'c\\hl{"}', opt = { desc = "Add highlight to selected text" } }, + { mode = "n", keys = "cc", cmd = "w", opt = { desc = "Save and compile tex file" } }, +} + +local set_buf_keymaps = require("keymaps.utils").set_buf_keymaps + +set_buf_keymaps(bufmap) diff --git a/home/dot_config/nvim/init.lua b/home/dot_config/nvim/init.lua index 5515e4f..6bf03ce 100644 --- a/home/dot_config/nvim/init.lua +++ b/home/dot_config/nvim/init.lua @@ -10,12 +10,12 @@ require("config.options") local term = os.getenv("TERM") or "" if vim.g.vscode then -- TODO: VSCode Neovim Integration - require("config.vscode") + require("profiles.vscode") elseif term == "linux" then -- Under tty - require("config.tty") + require("profiles.tty") vim.cmd("colorscheme vim") -- Use minimal colorscheme else - require("config.plugins") + require("profiles.vanilla") require("config.colorscheme") end require("config.keymaps") diff --git a/home/dot_config/nvim/lua/config/lsp.lua b/home/dot_config/nvim/lua/config/lsp.lua index 17cc6bc..be6c22e 100644 --- a/home/dot_config/nvim/lua/config/lsp.lua +++ b/home/dot_config/nvim/lua/config/lsp.lua @@ -1,3 +1,5 @@ +-- Source all lsp definition in +-- ~/.config/nvim/lsp/*.lua local lsp_configs = {} for _, v in ipairs(vim.api.nvim_get_runtime_file("lsp/*", true)) do local name = vim.fn.fnamemodify(v, ":t:r") diff --git a/home/dot_config/nvim/lua/config/options.lua b/home/dot_config/nvim/lua/config/options.lua index 98ec308..1ad8e36 100644 --- a/home/dot_config/nvim/lua/config/options.lua +++ b/home/dot_config/nvim/lua/config/options.lua @@ -1,7 +1,8 @@ -- is space vim.g.mapleader = " " vim.g.maplocalleader = "\\" --- Disable netrw (file explorer) use NvimTree instead +-- Disable netrw (file explorer) use neo-tree instead +-- See: lua/plugins/mod/neo-tree.lua vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 -- Disable Perl diff --git a/home/dot_config/nvim/lua/config/servers.lua b/home/dot_config/nvim/lua/config/servers.lua deleted file mode 100644 index 0b2b37a..0000000 --- a/home/dot_config/nvim/lua/config/servers.lua +++ /dev/null @@ -1,36 +0,0 @@ ---- 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 diff --git a/home/dot_config/nvim/lua/keymaps/basic.lua b/home/dot_config/nvim/lua/keymaps/basic.lua index 216c3ae..1066dc5 100644 --- a/home/dot_config/nvim/lua/keymaps/basic.lua +++ b/home/dot_config/nvim/lua/keymaps/basic.lua @@ -1,6 +1,6 @@ local mode_arrow = { "n", "v", "s", "x", "o" } -local keymaps_basic = { -- Modification of Original Keymap - Colemak +local keymaps_basic = { -- https://github.com/LazyVim/LazyVim/blob/d1529f650fdd89cb620258bdeca5ed7b558420c7/lua/lazyvim/config/keymaps.lua#L8 { mode = mode_arrow, @@ -95,6 +95,8 @@ local keymaps_basic = { -- Modification of Original Keymap - Colemak cmd = "5e", opts = { desc = "Down 5 Lines" }, }, + { keys = "", cmd = "", opts = { desc = "Focus on other panel" } }, + { keys = "", cmd = "%" }, { 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" }, diff --git a/home/dot_config/nvim/lua/keymaps/buffer.lua b/home/dot_config/nvim/lua/keymaps/buffer.lua deleted file mode 100644 index 1df8ae8..0000000 --- a/home/dot_config/nvim/lua/keymaps/buffer.lua +++ /dev/null @@ -1,96 +0,0 @@ --- Use leader + m for `major`, inspired by emacs --- If under mode = 'n' / 'v': m and will be added by default --- If under `i` -local bufmap = { - markdown = { - { mode = "x", keys = "i", cmd = 'c*"*', opt = { desc = "Add italic to selected text" } }, - { mode = "x", keys = "b", cmd = 'c**"**', opt = { desc = "Add bold to selected text" } }, - { mode = "x", keys = "c", cmd = 'c`"`', opt = { desc = "Add code block to selected text" } }, - { mode = "x", keys = "d", cmd = 'c~~"~~', opt = { desc = "Add strikethrough to selected text" } }, - { mode = "x", keys = "h", cmd = 'c=="==', opt = { desc = "Add highlight to selected text" } }, - }, - tex = { - { mode = "x", keys = "i", cmd = 'c\\textit{"}', opt = { desc = "Add italic to selected text" } }, - { mode = "x", keys = "b", cmd = 'c\\textbf{"}', opt = { desc = "Add bold to selected text" } }, - { - mode = "x", - keys = "c", - cmd = 'c\\begin{verbatim}"\\end{verbatim}', - opt = { desc = "Add code block to selected text" }, - }, - { mode = "x", keys = "d", cmd = 'c\\sout{"}', opt = { desc = "Add strikethrough to selected text" } }, - { mode = "x", keys = "h", cmd = 'c\\hl{"}', opt = { desc = "Add highlight to selected text" } }, - { mode = "n", keys = "cc", cmd = "w", opt = { desc = "Save and compile tex file" } }, - -- { mode = "i", keys = "", cmd = "w", opt = { desc = "Save and compile tex file" } }, - }, - org = { - { mode = "x", keys = "i", cmd = 'c//"', opt = { desc = "Add italic to selected text" } }, - { mode = "x", keys = "b", cmd = 'c*"*', opt = { desc = "Add bold to selected text" } }, - -- { - -- mode = "x", - -- keys = "c", - -- cmd = 'c#+BEGIN_SRC"#+END_SRC', - -- opt = { desc = "Add code block to selected text" }, - -- }, - { mode = "x", keys = "d", cmd = 'c+"+', opt = { desc = "Add strikethrough to selected text" } }, - { mode = "x", keys = "h", cmd = 'c~"~', opt = { desc = "Add highlight to selected text" } }, - }, - sh = { - { mode = "n", keys = "mx", cmd = "!chmod u+x %", opt = { desc = "Mark the file as executable" } }, - }, - json = { - { mode = "n", keys = "mp", cmd = "%!jq", opt = { desc = "Prettify json" } }, - }, -} - --- Shallow copy -local function extend(tbl1, tbl2) - local t = {} - for _, v in ipairs(tbl1 or {}) do - table.insert(t, v) - end - for _, v in ipairs(tbl2 or {}) do - table.insert(t, v) - end - return t -end - -for _, ft in ipairs({ "bash", "zsh", "fish", "python" }) do - bufmap[ft] = extend(bufmap[ft], bufmap.sh) -end - -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 = "" .. 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 = "" .. mapping.keys - end - vim.keymap.set(mapping.mode, mapping.keys, mapping.cmd, opts) - end - end, - }) - end -end - -setup_buffer_maps(bufmap) diff --git a/home/dot_config/nvim/lua/keymaps/init.lua b/home/dot_config/nvim/lua/keymaps/init.lua index a36a6bc..a75939f 100644 --- a/home/dot_config/nvim/lua/keymaps/init.lua +++ b/home/dot_config/nvim/lua/keymaps/init.lua @@ -11,7 +11,7 @@ local keymaps_basic = require("keymaps.basic") local keymaps_modifier = require("keymaps.modifier") local keymaps_terminal = require("keymaps.tmap") -require("keymaps.buffer") +-- require("keymaps.buffer") utils.set_keymaps(keymaps_general) utils.set_keymaps(keymaps_basic) diff --git a/home/dot_config/nvim/lua/keymaps/leaders.lua b/home/dot_config/nvim/lua/keymaps/leaders.lua index abb938b..e2d3af0 100644 --- a/home/dot_config/nvim/lua/keymaps/leaders.lua +++ b/home/dot_config/nvim/lua/keymaps/leaders.lua @@ -86,6 +86,16 @@ local leader_mappings = { cmd = ":let @+ = expand('%') . ':' . line('.')", opts = { desc = "Copy relative file path with line number" }, }, + { keys= "p", + cmd = function() + local filepath = vim.fn.expand('%:.') + if filepath == '' then + vim.notify("No file path (buffer is unnamed)", vim.log.levels.WARN) + else + vim.notify(filepath, vim.log.levels.INFO) + end + end, opts = { desc = "Print current file path" } + } }, g = { -- +git/version control }, diff --git a/home/dot_config/nvim/lua/keymaps/tmap.lua b/home/dot_config/nvim/lua/keymaps/tmap.lua index fdd9c48..d6e227f 100644 --- a/home/dot_config/nvim/lua/keymaps/tmap.lua +++ b/home/dot_config/nvim/lua/keymaps/tmap.lua @@ -1,3 +1,5 @@ +-- Terminal Keymaps +-- Use h|j|k|l to navigate directly local M = { { keys = "h", diff --git a/home/dot_config/nvim/lua/keymaps/utils.lua b/home/dot_config/nvim/lua/keymaps/utils.lua index 66bb98e..e5cc81c 100644 --- a/home/dot_config/nvim/lua/keymaps/utils.lua +++ b/home/dot_config/nvim/lua/keymaps/utils.lua @@ -21,13 +21,28 @@ M.set_lang_keymaps = function(maps) }) end +-- This fuction is used in ftplugin/*.lua M.set_buf_keymaps = function(maps) - vim.api.create_autocmd("BufEnter", { - pattern = maps.filetype, - callback = function() - M.set_keymaps(maps.keymaps) - end, - }) + if not maps then + return + end + for _, map in ipairs(maps) do + local opts = vim.tbl_extend("force", map.opt or {}, { buffer = true }) + vim.keymap.set(map.mode, map.keys, map.cmd, opts) + end +end + +M.set_buf_keymaps_prefix = function(maps) + local n_prefix = "m" + local i_prefix = "" + if not maps then + return + end + for _, map in ipairs(maps) do + local opts = vim.tbl_extend("force", map.opt or {}, { buffer = true }) + vim.keymap.set("n", n_prefix .. map.keys, map.cmd, opts) + vim.keymap.set("i", i_prefix .. map.keys, map.cmd, opts) + end end return M diff --git a/home/dot_config/nvim/lua/plugins/lang/markdown/markview.lua.bak b/home/dot_config/nvim/lua/plugins/lang/markdown/markview.lua.bak deleted file mode 100644 index 39c52d0..0000000 --- a/home/dot_config/nvim/lua/plugins/lang/markdown/markview.lua.bak +++ /dev/null @@ -1,29 +0,0 @@ --- 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", - }, - }, - }, -} diff --git a/home/dot_config/nvim/lua/plugins/lang/org.lua b/home/dot_config/nvim/lua/plugins/lang/org.lua index a74c3d4..f4d181e 100644 --- a/home/dot_config/nvim/lua/plugins/lang/org.lua +++ b/home/dot_config/nvim/lua/plugins/lang/org.lua @@ -69,7 +69,7 @@ return { -- require("telescope").load_extension("orgmode") -- vim.keymap.set("n", "r", require("telescope").extensions.orgmode.refile_heading) -- vim.keymap.set("n", "oP", require("telescope").extensions.orgmode.search_headings) - vim.keymap.set("n", "op", "FzfLua files cwd=~/OrgFiles") + -- vim.keymap.set("n", "op", "FzfLua files cwd=~/OrgFiles") -- vim.keymap.set("n", "li", require("telescope").extensions.orgmode.insert_link) end, }, diff --git a/home/dot_config/nvim/lua/plugins/lazy-nvim.lua b/home/dot_config/nvim/lua/plugins/lazy-nvim.lua index f511aca..272c178 100644 --- a/home/dot_config/nvim/lua/plugins/lazy-nvim.lua +++ b/home/dot_config/nvim/lua/plugins/lazy-nvim.lua @@ -6,7 +6,7 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then if vim.v.shell_error ~= 0 then vim.api.nvim_echo({ { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, - { out, "WarningMsg" }, + { out, "WarningMsg" }, { "\nPress any key to exit..." }, }, true, {}) vim.fn.getchar() @@ -14,9 +14,3 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then 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 = "\\" diff --git a/home/dot_config/nvim/lua/config/tty.lua b/home/dot_config/nvim/lua/profiles/tty.lua similarity index 100% rename from home/dot_config/nvim/lua/config/tty.lua rename to home/dot_config/nvim/lua/profiles/tty.lua diff --git a/home/dot_config/nvim/lua/config/plugins.lua b/home/dot_config/nvim/lua/profiles/vanilla.lua similarity index 100% rename from home/dot_config/nvim/lua/config/plugins.lua rename to home/dot_config/nvim/lua/profiles/vanilla.lua diff --git a/home/dot_config/nvim/lua/config/vscode.lua b/home/dot_config/nvim/lua/profiles/vscode.lua similarity index 100% rename from home/dot_config/nvim/lua/config/vscode.lua rename to home/dot_config/nvim/lua/profiles/vscode.lua