From cb8c9208e160837fd9c4c3b88e99a2fddf20dadf Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 24 Jul 2024 21:59:41 +0200 Subject: [PATCH 001/247] update which-key conf and some mappings --- lua/config/which-key.lua | 60 ++-------------------------------------- lua/mappings.lua | 8 ++++-- 2 files changed, 8 insertions(+), 60 deletions(-) diff --git a/lua/config/which-key.lua b/lua/config/which-key.lua index 10c0c413..13b736c9 100644 --- a/lua/config/which-key.lua +++ b/lua/config/which-key.lua @@ -1,60 +1,6 @@ require("which-key").setup { - plugins = { - marks = true, -- shows a list of your marks on ' and ` - registers = true, -- shows your registers on " in NORMAL or in INSERT mode - spelling = { - enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions - suggestions = 9, -- how many suggestions should be shown in the list? - }, - -- the presets plugin, adds help for a bunch of default keybindings in Neovim - -- No actual key bindings are created - presets = { - operators = true, -- adds help for operators like d, y, ... and registers them for motion / text object completion - motions = true, -- adds help for motions - text_objects = true, -- help for text objects triggered after entering an operator - windows = true, -- default bindings on - nav = true, -- misc bindings to work with windows - z = true, -- bindings for folds, spelling and others prefixed with z - g = true, -- bindings for prefixed with g - }, - }, - -- add operators that will trigger motion and text object completion - -- to enable all native operators, set the preset / operators plugin above - operators = { gc = "Comments" }, - key_labels = { - -- override the label used to display some keys. It doesn't effect WK in any other way. - -- For example: - -- [""] = "SPC", - -- [""] = "RET", - -- [""] = "TAB", - }, + preset = "modern", icons = { - breadcrumb = "»", -- symbol used in the command line area that shows your active key combo - separator = "➜", -- symbol used between a key and it's label - group = "+", -- symbol prepended to a group - }, - window = { - border = "none", -- none, single, double, shadow - position = "bottom", -- bottom, top - margin = { 0, 0, 0, 0 }, -- extra window margin [top, right, bottom, left] - padding = { 1, 0, 1, 0 }, -- extra window padding [top, right, bottom, left] - }, - layout = { - height = { min = 1, max = 25 }, -- min and max height of the columns - width = { min = 20, max = 50 }, -- min and max width of the columns - spacing = 1, -- spacing between columns - align = "center", -- align columns left, center or right - }, - ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label - hidden = { "", "", "", "", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate - show_help = true, -- show help message on the command line when the popup is visible - triggers = "auto", -- automatically setup triggers - -- triggers = {""} -- or specify a list manually - - triggers_blacklist = { - -- list of mode / prefixes that should never be hooked by WhichKey - -- this is mostly relevant for key maps that start with a native binding - -- most people should not need to change this - n = { "o", "O" }, - }, + mappings = false + } } diff --git a/lua/mappings.lua b/lua/mappings.lua index fb7091e2..96a07cc7 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -217,7 +217,7 @@ keymap.set("n", "cb", function() local timer = uv.new_timer() timer:start(0, 100, vim.schedule_wrap(function() - vim.cmd[[ + vim.cmd [[ set cursorcolumn! set cursorline! ]] @@ -227,5 +227,7 @@ keymap.set("n", "cb", function() end cnt = cnt + 1 - end)) -end) + end) + ) +end, + { desc = "show cursor" }) From ca7430056c6c6cfe68b98178bcfde6a85b9023f7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 25 Jul 2024 21:31:53 +0200 Subject: [PATCH 002/247] update to neovim version 0.10.1 --- README.md | 6 +++--- init.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7116a590..c29e7f3e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Latest release - Neovim minimum version + Neovim minimum version Top languages @@ -21,8 +21,8 @@ - - + + diff --git a/init.lua b/init.lua index baa4ae65..ee66d272 100644 --- a/init.lua +++ b/init.lua @@ -14,11 +14,11 @@ vim.loader.enable() local version = vim.version -- check if we have the latest stable version of nvim -local expected_ver = "0.10.0" -local ev = version.parse(expected_ver) +local expected_ver = "0.10.1" +local expect_ver = version.parse(expected_ver) local actual_ver = version() -local result = version.cmp(ev, {actual_ver.major, actual_ver.minor, actual_ver.patch}) +local result = version.cmp(expect_ver, actual_ver) if result ~= 0 then local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch) From e815de294ff124ed36e95ee8540472a28755088c Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 26 Jul 2024 21:24:51 +0200 Subject: [PATCH 003/247] update plugin for markdown preview --- README.md | 4 ++-- lua/plugin_specs.lua | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c29e7f3e..176e43fa 100644 --- a/README.md +++ b/README.md @@ -169,8 +169,8 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu | `gc` | Normal | Linux/macOS/Win | Run git commit | | `gpl` | Normal | Linux/macOS/Win | Run git pull | | `gpu` | Normal | Linux/macOS/Win | Run git push | -| `gl` | Normal/Visual | Linux/macOS/Win | Get perm link for current/visually-select lines -| `gb` | Normal | macOS | Browse current git repo in browser +| `gl` | Normal/Visual | Linux/macOS/Win | Get perm link for current/visually-select lines | +| `gb` | Normal | macOS | Browse current git repo in browser | | `` | Normal | Linux/macOS/Win | Compile&run current source file (for C++, LaTeX, Lua, Python) | | `` | Normal | Linux/macOS/Win | Toggle spell checking | | `` | Normal | Linux/macOS/Win | Toggle paste mode | diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index f18dda42..68d07d4c 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -122,9 +122,10 @@ local plugin_specs = { }, }, { - "lukas-reineke/headlines.nvim", - dependencies = "nvim-treesitter/nvim-treesitter", - config = true, -- or `opts = {}` + 'MeanderingProgrammer/markdown.nvim', + main = "render-markdown", + opts = {}, + dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, }, -- A list of colorscheme plugin you may want to try. Find what suits you. { "navarasu/onedark.nvim", lazy = true }, From 719fbfc1ab6fe0ef4bd5ca0a1ad322ed08eb4c31 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 30 Jul 2024 23:34:53 +0200 Subject: [PATCH 004/247] update lua_ls settings --- lua/config/lsp.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index aac7a90c..f43aa583 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -231,11 +231,12 @@ if utils.executable("lua-language-server") then }, workspace = { -- Make the server aware of Neovim runtime files, - -- see also https://github.com/LuaLS/lua-language-server/wiki/Libraries#link-to-workspace . - -- Lua-dev.nvim also has similar settings for lua ls, https://github.com/folke/neodev.nvim/blob/main/lua/neodev/luals.lua . + -- see also https://luals.github.io/wiki/settings/#workspacelibrary library = { vim.env.VIMRUNTIME, fn.stdpath("config"), + -- make lua_ls aware of functions under vim.uv + "${3rd}/luv/library" }, maxPreload = 2000, preloadFileSize = 50000, From 6e137fe9a3ee215f82a46a05e77be51ac17151f7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 31 Jul 2024 01:08:50 +0200 Subject: [PATCH 005/247] make firenvim work again 1. fix build issue 2. fix PATH env issue --- lua/plugin_specs.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 68d07d4c..17de0510 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -15,6 +15,12 @@ end vim.opt.rtp:prepend(lazypath) -- check if firenvim is active +-- macOS will reset the PATH when firenvim starts a nvim process, causing the PATH variable to change unexpectedly. +-- Here we are trying to get the correct PATH and use it for firenvim. +-- See also https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md#make-sure-firenvims-path-is-the-same-as-neovims +local path_env = vim.env.PATH +local prologue = string.format('export PATH="%s"', path_env) + local firenvim_not_active = function() return not vim.g.started_by_firenvim end @@ -419,17 +425,13 @@ local plugin_specs = { { "glacambre/firenvim", enabled = function() - if vim.g.is_win or vim.g.is_mac then - return true - end - return false + local result = vim.g.is_win or vim.g.is_mac + return result end, - build = function() - vim.fn["firenvim#install"](0) - end, - lazy = true, + -- it seems that we can only call the firenvim function directly. + -- Using vim.fn or vim.cmd to call this function will fail. + build = string.format(":call firenvim#install(0, '%s')", prologue) }, - -- Debugger plugin { "sakhnik/nvim-gdb", From 9efadac8fb8506f31f0d48deb90e3ce543fe5120 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 31 Jul 2024 22:13:07 +0200 Subject: [PATCH 006/247] update lazy.nvim config --- lua/plugin_specs.lua | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 17de0510..8c55f8bc 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -128,10 +128,10 @@ local plugin_specs = { }, }, { - 'MeanderingProgrammer/markdown.nvim', - main = "render-markdown", - opts = {}, - dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, + "MeanderingProgrammer/markdown.nvim", + main = "render-markdown", + opts = {}, + dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-tree/nvim-web-devicons" }, }, -- A list of colorscheme plugin you may want to try. Find what suits you. { "navarasu/onedark.nvim", lazy = true }, @@ -176,7 +176,7 @@ local plugin_specs = { { "lukas-reineke/indent-blankline.nvim", event = "VeryLazy", - main = 'ibl', + main = "ibl", config = function() require("config.indent-blankline") end, @@ -229,9 +229,9 @@ local plugin_specs = { -- Automatic insertion and deletion of a pair of characters { - 'windwp/nvim-autopairs', - event = "InsertEnter", - config = true + "windwp/nvim-autopairs", + event = "InsertEnter", + config = true, }, -- Comment plugin @@ -323,7 +323,7 @@ local plugin_specs = { { "rhysd/committia.vim", lazy = true }, { - "sindrets/diffview.nvim" + "sindrets/diffview.nvim", }, { @@ -430,7 +430,7 @@ local plugin_specs = { end, -- it seems that we can only call the firenvim function directly. -- Using vim.fn or vim.cmd to call this function will fail. - build = string.format(":call firenvim#install(0, '%s')", prologue) + build = string.format(":call firenvim#install(0, '%s')", prologue), }, -- Debugger plugin { @@ -497,13 +497,14 @@ local plugin_specs = { }, } --- configuration for lazy itself. -local lazy_opts = { +require("lazy").setup { + spec = plugin_specs, ui = { border = "rounded", title = "Plugin Manager", title_pos = "center", }, + rocks = { + enabled = false + }, } - -require("lazy").setup(plugin_specs, lazy_opts) From bbb8545403d276fa6bc56e956906fb14f871553f Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 2 Aug 2024 00:22:04 +0200 Subject: [PATCH 007/247] update lualine config - rearrange a few components - add and remove a few components --- lua/config/statusline.lua | 64 ++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/lua/config/statusline.lua b/lua/config/statusline.lua index 0563ba64..466edf6c 100644 --- a/lua/config/statusline.lua +++ b/lua/config/statusline.lua @@ -99,12 +99,12 @@ end local virtual_env = function() -- only show virtual env for Python - if vim.bo.filetype ~= 'python' then + if vim.bo.filetype ~= "python" then return "" end - local conda_env = os.getenv('CONDA_DEFAULT_ENV') - local venv_path = os.getenv('VIRTUAL_ENV') + local conda_env = os.getenv("CONDA_DEFAULT_ENV") + local venv_path = os.getenv("VIRTUAL_ENV") if venv_path == nil then if conda_env == nil then @@ -113,17 +113,32 @@ local virtual_env = function() return string.format(" %s (conda)", conda_env) end else - local venv_name = vim.fn.fnamemodify(venv_path, ':t') + local venv_name = vim.fn.fnamemodify(venv_path, ":t") return string.format(" %s (venv)", venv_name) end end +local get_active_lsp = function() + local msg = "No Active Lsp" + local buf_ft = vim.api.nvim_get_option_value("filetype", {}) + local clients = vim.lsp.get_clients { bufnr = 0 } + 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 + require("lualine").setup { options = { icons_enabled = true, theme = "auto", - -- component_separators = { left = "", right = "" }, - -- section_separators = { left = "", right = "" }, section_separators = "", component_separators = "", disabled_filetypes = {}, @@ -132,18 +147,29 @@ require("lualine").setup { sections = { lualine_a = { "mode" }, lualine_b = { - "branch", { - "diff", - source = diff, + "branch", + fmt = function(name, context) + -- truncate branch name in case the name is too long + return string.sub(name, 1, 20) + end, }, { virtual_env, - color = { fg = 'black', bg = "#F1CA81" } - } + color = { fg = "black", bg = "#F1CA81" }, + }, }, lualine_c = { - "filename", + { + "filename", + symbols = { + readonly = "[🔒]", + }, + }, + { + "diff", + source = diff, + }, { ime_state, color = { fg = "black", bg = "#f46868" }, @@ -152,13 +178,19 @@ require("lualine").setup { spell, color = { fg = "black", bg = "#a7c080" }, }, + }, + lualine_x = { + { + get_active_lsp, + icon = " LSP:", + }, { "diagnostics", sources = { "nvim_diagnostic" }, - symbols = {error = '🆇 ', warn = '⚠️ ', info = 'ℹ️ ', hint = ' '}, + symbols = { error = "🆇 ", warn = "⚠️ ", info = "ℹ️ ", hint = " " }, }, }, - lualine_x = { + lualine_y = { "encoding", { "fileformat", @@ -170,9 +202,6 @@ require("lualine").setup { }, "filetype", }, - lualine_y = { - "location", - }, lualine_z = { { trailing_space, @@ -182,6 +211,7 @@ require("lualine").setup { mixed_indent, color = "WarningMsg", }, + "progress" }, }, inactive_sections = { From beec97c0865795e91c8734f0c7048d453c2bd6ab Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 2 Aug 2024 17:28:28 +0200 Subject: [PATCH 008/247] Fix firenvim and LeaderF build issues In lazy.nvim, the `build` parameter accept value in different format. If the value is 1. a string and starts with `:`, it will be treated as vim command 2. a string and starts without `:`, it will be treated as shell command 3. a function. Lazy.nvim will run this function I compared closely between case 1 and case 3. In case 1, when lazy.nvim runs the viml command, the runtimepath is already populated with the current plugin we are trying to build. However in case 3, the runtimepath is not populated with the plugin path, which means that any command you run by this plugin is not available. So I did it in a hacky way to add the plugin path to runtimepath manually, and source it manually using `:runtime` command. The `: runtime` command is needed because in the init process, adding the plugin path to runtimepath does not ensure that the script under this plugin is sourced immediately. So if we want to use the command/function immediately, we need to source it manually, see also https://github.com/neovim/neovim/issues/29957. --- lua/plugin_specs.lua | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 8c55f8bc..7b58b85b 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -1,6 +1,7 @@ local utils = require("utils") -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +local plugin_dir = vim.fn.stdpath("data") .. "/lazy" +local lazypath = plugin_dir .. "/lazy.nvim" if not vim.uv.fs_stat(lazypath) then vim.fn.system { @@ -15,12 +16,6 @@ end vim.opt.rtp:prepend(lazypath) -- check if firenvim is active --- macOS will reset the PATH when firenvim starts a nvim process, causing the PATH variable to change unexpectedly. --- Here we are trying to get the correct PATH and use it for firenvim. --- See also https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md#make-sure-firenvims-path-is-the-same-as-neovims -local path_env = vim.env.PATH -local prologue = string.format('export PATH="%s"', path_env) - local firenvim_not_active = function() return not vim.g.started_by_firenvim end @@ -114,8 +109,12 @@ local plugin_specs = { "Yggdroot/LeaderF", cmd = "Leaderf", build = function() + local leaderf_path = plugin_dir .. "/LeaderF" + vim.opt.runtimepath:append(leaderf_path) + vim.cmd("runtime! plugin/leaderf.vim") + if not vim.g.is_win then - vim.cmd(":LeaderfInstallCExtension") + vim.cmd("LeaderfInstallCExtension") end end, }, @@ -430,7 +429,20 @@ local plugin_specs = { end, -- it seems that we can only call the firenvim function directly. -- Using vim.fn or vim.cmd to call this function will fail. - build = string.format(":call firenvim#install(0, '%s')", prologue), + build = function() + local firenvim_path = plugin_dir .. "/firenvim" + vim.opt.runtimepath:append(firenvim_path) + vim.cmd("runtime! firenvim.vim") + + -- macOS will reset the PATH when firenvim starts a nvim process, causing the PATH variable to change unexpectedly. + -- Here we are trying to get the correct PATH and use it for firenvim. + -- See also https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md#make-sure-firenvims-path-is-the-same-as-neovims + local path_env = vim.env.PATH + local prologue = string.format('export PATH="%s"', path_env) + -- local prologue = "echo" + local cmd_str = string.format(":call firenvim#install(0, '%s')", prologue) + vim.cmd(cmd_str) + end }, -- Debugger plugin { From 784b435f0e637e496e4bb541bb3d2331c2eeb47f Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 2 Aug 2024 17:41:05 +0200 Subject: [PATCH 009/247] update LeaderF settings --- viml_conf/plugins.vim | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim index 83b6a527..da3252ec 100644 --- a/viml_conf/plugins.vim +++ b/viml_conf/plugins.vim @@ -58,16 +58,6 @@ endif " Only fuzzy-search files names let g:Lf_DefaultMode = 'FullPath' -" Popup window settings -let w = float2nr(&columns * 0.8) -if w > 140 - let g:Lf_PopupWidth = 140 -else - let g:Lf_PopupWidth = w -endif - -let g:Lf_PopupPosition = [0, float2nr((&columns - g:Lf_PopupWidth)/2)] - " Do not use version control tool to list files under a directory since " submodules are not searched by default. let g:Lf_UseVersionControlTool = 0 From bf49e9094752f4d27d2856d0c08f71366efae57d Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 4 Aug 2024 23:02:16 +0200 Subject: [PATCH 010/247] change value for option 'splitkeep' --- viml_conf/options.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/viml_conf/options.vim b/viml_conf/options.vim index 98fb3a6c..f3b9af45 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -6,6 +6,9 @@ set fillchars=fold:\ ,vert:\│,eob:\ ,msgsep:‾,diff:╱ " Split window below/right when creating horizontal/vertical windows set splitbelow splitright +" avoid the flickering when splitting window horizontal +set splitkeep=screen + " Time in milliseconds to wait for a mapped sequence to complete, " see https://unix.stackexchange.com/q/36882/221410 for more info set timeoutlen=500 From 7f4772fd31d020c234b780f0f33376d8e92c422d Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 4 Aug 2024 23:03:56 +0200 Subject: [PATCH 011/247] update setting for colorscheme gruvbox-material --- lua/colorschemes.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 9618b4d5..387b6ec5 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -24,9 +24,9 @@ M.colorscheme_conf = { end, gruvbox_material = function() -- foreground option can be material, mix, or original - vim.g.gruvbox_material_foreground = "material" + vim.g.gruvbox_material_foreground = "original" --background option can be hard, medium, soft - vim.g.gruvbox_material_background = "soft" + vim.g.gruvbox_material_background = "medium" vim.g.gruvbox_material_enable_italic = 1 vim.g.gruvbox_material_better_performance = 1 From 69643e143a72f7e98015f61faba2f2a428d9c79a Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 4 Aug 2024 23:25:17 +0200 Subject: [PATCH 012/247] use plugin nvim-ufo for better folding The settings are copied from https://github.com/kevinhwang91/nvim-ufo/issues/4#issuecomment-1514537245, with some modification. --- lua/config/nvim_ufo.lua | 48 +++++++++++++++++++++++++++++++++++++++++ lua/plugin_specs.lua | 35 +++++++++++++++++++++++++++--- viml_conf/options.vim | 2 +- 3 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 lua/config/nvim_ufo.lua diff --git a/lua/config/nvim_ufo.lua b/lua/config/nvim_ufo.lua new file mode 100644 index 00000000..8d0ffc04 --- /dev/null +++ b/lua/config/nvim_ufo.lua @@ -0,0 +1,48 @@ +local handler = function(virtText, lnum, endLnum, width, truncate) + local newVirtText = {} + local totalLines = vim.api.nvim_buf_line_count(0) + local foldedLines = endLnum - lnum + local suffix = (" 󰁂 %d"):format(foldedLines) + local sufWidth = vim.fn.strdisplaywidth(suffix) + local targetWidth = width - sufWidth + local curWidth = 0 + + for _, chunk in ipairs(virtText) do + local chunkText = chunk[1] + local chunkWidth = vim.fn.strdisplaywidth(chunkText) + if targetWidth > curWidth + chunkWidth then + table.insert(newVirtText, chunk) + else + chunkText = truncate(chunkText, targetWidth - curWidth) + local hlGroup = chunk[2] + table.insert(newVirtText, { chunkText, hlGroup }) + chunkWidth = vim.fn.strdisplaywidth(chunkText) + -- str width returned from truncate() may less than 2nd argument, need padding + if curWidth + chunkWidth < targetWidth then + suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth) + end + break + end + curWidth = curWidth + chunkWidth + end + local rAlignAppndx = math.max(math.min(vim.opt.textwidth["_value"], width - 1) - curWidth - sufWidth, 0) + suffix = (" "):rep(rAlignAppndx) .. suffix + table.insert(newVirtText, { suffix, "MoreMsg" }) + return newVirtText +end + +local opts = {} +opts["fold_virt_text_handler"] = handler + +require("ufo").setup(opts) + +vim.keymap.set("n", "zR", require("ufo").openAllFolds) +vim.keymap.set("n", "zM", require("ufo").closeAllFolds) +vim.keymap.set("n", "zr", require("ufo").openFoldsExceptKinds) +vim.keymap.set("n", "K", function() + local winid = require("ufo").peekFoldedLinesUnderCursor() + if not winid then + -- vim.lsp.buf.hover() + vim.cmd([[ Lspsaga hover_doc ]]) + end +end) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 7b58b85b..551dc855 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -180,7 +180,36 @@ local plugin_specs = { require("config.indent-blankline") end, }, - + { + "luukvbaal/statuscol.nvim", + opts = {}, + config = function() + local builtin = require("statuscol.builtin") + require("statuscol").setup { + relculright = true, + segments = { + { text = { builtin.foldfunc }, click = "v:lua.ScFa" }, + { text = { "%s" }, click = "v:lua.ScSa" }, + { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" }, + }, + } + end, + }, + { + "kevinhwang91/nvim-ufo", + dependencies = "kevinhwang91/promise-async", + event = "VeryLazy", + opts = {}, + init = function() + vim.o.foldcolumn = "1" -- '0' is not bad + vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value + vim.o.foldlevelstart = 99 + vim.o.foldenable = true + end, + config = function() + require("config.nvim_ufo") + end, + }, -- Highlight URLs inside vim { "itchyny/vim-highlighturl", event = "VeryLazy" }, @@ -442,7 +471,7 @@ local plugin_specs = { -- local prologue = "echo" local cmd_str = string.format(":call firenvim#install(0, '%s')", prologue) vim.cmd(cmd_str) - end + end, }, -- Debugger plugin { @@ -517,6 +546,6 @@ require("lazy").setup { title_pos = "center", }, rocks = { - enabled = false + enabled = false, }, } diff --git a/viml_conf/options.vim b/viml_conf/options.vim index f3b9af45..68e0059f 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -1,7 +1,7 @@ scriptencoding utf-8 " change fillchars for folding, vertical split, end of buffer, and message separator -set fillchars=fold:\ ,vert:\│,eob:\ ,msgsep:‾,diff:╱ +set fillchars=fold:\ ,foldsep:\ ,foldopen:,foldclose:,vert:\│,eob:\ ,msgsep:‾,diff:╱ " Split window below/right when creating horizontal/vertical windows set splitbelow splitright From 933b887281eaefec6f8c64c7ea627de8308caddf Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 4 Aug 2024 23:47:08 +0200 Subject: [PATCH 013/247] update config for nvim-ufo --- lua/config/nvim_ufo.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lua/config/nvim_ufo.lua b/lua/config/nvim_ufo.lua index 8d0ffc04..2430932d 100644 --- a/lua/config/nvim_ufo.lua +++ b/lua/config/nvim_ufo.lua @@ -40,9 +40,7 @@ vim.keymap.set("n", "zR", require("ufo").openAllFolds) vim.keymap.set("n", "zM", require("ufo").closeAllFolds) vim.keymap.set("n", "zr", require("ufo").openFoldsExceptKinds) vim.keymap.set("n", "K", function() - local winid = require("ufo").peekFoldedLinesUnderCursor() - if not winid then - -- vim.lsp.buf.hover() - vim.cmd([[ Lspsaga hover_doc ]]) - end -end) + local _ = require("ufo").peekFoldedLinesUnderCursor() +end, { + desc = "Preview folded maps", +}) From e165276763f52bc1f8a30d892651b1725aef7017 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 5 Aug 2024 00:22:29 +0200 Subject: [PATCH 014/247] fix error when there is no cursor word --- lua/config/hlslens.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua index 430bd230..36323470 100644 --- a/lua/config/hlslens.lua +++ b/lua/config/hlslens.lua @@ -35,14 +35,28 @@ keymap.set("n", "N", "", { end, }) +local no_word_under_cursor = function() + local word_under_cursor = vim.fn.expand("") + + local msg = "E348: No string under cursor" + api.nvim_err_writeln(msg) + return word_under_cursor == "" +end + keymap.set("n", "*", "", { callback = function() + if no_word_under_cursor() then + return + end vim.fn.execute("normal! *N") hlslens.start() end, }) keymap.set("n", "#", "", { callback = function() + if no_word_under_cursor() then + return + end vim.fn.execute("normal! #N") hlslens.start() end, From fe9565831929d047f623e68c72173fb2f9624ecc Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 5 Aug 2024 00:24:48 +0200 Subject: [PATCH 015/247] Add colorscheme arctic.nvim --- lua/colorschemes.lua | 3 +++ lua/plugin_specs.lua | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 387b6ec5..f956ad0e 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -56,6 +56,9 @@ M.colorscheme_conf = { vim.g.material_style = "oceanic" vim.cmd('colorscheme material') end, + arctic = function () + vim.cmd("colorscheme arctic") + end } --- Use a random colorscheme from the pre-defined list of colorschemes. diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 551dc855..f040f23a 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -142,6 +142,12 @@ local plugin_specs = { { "catppuccin/nvim", name = "catppuccin", lazy = true }, { "olimorris/onedarkpro.nvim", lazy = true }, { "marko-cerovac/material.nvim", lazy = true }, + { + "rockyzhang24/arctic.nvim", + dependencies = { "rktjmp/lush.nvim" }, + name = "arctic", + branch = "v2", + }, { "nvim-tree/nvim-web-devicons", event = "VeryLazy" }, From 5502d29f408509838afab2b0e6e5ef6b1614f543 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 5 Aug 2024 23:14:24 +0200 Subject: [PATCH 016/247] update config related to folding 1. For python and lua, rely on LSP for folding 2. show fold signs on the right of the number column --- after/ftplugin/lua.vim | 4 ---- after/ftplugin/python.vim | 4 ---- lua/plugin_specs.lua | 2 +- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/after/ftplugin/lua.vim b/after/ftplugin/lua.vim index 910c31da..914dd843 100644 --- a/after/ftplugin/lua.vim +++ b/after/ftplugin/lua.vim @@ -3,7 +3,3 @@ set formatoptions-=o set formatoptions-=r nnoremap :luafile % - -" Use nvim-treesitter for folding -set foldmethod=expr -set foldexpr=nvim_treesitter#foldexpr() diff --git a/after/ftplugin/python.vim b/after/ftplugin/python.vim index a9f625c4..7e8b33ba 100644 --- a/after/ftplugin/python.vim +++ b/after/ftplugin/python.vim @@ -12,7 +12,3 @@ set tabstop=4 " number of visual spaces per TAB set softtabstop=4 " number of spaces in tab when editing set shiftwidth=4 " number of spaces to use for autoindent set expandtab " expand tab to spaces so that tabs are spaces - -" Use nvim-treesitter for folding -set foldmethod=expr -set foldexpr=nvim_treesitter#foldexpr() diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index f040f23a..008c11f6 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -194,9 +194,9 @@ local plugin_specs = { require("statuscol").setup { relculright = true, segments = { - { text = { builtin.foldfunc }, click = "v:lua.ScFa" }, { text = { "%s" }, click = "v:lua.ScSa" }, { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" }, + { text = { builtin.foldfunc, " " }, condition = {true, builtin.not_empty}, click = "v:lua.ScFa" }, }, } end, From 44e9e5a1ce766d31770329257f52f97a27bdb7ae Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 5 Aug 2024 23:23:44 +0200 Subject: [PATCH 017/247] Fix lua_ls diagnostic warnings --- init.lua | 14 ++++++++++---- lua/config/nvim_ufo.lua | 1 - lua/config/statusline.lua | 3 ++- lua/mappings.lua | 4 +++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index ee66d272..9fda2f9a 100644 --- a/init.lua +++ b/init.lua @@ -14,15 +14,21 @@ vim.loader.enable() local version = vim.version -- check if we have the latest stable version of nvim -local expected_ver = "0.10.1" -local expect_ver = version.parse(expected_ver) -local actual_ver = version() +local expected_ver_str = "0.10.1" +local expect_ver = version.parse(expected_ver_str) +local actual_ver = vim.version() + +if expect_ver == nil then + local msg = string.format("Unsupported version string: %s", expected_ver_str) + vim.api.nvim_err_writeln(msg) + return +end local result = version.cmp(expect_ver, actual_ver) if result ~= 0 then local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch) - local msg = string.format("Expect nvim %s, but got %s instead. Use at your own risk!", expected_ver, _ver) + local msg = string.format("Expect nvim %s, but got %s instead. Use at your own risk!", expected_ver_str, _ver) vim.api.nvim_err_writeln(msg) end diff --git a/lua/config/nvim_ufo.lua b/lua/config/nvim_ufo.lua index 2430932d..96d7bc11 100644 --- a/lua/config/nvim_ufo.lua +++ b/lua/config/nvim_ufo.lua @@ -1,6 +1,5 @@ local handler = function(virtText, lnum, endLnum, width, truncate) local newVirtText = {} - local totalLines = vim.api.nvim_buf_line_count(0) local foldedLines = endLnum - lnum local suffix = (" 󰁂 %d"):format(foldedLines) local sufWidth = vim.fn.strdisplaywidth(suffix) diff --git a/lua/config/statusline.lua b/lua/config/statusline.lua index 466edf6c..08ead79a 100644 --- a/lua/config/statusline.lua +++ b/lua/config/statusline.lua @@ -127,6 +127,7 @@ local get_active_lsp = function() end for _, client in ipairs(clients) do + ---@diagnostic disable-next-line: undefined-field local filetypes = client.config.filetypes if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then return client.name @@ -149,7 +150,7 @@ require("lualine").setup { lualine_b = { { "branch", - fmt = function(name, context) + fmt = function(name, _) -- truncate branch name in case the name is too long return string.sub(name, 1, 20) end, diff --git a/lua/mappings.lua b/lua/mappings.lua index 96a07cc7..f2976953 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -1,5 +1,4 @@ local keymap = vim.keymap -local api = vim.api local uv = vim.uv -- Save key strokes (now we do not need to press shift to enter command mode). @@ -215,6 +214,9 @@ keymap.set("n", "cb", function() local cnt = 0 local blink_times = 7 local timer = uv.new_timer() + if timer == nil then + return + end timer:start(0, 100, vim.schedule_wrap(function() vim.cmd [[ From acc3ed7829882a55e2e3ce29163cb9b2b907a5e5 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 5 Aug 2024 23:32:03 +0200 Subject: [PATCH 018/247] show error message only when no word is under cursor --- lua/config/hlslens.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua index 36323470..c682d5c0 100644 --- a/lua/config/hlslens.lua +++ b/lua/config/hlslens.lua @@ -36,11 +36,15 @@ keymap.set("n", "N", "", { }) local no_word_under_cursor = function() - local word_under_cursor = vim.fn.expand("") + local cursor_word = vim.fn.expand("") - local msg = "E348: No string under cursor" - api.nvim_err_writeln(msg) - return word_under_cursor == "" + local result = cursor_word == "" + if result then + local msg = "E348: No string under cursor" + api.nvim_err_writeln(msg) + end + + return result end keymap.set("n", "*", "", { From b728b3978421048e8a0336ea7a09cfcc0507f92f Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 5 Aug 2024 23:34:19 +0200 Subject: [PATCH 019/247] update type hint for functions --- lua/utils.lua | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lua/utils.lua b/lua/utils.lua index fef41782..6b279d62 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -11,9 +11,8 @@ function M.executable(name) end --- check whether a feature exists in Nvim ---- @feat: string ---- the feature name, like `nvim-0.7` or `unix`. ---- return: bool +--- @param feat string the feature name, like `nvim-0.7` or `unix`. +--- @return boolean M.has = function(feat) if fn.has(feat) == 1 then return true @@ -33,8 +32,9 @@ end --- Generate random integers in the range [Low, High], inclusive, --- adapted from https://stackoverflow.com/a/12739441/6064933 ---- @low: the lower value for this range ---- @high: the upper value for this range +--- @param low integer the lower value for this range +--- @param high integer the upper value for this range +--- @return integer function M.rand_int(low, high) -- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933 math.randomseed(os.time()) @@ -43,17 +43,11 @@ function M.rand_int(low, high) end --- Select a random element from a sequence/list. ---- @seq: the sequence to choose an element +--- @param seq any[] the sequence to choose an element function M.rand_element(seq) local idx = M.rand_int(1, #seq) return seq[idx] end -function M.add_pack(name) - local status, error = pcall(vim.cmd, "packadd " .. name) - - return status -end - return M From 794b09809030e19ed45fa4752597fd6df9436cbf Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 5 Aug 2024 23:58:20 +0200 Subject: [PATCH 020/247] Add git blame mapping --- lua/config/fugitive.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/config/fugitive.lua b/lua/config/fugitive.lua index b9c45e2a..9aaab97d 100644 --- a/lua/config/fugitive.lua +++ b/lua/config/fugitive.lua @@ -6,6 +6,7 @@ keymap.set("n", "gc", "Git commit", { desc = "Git commit" }) keymap.set("n", "gd", "Gdiffsplit", { desc = "Git diff" }) keymap.set("n", "gpl", "Git pull", { desc = "Git pull" }) keymap.set("n", "gpu", "15 split|term git push", { desc = "Git push" }) +keymap.set("v", "gb", ":Git blame", { desc = "Git blame line" }) -- convert git to Git in command line mode -vim.fn['utils#Cabbrev']('git', 'Git') +vim.fn["utils#Cabbrev"]("git", "Git") From b3a26e42269846041ddcfb0cf8d8a1d6ae238589 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 6 Aug 2024 00:01:17 +0200 Subject: [PATCH 021/247] update load condtion for nvim-tree --- lua/plugin_specs.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 008c11f6..20bf4eb7 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -527,7 +527,7 @@ local plugin_specs = { -- file explorer { "nvim-tree/nvim-tree.lua", - keys = { "s" }, + event = "VeryLazy", dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() require("config.nvim-tree") From b30cc9ed782a1d93154907e692078725e74ff31d Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 6 Aug 2024 00:04:48 +0200 Subject: [PATCH 022/247] update user dictionary --- spell/en.utf-8.add | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spell/en.utf-8.add b/spell/en.utf-8.add index 9767d50e..42e271e3 100644 --- a/spell/en.utf-8.add +++ b/spell/en.utf-8.add @@ -467,3 +467,6 @@ pylintrc PYTHONPATH Uvicorn qpdf +Elasticsearch +kibana +submodule From 262ad6aa381ee7f6b6c35f87b1616bd173c31d4c Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 6 Aug 2024 00:15:31 +0200 Subject: [PATCH 023/247] Add new colorscheme kanagawa --- lua/colorschemes.lua | 3 +++ lua/plugin_specs.lua | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index f956ad0e..132e3c28 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -58,6 +58,9 @@ M.colorscheme_conf = { end, arctic = function () vim.cmd("colorscheme arctic") + end, + kanagawa = function() + vim.cmd("colorscheme kanagawa-wave") end } diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 20bf4eb7..ed5a1c3d 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -148,7 +148,7 @@ local plugin_specs = { name = "arctic", branch = "v2", }, - + { "rebelot/kanagawa.nvim", lazy = true }, { "nvim-tree/nvim-web-devicons", event = "VeryLazy" }, { From e6f95cedb15eb9cc6f7ded15017fd4e4fb60e8af Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 6 Aug 2024 00:50:47 +0200 Subject: [PATCH 024/247] Update installation doc --- docs/README.md | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/docs/README.md b/docs/README.md index 774d9196..d041655f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -118,16 +118,16 @@ The version of Git on the Linux system may be too old so that plugins may break. Check [here](https://jdhao.github.io/2021/03/27/upgrade_git_on_linux/) on how to install and set up the latest version of Git. For Windows, install [Git for Windows](https://git-scm.com/download/win) and make sure you can run `git` from command line. -### ctags +### universal-ctags In order to use tags related plugins such as [vista.vim](https://github.com/liuchengxu/vista.vim), we need to install a ctags distribution. Universal-ctags is preferred. To install it on Linux, we need to build it from source. See [here](https://askubuntu.com/a/836521/768311) for the details. -To install ctags on macOS, use [Homebrew](https://github.com/universal-ctags/homebrew-universal-ctags): +To install ctags on macOS, use [Homebrew](https://formulae.brew.sh/formula/universal-ctags): ```bash -brew install ctags +brew install universal-ctags ``` To install it Windows, use [chocolatey](https://chocolatey.org/) or [scoop](https://scoop.sh/) @@ -166,35 +166,9 @@ Set their PATH properly and make sure you can run `pylint`, `flake8` and `vint` There are various ways to install Nvim depending on your system. This config is only maintained for [the latest nvim stable release](https://github.com/neovim/neovim/releases/tag/stable). -### Linux +Please check the official doc on how to install Neovim on different systems: https://github.com/neovim/neovim/blob/master/INSTALL.md -You can directly download the binary release from [here](https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz). -You can also use the system package manager to install nvim, -but that is not reliable since the latest version may not be available. - -### Windows - -You may download from [nvim release](https://github.com/neovim/neovim/releases/download/stable/nvim-win64.zip) from GitHub and manually extract it. - -Another way to install Nvim on Windows is via chocolatey or scoop: - -``` -choco install neovim - -# via scoop -# scoop bucket add versions -# scoop install neovim -``` - -### macOS - -It is recommended to install neovim via [Homebrew](https://brew.sh/) on macOS. Simply run the following command: - -```bash -brew install neovim -``` - -After installing Nvim, we need to set the path to nvim correctly. +After installing Nvim, we need to set the PATH to nvim correctly. **Make sure that you can run `nvim` from the command line after all these setups**. ## Setting up Nvim From 4c697d89f30ae619d82749a6f0f89f2a4a6e51d7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 6 Aug 2024 17:00:18 +0200 Subject: [PATCH 025/247] change name of lualine config --- lua/config/lualine.lua | 228 +++++++++++++++++++++++++++++++++++++++++ lua/plugin_specs.lua | 2 +- 2 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 lua/config/lualine.lua diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua new file mode 100644 index 00000000..08ead79a --- /dev/null +++ b/lua/config/lualine.lua @@ -0,0 +1,228 @@ +local fn = vim.fn + +local function spell() + if vim.o.spell then + return string.format("[SPELL]") + end + + return "" +end + +--- show indicator for Chinese IME +local function ime_state() + if vim.g.is_mac then + -- ref: https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11 + local layout = fn.libcall(vim.g.XkbSwitchLib, "Xkb_Switch_getXkbLayout", "") + + -- We can use `xkbswitch -g` on the command line to get current mode. + -- mode for macOS builtin pinyin IME: com.apple.inputmethod.SCIM.ITABC + -- mode for Rime: im.rime.inputmethod.Squirrel.Rime + local res = fn.match(layout, [[\v(Squirrel\.Rime|SCIM.ITABC)]]) + if res ~= -1 then + return "[CN]" + end + end + + return "" +end + +local function trailing_space() + if not vim.o.modifiable then + return "" + end + + local line_num = nil + + for i = 1, fn.line("$") do + local linetext = fn.getline(i) + -- To prevent invalid escape error, we wrap the regex string with `[[]]`. + local idx = fn.match(linetext, [[\v\s+$]]) + + if idx ~= -1 then + line_num = i + break + end + end + + local msg = "" + if line_num ~= nil then + msg = string.format("[%d]trailing", line_num) + end + + return msg +end + +local function mixed_indent() + if not vim.o.modifiable then + return "" + end + + local space_pat = [[\v^ +]] + local tab_pat = [[\v^\t+]] + local space_indent = fn.search(space_pat, "nwc") + local tab_indent = fn.search(tab_pat, "nwc") + local mixed = (space_indent > 0 and tab_indent > 0) + local mixed_same_line + if not mixed then + mixed_same_line = fn.search([[\v^(\t+ | +\t)]], "nwc") + mixed = mixed_same_line > 0 + end + if not mixed then + return "" + end + if mixed_same_line ~= nil and mixed_same_line > 0 then + return "MI:" .. mixed_same_line + end + local space_indent_cnt = fn.searchcount({ pattern = space_pat, max_count = 1e3 }).total + local tab_indent_cnt = fn.searchcount({ pattern = tab_pat, max_count = 1e3 }).total + if space_indent_cnt > tab_indent_cnt then + return "MI:" .. tab_indent + else + return "MI:" .. space_indent + end +end + +local diff = function() + local git_status = vim.b.gitsigns_status_dict + if git_status == nil then + return + end + + local modify_num = git_status.changed + local remove_num = git_status.removed + local add_num = git_status.added + + local info = { added = add_num, modified = modify_num, removed = remove_num } + -- vim.print(info) + return info +end + +local virtual_env = function() + -- only show virtual env for Python + if vim.bo.filetype ~= "python" then + return "" + end + + local conda_env = os.getenv("CONDA_DEFAULT_ENV") + local venv_path = os.getenv("VIRTUAL_ENV") + + if venv_path == nil then + if conda_env == nil then + return "" + else + return string.format(" %s (conda)", conda_env) + end + else + local venv_name = vim.fn.fnamemodify(venv_path, ":t") + return string.format(" %s (venv)", venv_name) + end +end + +local get_active_lsp = function() + local msg = "No Active Lsp" + local buf_ft = vim.api.nvim_get_option_value("filetype", {}) + local clients = vim.lsp.get_clients { bufnr = 0 } + if next(clients) == nil then + return msg + end + + for _, client in ipairs(clients) do + ---@diagnostic disable-next-line: undefined-field + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + return client.name + end + end + return msg +end + +require("lualine").setup { + options = { + icons_enabled = true, + theme = "auto", + section_separators = "", + component_separators = "", + disabled_filetypes = {}, + always_divide_middle = true, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { + { + "branch", + fmt = function(name, _) + -- truncate branch name in case the name is too long + return string.sub(name, 1, 20) + end, + }, + { + virtual_env, + color = { fg = "black", bg = "#F1CA81" }, + }, + }, + lualine_c = { + { + "filename", + symbols = { + readonly = "[🔒]", + }, + }, + { + "diff", + source = diff, + }, + { + ime_state, + color = { fg = "black", bg = "#f46868" }, + }, + { + spell, + color = { fg = "black", bg = "#a7c080" }, + }, + }, + lualine_x = { + { + get_active_lsp, + icon = " LSP:", + }, + { + "diagnostics", + sources = { "nvim_diagnostic" }, + symbols = { error = "🆇 ", warn = "⚠️ ", info = "ℹ️ ", hint = " " }, + }, + }, + lualine_y = { + "encoding", + { + "fileformat", + symbols = { + unix = "unix", + dos = "win", + mac = "mac", + }, + }, + "filetype", + }, + lualine_z = { + { + trailing_space, + color = "WarningMsg", + }, + { + mixed_indent, + color = "WarningMsg", + }, + "progress" + }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = { "quickfix", "fugitive", "nvim-tree" }, +} diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index ed5a1c3d..c57fd25f 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -156,7 +156,7 @@ local plugin_specs = { event = "VeryLazy", cond = firenvim_not_active, config = function() - require("config.statusline") + require("config.lualine") end, }, From 8af8ebd72a3632c96968a686e2d2fdeaa61de092 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 6 Aug 2024 17:25:33 +0200 Subject: [PATCH 026/247] remove statusline.lua --- lua/config/statusline.lua | 228 -------------------------------------- 1 file changed, 228 deletions(-) delete mode 100644 lua/config/statusline.lua diff --git a/lua/config/statusline.lua b/lua/config/statusline.lua deleted file mode 100644 index 08ead79a..00000000 --- a/lua/config/statusline.lua +++ /dev/null @@ -1,228 +0,0 @@ -local fn = vim.fn - -local function spell() - if vim.o.spell then - return string.format("[SPELL]") - end - - return "" -end - ---- show indicator for Chinese IME -local function ime_state() - if vim.g.is_mac then - -- ref: https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11 - local layout = fn.libcall(vim.g.XkbSwitchLib, "Xkb_Switch_getXkbLayout", "") - - -- We can use `xkbswitch -g` on the command line to get current mode. - -- mode for macOS builtin pinyin IME: com.apple.inputmethod.SCIM.ITABC - -- mode for Rime: im.rime.inputmethod.Squirrel.Rime - local res = fn.match(layout, [[\v(Squirrel\.Rime|SCIM.ITABC)]]) - if res ~= -1 then - return "[CN]" - end - end - - return "" -end - -local function trailing_space() - if not vim.o.modifiable then - return "" - end - - local line_num = nil - - for i = 1, fn.line("$") do - local linetext = fn.getline(i) - -- To prevent invalid escape error, we wrap the regex string with `[[]]`. - local idx = fn.match(linetext, [[\v\s+$]]) - - if idx ~= -1 then - line_num = i - break - end - end - - local msg = "" - if line_num ~= nil then - msg = string.format("[%d]trailing", line_num) - end - - return msg -end - -local function mixed_indent() - if not vim.o.modifiable then - return "" - end - - local space_pat = [[\v^ +]] - local tab_pat = [[\v^\t+]] - local space_indent = fn.search(space_pat, "nwc") - local tab_indent = fn.search(tab_pat, "nwc") - local mixed = (space_indent > 0 and tab_indent > 0) - local mixed_same_line - if not mixed then - mixed_same_line = fn.search([[\v^(\t+ | +\t)]], "nwc") - mixed = mixed_same_line > 0 - end - if not mixed then - return "" - end - if mixed_same_line ~= nil and mixed_same_line > 0 then - return "MI:" .. mixed_same_line - end - local space_indent_cnt = fn.searchcount({ pattern = space_pat, max_count = 1e3 }).total - local tab_indent_cnt = fn.searchcount({ pattern = tab_pat, max_count = 1e3 }).total - if space_indent_cnt > tab_indent_cnt then - return "MI:" .. tab_indent - else - return "MI:" .. space_indent - end -end - -local diff = function() - local git_status = vim.b.gitsigns_status_dict - if git_status == nil then - return - end - - local modify_num = git_status.changed - local remove_num = git_status.removed - local add_num = git_status.added - - local info = { added = add_num, modified = modify_num, removed = remove_num } - -- vim.print(info) - return info -end - -local virtual_env = function() - -- only show virtual env for Python - if vim.bo.filetype ~= "python" then - return "" - end - - local conda_env = os.getenv("CONDA_DEFAULT_ENV") - local venv_path = os.getenv("VIRTUAL_ENV") - - if venv_path == nil then - if conda_env == nil then - return "" - else - return string.format(" %s (conda)", conda_env) - end - else - local venv_name = vim.fn.fnamemodify(venv_path, ":t") - return string.format(" %s (venv)", venv_name) - end -end - -local get_active_lsp = function() - local msg = "No Active Lsp" - local buf_ft = vim.api.nvim_get_option_value("filetype", {}) - local clients = vim.lsp.get_clients { bufnr = 0 } - if next(clients) == nil then - return msg - end - - for _, client in ipairs(clients) do - ---@diagnostic disable-next-line: undefined-field - local filetypes = client.config.filetypes - if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then - return client.name - end - end - return msg -end - -require("lualine").setup { - options = { - icons_enabled = true, - theme = "auto", - section_separators = "", - component_separators = "", - disabled_filetypes = {}, - always_divide_middle = true, - }, - sections = { - lualine_a = { "mode" }, - lualine_b = { - { - "branch", - fmt = function(name, _) - -- truncate branch name in case the name is too long - return string.sub(name, 1, 20) - end, - }, - { - virtual_env, - color = { fg = "black", bg = "#F1CA81" }, - }, - }, - lualine_c = { - { - "filename", - symbols = { - readonly = "[🔒]", - }, - }, - { - "diff", - source = diff, - }, - { - ime_state, - color = { fg = "black", bg = "#f46868" }, - }, - { - spell, - color = { fg = "black", bg = "#a7c080" }, - }, - }, - lualine_x = { - { - get_active_lsp, - icon = " LSP:", - }, - { - "diagnostics", - sources = { "nvim_diagnostic" }, - symbols = { error = "🆇 ", warn = "⚠️ ", info = "ℹ️ ", hint = " " }, - }, - }, - lualine_y = { - "encoding", - { - "fileformat", - symbols = { - unix = "unix", - dos = "win", - mac = "mac", - }, - }, - "filetype", - }, - lualine_z = { - { - trailing_space, - color = "WarningMsg", - }, - { - mixed_indent, - color = "WarningMsg", - }, - "progress" - }, - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { "filename" }, - lualine_x = { "location" }, - lualine_y = {}, - lualine_z = {}, - }, - tabline = {}, - extensions = { "quickfix", "fugitive", "nvim-tree" }, -} From fd6df981cd0b888d3a51666af2bb1fc5b8db8dd7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 6 Aug 2024 17:58:05 +0200 Subject: [PATCH 027/247] Update nvim-ufo settings --- lua/config/lsp.lua | 5 +++++ lua/config/nvim_ufo.lua | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index f43aa583..da7d93c6 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -110,6 +110,11 @@ local custom_attach = function(client, bufnr) end local capabilities = require('cmp_nvim_lsp').default_capabilities() +-- required by nvim-ufo +capabilities.textDocument.foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true +} local lspconfig = require("lspconfig") diff --git a/lua/config/nvim_ufo.lua b/lua/config/nvim_ufo.lua index 96d7bc11..b8704ee7 100644 --- a/lua/config/nvim_ufo.lua +++ b/lua/config/nvim_ufo.lua @@ -30,10 +30,9 @@ local handler = function(virtText, lnum, endLnum, width, truncate) return newVirtText end -local opts = {} -opts["fold_virt_text_handler"] = handler - -require("ufo").setup(opts) +require("ufo").setup { + fold_virt_text_handler = handler, +} vim.keymap.set("n", "zR", require("ufo").openAllFolds) vim.keymap.set("n", "zM", require("ufo").closeAllFolds) From f1062a3d8f0002e8fd3ddf45580397e013c0aa8b Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 6 Aug 2024 18:00:41 +0200 Subject: [PATCH 028/247] filter fold level sign for statuscol.nvim Only show fold signs for fold level below a certain level to avoid clutter the left side columns with a lot of folding signs --- lua/config/nvim-statuscol.lua | 23 +++++++++++++++++++++++ lua/plugin_specs.lua | 10 +--------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 lua/config/nvim-statuscol.lua diff --git a/lua/config/nvim-statuscol.lua b/lua/config/nvim-statuscol.lua new file mode 100644 index 00000000..a0998de6 --- /dev/null +++ b/lua/config/nvim-statuscol.lua @@ -0,0 +1,23 @@ +local builtin = require("statuscol.builtin") +local ffi = require("statuscol.ffidef") +local C = ffi.C + +-- only show fold level up to this level +local fold_level_limit = 2 +local function foldfunc(args) + local foldinfo = C.fold_info(args.wp, args.lnum) + if foldinfo.level > fold_level_limit then + return " " + end + + return builtin.foldfunc(args) +end + +require("statuscol").setup { + relculright = false, + segments = { + { text = { "%s" }, click = "v:lua.ScSa" }, + { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" }, + { text = { foldfunc, " " }, condition = { true, builtin.not_empty }, click = "v:lua.ScFa" }, + }, +} diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index c57fd25f..ee87c053 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -190,15 +190,7 @@ local plugin_specs = { "luukvbaal/statuscol.nvim", opts = {}, config = function() - local builtin = require("statuscol.builtin") - require("statuscol").setup { - relculright = true, - segments = { - { text = { "%s" }, click = "v:lua.ScSa" }, - { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" }, - { text = { builtin.foldfunc, " " }, condition = {true, builtin.not_empty}, click = "v:lua.ScFa" }, - }, - } + require("config.nvim-statuscol") end, }, { From cfc0089bb5f923084f5e8df4933cf7033364aa4d Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 6 Aug 2024 18:47:50 +0200 Subject: [PATCH 029/247] add plugin lazydev.nvim --- lua/plugin_specs.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index ee87c053..96200245 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -534,6 +534,11 @@ local plugin_specs = { require("config.fidget-nvim") end, }, + { + "folke/lazydev.nvim", + ft = "lua", -- only load on lua files + opts = {}, + }, } require("lazy").setup { From 85232b82a856481c2a8ffeaa4968a0092e274089 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 9 Aug 2024 22:03:02 +0200 Subject: [PATCH 030/247] Update mapping of plugin open-browser.vim --- viml_conf/plugins.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim index da3252ec..f7c202ba 100644 --- a/viml_conf/plugins.vim +++ b/viml_conf/plugins.vim @@ -119,8 +119,9 @@ if g:is_win || g:is_mac let g:netrw_nogx = 1 " Use another mapping for the open URL method - nmap ob (openbrowser-smart-search) - xmap ob (openbrowser-smart-search) + nmap ob (openbrowser-smart-search) + xmap ob (openbrowser-smart-search) + nmap ob echoerr "Use ob instead!" endif """"""""""""""""""""""""""" vista settings """""""""""""""""""""""""""""""""" From 9ff76931e366634f0e73d0ef3ca600bb79c5272a Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 9 Aug 2024 22:18:39 +0200 Subject: [PATCH 031/247] update git related mappings --- lua/config/fugitive.lua | 29 ++++++++++++++++++++++------- lua/config/git-linker.lua | 6 +++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lua/config/fugitive.lua b/lua/config/fugitive.lua index 9aaab97d..8d37cf3f 100644 --- a/lua/config/fugitive.lua +++ b/lua/config/fugitive.lua @@ -1,12 +1,27 @@ local keymap = vim.keymap -keymap.set("n", "gs", "Git", { desc = "Git status" }) -keymap.set("n", "gw", "Gwrite", { desc = "Git add" }) -keymap.set("n", "gc", "Git commit", { desc = "Git commit" }) -keymap.set("n", "gd", "Gdiffsplit", { desc = "Git diff" }) -keymap.set("n", "gpl", "Git pull", { desc = "Git pull" }) -keymap.set("n", "gpu", "15 split|term git push", { desc = "Git push" }) -keymap.set("v", "gb", ":Git blame", { desc = "Git blame line" }) +keymap.set("n", "gs", "Git", { desc = "Git: show status" }) +keymap.set("n", "gw", "Gwrite", { desc = "Git: add file" }) +keymap.set("n", "gc", "Git commit", { desc = "Git: commit changes" }) +keymap.set("n", "gpl", "Git pull", { desc = "Git: pull changes" }) +keymap.set("n", "gpu", "15 split|term git push", { desc = "Git: push changes" }) +keymap.set("v", "gb", ":Git blame", { desc = "Git: blame selected line" }) -- convert git to Git in command line mode vim.fn["utils#Cabbrev"]("git", "Git") + +keymap.set("n", "gnb", function() + vim.ui.input({ prompt = "Enter the new branch nmae" }, function(user_input) + if user_input == nil or user_input == "" then + return + end + + local cmd_str = string.format("G checkout -b %s", user_input) + vim.cmd(cmd_str) + end) +end, { + desc = "Git: create new branch", +}) + +keymap.set("n", "gf", "Git fetch", { desc = "Git: prune branches" }) +keymap.set("n", "gbd", ":Git branch -D ", { desc = "Git: delete branch" }) diff --git a/lua/config/git-linker.lua b/lua/config/git-linker.lua index 39f5ba21..e3fb3e67 100644 --- a/lua/config/git-linker.lua +++ b/lua/config/git-linker.lua @@ -24,14 +24,14 @@ keymap.set({ "n", "v" }, "gl", function() gitlinker.get_buf_range_url(mode) end, { silent = true, - desc = "get git permlink", + desc = "Git: get permlink", }) -keymap.set("n", "gb", function() +keymap.set("n", "gbr", function() gitlinker.get_repo_url({ action_callback = gitlinker.actions.open_in_browser }) end, { silent = true, - desc = "browse repo in browser", + desc = "Git: browse repo in browser", }) From a602d9881982ec209218299bad200c98f53b2259 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 9 Aug 2024 22:22:01 +0200 Subject: [PATCH 032/247] fix git mapping issue ` `mapping must end with `` --- lua/config/fugitive.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/config/fugitive.lua b/lua/config/fugitive.lua index 8d37cf3f..b92415a9 100644 --- a/lua/config/fugitive.lua +++ b/lua/config/fugitive.lua @@ -23,5 +23,5 @@ end, { desc = "Git: create new branch", }) -keymap.set("n", "gf", "Git fetch", { desc = "Git: prune branches" }) +keymap.set("n", "gf", ":Git fetch ", { desc = "Git: prune branches" }) keymap.set("n", "gbd", ":Git branch -D ", { desc = "Git: delete branch" }) From 659f410b9ea400277a444813f10ce7b747a025d1 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 15 Aug 2024 23:37:35 +0200 Subject: [PATCH 033/247] move version check into function --- init.lua | 22 +++------------------- lua/utils.lua | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/init.lua b/init.lua index 9fda2f9a..5199cd72 100644 --- a/init.lua +++ b/init.lua @@ -11,26 +11,10 @@ -- StackOverflow: https://stackoverflow.com/users/6064933/jdhao vim.loader.enable() -local version = vim.version +local utils = require("utils") --- check if we have the latest stable version of nvim -local expected_ver_str = "0.10.1" -local expect_ver = version.parse(expected_ver_str) -local actual_ver = vim.version() - -if expect_ver == nil then - local msg = string.format("Unsupported version string: %s", expected_ver_str) - vim.api.nvim_err_writeln(msg) - return -end - -local result = version.cmp(expect_ver, actual_ver) - -if result ~= 0 then - local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch) - local msg = string.format("Expect nvim %s, but got %s instead. Use at your own risk!", expected_ver_str, _ver) - vim.api.nvim_err_writeln(msg) -end +local expected_version = "0.10.1" +utils.is_compatible_version(expected_version) local core_conf_files = { "globals.lua", -- some global settings diff --git a/lua/utils.lua b/lua/utils.lua index 6b279d62..86a97d08 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -1,4 +1,5 @@ local fn = vim.fn +local version = vim.version local M = {} @@ -50,4 +51,32 @@ function M.rand_element(seq) return seq[idx] end +--- check if the current nvim version is compatible with the allowed version +--- @param expected_version string +--- @return boolean +function M.is_compatible_version(expected_version) + -- check if we have the latest stable version of nvim + local expect_ver = version.parse(expected_version) + local actual_ver = vim.version() + + if expect_ver == nil then + local msg = string.format("Unsupported version string: %s", expected_version) + vim.api.nvim_err_writeln(msg) + return false + end + + local result = version.cmp(expect_ver, actual_ver) + if result ~= 0 then + local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch) + local msg = string.format( + "Expect nvim version %s, but your current nvim version is %s. Use at your own risk!", + expected_version, + _ver + ) + vim.api.nvim_err_writeln(msg) + end + + return true +end + return M From d90273df8eacdb33557258118df89806f7bbc295 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 15 Aug 2024 23:43:41 +0200 Subject: [PATCH 034/247] remove lua_ls conf in favor of lazydev.nvim The removed settings are already set by lazydev.nvim. --- lua/config/lsp.lua | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index da7d93c6..2b385a18 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -230,22 +230,6 @@ if utils.executable("lua-language-server") then -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) version = "LuaJIT", }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files, - -- see also https://luals.github.io/wiki/settings/#workspacelibrary - library = { - vim.env.VIMRUNTIME, - fn.stdpath("config"), - -- make lua_ls aware of functions under vim.uv - "${3rd}/luv/library" - }, - maxPreload = 2000, - preloadFileSize = 50000, - }, }, }, capabilities = capabilities, From 6e60475f3f956ee4b7a2a2deea47f44d9676ed9a Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 16 Aug 2024 00:02:24 +0200 Subject: [PATCH 035/247] Use gx.nvim for browsing in Browser --- lua/plugin_specs.lua | 11 +++++++++-- viml_conf/plugins.vim | 11 ----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 96200245..8230e063 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -223,7 +223,12 @@ local plugin_specs = { -- For Windows and Mac, we can open an URL in the browser. For Linux, it may -- not be possible since we maybe in a server which disables GUI. { - "tyru/open-browser.vim", + "chrishrb/gx.nvim", + keys = { { "gx", "Browse", mode = { "n", "x" } } }, + cmd = { "Browse" }, + init = function() + vim.g.netrw_nogx = 1 -- disable netrw gx + end, enabled = function() if vim.g.is_win or vim.g.is_mac then return true @@ -231,7 +236,9 @@ local plugin_specs = { return false end end, - event = "VeryLazy", + dependencies = { "nvim-lua/plenary.nvim" }, + config = true, -- default settings + submodules = false, -- not needed, submodules are required only for tests }, -- Only install these plugins if ctags are installed on the system diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim index f7c202ba..9b223a6d 100644 --- a/viml_conf/plugins.vim +++ b/viml_conf/plugins.vim @@ -113,17 +113,6 @@ let g:Lf_PreviewResult = { \ 'Gtags': 0 \} -""""""""""""""""""""""""""""open-browser.vim settings""""""""""""""""""" -if g:is_win || g:is_mac - " Disable netrw's gx mapping. - let g:netrw_nogx = 1 - - " Use another mapping for the open URL method - nmap ob (openbrowser-smart-search) - xmap ob (openbrowser-smart-search) - nmap ob echoerr "Use ob instead!" -endif - """"""""""""""""""""""""""" vista settings """""""""""""""""""""""""""""""""" let g:vista#renderer#icons = { \ 'member': '', From eff98d036d93034cc9809ecb942c084ff06818f9 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 17 Aug 2024 15:10:09 +0200 Subject: [PATCH 036/247] update README --- README.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 176e43fa..76f3de5c 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ and how to set up on different platforms (Linux, macOS, and Windows). + Tags navigation via [vista](https://github.com/liuchengxu/vista.vim). + Code formatting via [Neoformat](https://github.com/sbdchd/neoformat). + Undo management via [vim-mundo](https://github.com/simnalamburt/vim-mundo) ++ Code folding with [nvim-ufo](https://github.com/kevinhwang91/nvim-ufo) and [statuscol.nvim](https://github.com/luukvbaal/statuscol.nvim) + ...... # UI Demo @@ -140,6 +141,12 @@ Go to a string starting with `se`

+## code folding with nvim-ufo and statuscol.nvim + +

+ +

+ # Shortcuts Some of the shortcuts I use frequently are listed here. In the following shortcuts, `` represents ASCII character `,`. @@ -165,12 +172,14 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu | `t` | Normal | Linux/macOS/Win | Toggle tag window (show project tags in the right window) | | `gs` | Normal | Linux/macOS/Win | Show Git status result | | `gw` | Normal | Linux/macOS/Win | Run Git add for current file | -| `gd` | Normal | Linux/macOS/Win | Run git diff for current file | | `gc` | Normal | Linux/macOS/Win | Run git commit | | `gpl` | Normal | Linux/macOS/Win | Run git pull | | `gpu` | Normal | Linux/macOS/Win | Run git push | +| `gbd` | Normal | Linux/macOS/Win | Delete a branch | +| `gbn` | Normal | Linux/macOS/Win | Create a new branch | | `gl` | Normal/Visual | Linux/macOS/Win | Get perm link for current/visually-select lines | -| `gb` | Normal | macOS | Browse current git repo in browser | +| `gbr` | Normal | macOS | Browse current git repo in browser | +| `gb` | Visual | macOS | Blame current line | | `` | Normal | Linux/macOS/Win | Compile&run current source file (for C++, LaTeX, Lua, Python) | | `` | Normal | Linux/macOS/Win | Toggle spell checking | | `` | Normal | Linux/macOS/Win | Toggle paste mode | @@ -191,11 +200,12 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu In addition to commands provided by various plugins, I have also created some custom commands for personal use. -| command | description | example | -|------------|-------------------------------------------------------------------------|--------------------------------| -| `Redir` | capture command output to a tabpage for easier inspection. | `Redir hi` | -| `Edit` | edit multiple files at the same time, supports globing | `Edit *.vim` | -| `Datetime` | print current date and time or convert Unix time stamp to date and time | `Datetime 12345` or `Datetime` | +| command | description | example | +|--------------|-------------------------------------------------------------------------|--------------------------------| +| `Redir` | capture command output to a tabpage for easier inspection. | `Redir hi` | +| `Edit` | edit multiple files at the same time, supports globing | `Edit *.vim` | +| `Datetime` | print current date and time or convert Unix time stamp to date and time | `Datetime 12345` or `Datetime` | +| `JSONFormat` | format a JSON file | `JSONFormat` | # Contributing From 256c37a946aeb00382c17778a917c7af2805d733 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 17 Aug 2024 15:15:30 +0200 Subject: [PATCH 037/247] update vim-fugitive mapping --- lua/config/fugitive.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/config/fugitive.lua b/lua/config/fugitive.lua index b92415a9..306d71ba 100644 --- a/lua/config/fugitive.lua +++ b/lua/config/fugitive.lua @@ -10,8 +10,8 @@ keymap.set("v", "gb", ":Git blame", { desc = "Git: blame selected li -- convert git to Git in command line mode vim.fn["utils#Cabbrev"]("git", "Git") -keymap.set("n", "gnb", function() - vim.ui.input({ prompt = "Enter the new branch nmae" }, function(user_input) +keymap.set("n", "gbn", function() + vim.ui.input({ prompt = "Enter a new branch name" }, function(user_input) if user_input == nil or user_input == "" then return end From f9780c2dff238f83863a9bd9030484cb85b9d577 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 17 Aug 2024 17:28:09 +0200 Subject: [PATCH 038/247] update config for bufferline.nvim Do not show buffer number and use a mapping to pick buffer instead. --- lua/config/bufferline.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/config/bufferline.lua b/lua/config/bufferline.lua index 6fa27cee..747fe185 100644 --- a/lua/config/bufferline.lua +++ b/lua/config/bufferline.lua @@ -1,6 +1,6 @@ require("bufferline").setup { options = { - numbers = "buffer_id", + numbers = "none", close_command = "bdelete! %d", right_mouse_command = nil, left_mouse_command = "buffer %d", @@ -44,3 +44,7 @@ require("bufferline").setup { sort_by = "id", }, } + +vim.keymap.set("n", "bp", "BufferLinePick", { + desc = "pick a buffer", +}) From c3d8dc3e1d23f74f02f7972d9d40bfe3dddd394f Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 17 Aug 2024 17:32:24 +0200 Subject: [PATCH 039/247] Add mapping to delete other buffers --- lua/mappings.lua | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/lua/mappings.lua b/lua/mappings.lua index f2976953..7b4980ea 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -45,7 +45,21 @@ keymap.set("n", [[\x]], "windo lclose cclose ", { -- Delete a buffer, without closing the window, see https://stackoverflow.com/q/4465095/6064933 keymap.set("n", [[\d]], "bprevious bdelete #", { silent = true, - desc = "delete buffer", + desc = "delete current buffer", +}) + +keymap.set("n", [[\D]], function() + local buf_ids = vim.api.nvim_list_bufs() + local cur_buf = vim.api.nvim_win_get_buf(0) + + for _, buf_id in pairs(buf_ids) do + -- do not Delete unlisted buffers, which may lead to unexpected errors + if vim.api.nvim_get_option_value("buflisted", { buf = buf_id }) and buf_id ~= cur_buf then + vim.api.nvim_buf_delete(buf_id, { force = true }) + end + end +end, { + desc = "delete other buffers", }) -- Insert a blank line below or above current line (do not move the cursor), @@ -218,18 +232,20 @@ keymap.set("n", "cb", function() return end - timer:start(0, 100, vim.schedule_wrap(function() - vim.cmd [[ + timer:start( + 0, + 100, + vim.schedule_wrap(function() + vim.cmd([[ set cursorcolumn! set cursorline! - ]] + ]]) - if cnt == blink_times then - timer:close() - end + if cnt == blink_times then + timer:close() + end - cnt = cnt + 1 - end) + cnt = cnt + 1 + end) ) -end, - { desc = "show cursor" }) +end, { desc = "show cursor" }) From 95d3b2f2d86c0f452f9d615eb1c7113eb644c48e Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 19 Aug 2024 22:36:26 +0200 Subject: [PATCH 040/247] remove setting for JSON file --- after/ftplugin/json.vim | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 after/ftplugin/json.vim diff --git a/after/ftplugin/json.vim b/after/ftplugin/json.vim deleted file mode 100644 index 90db3ec7..00000000 --- a/after/ftplugin/json.vim +++ /dev/null @@ -1,6 +0,0 @@ -" let the initial folding state be that all folds are closed. -set foldlevel=0 - -" Use nvim-treesitter for folding -set foldmethod=expr -set foldexpr=nvim_treesitter#foldexpr() From 3904cd4ccf801674249569dd83ba52d3d42a4690 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 19 Aug 2024 23:33:29 +0200 Subject: [PATCH 041/247] Update config for handling large files --- viml_conf/autocommands.vim | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/viml_conf/autocommands.vim b/viml_conf/autocommands.vim index 0fad8423..3b4ec103 100644 --- a/viml_conf/autocommands.vim +++ b/viml_conf/autocommands.vim @@ -101,16 +101,14 @@ augroup END " ref: https://vi.stackexchange.com/a/169/15292 function! s:handle_large_file() abort - let g:large_file = 10485760 " 10MB + let g:file_size_limit = 524288 " 0.5MB let f = expand("") - if getfsize(f) > g:large_file || getfsize(f) == -2 - set eventignore+=all + if getfsize(f) > g:file_size_limit || getfsize(f) == -2 + setlocal eventignore=all " turning off relative number helps a lot - set norelativenumber - setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1 - else - set eventignore-=all relativenumber + setlocal norelativenumber + setlocal noswapfile bufhidden=unload undolevels=-1 endif endfunction From d150f39afc7031ff201bd35e0c02c71f8848fd4e Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 19 Aug 2024 23:37:31 +0200 Subject: [PATCH 042/247] Add new plugins --- lua/plugin_specs.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 8230e063..7e1eee0f 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -126,6 +126,15 @@ local plugin_specs = { "nvim-telescope/telescope-symbols.nvim", }, }, + { + "ibhagwan/fzf-lua", + -- optional for icon support + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + -- calling `setup` is optional for customization + require("fzf-lua").setup {} + end, + }, { "MeanderingProgrammer/markdown.nvim", main = "render-markdown", @@ -546,6 +555,26 @@ local plugin_specs = { ft = "lua", -- only load on lua files opts = {}, }, + { + "CopilotC-Nvim/CopilotChat.nvim", + branch = "canary", + dependencies = { + { "zbirenbaum/copilot.lua" }, -- or github/copilot.vim + { "nvim-lua/plenary.nvim" }, -- for curl, log wrapper + }, + opts = { + debug = true, -- Enable debugging + -- See Configuration section for rest + }, + -- See Commands section for default commands if you want to lazy load on them + }, + { + "zbirenbaum/copilot.lua", + cmd = "Copilot", + config = function() + require("copilot").setup {} + end, + }, } require("lazy").setup { From a3c8b3d5b59526f247bffa56ad9fba723d61feaf Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 20 Aug 2024 01:01:04 +0200 Subject: [PATCH 043/247] Update configuration for nvim-cmp 1. restrict max width of the completion menu. Here I am using lspkind.nvim to achieve this. There are other native ways to do this, see also https://github.com/hrsh7th/nvim-cmp/discussions/609 and https://github.com/hrsh7th/nvim-cmp/issues/980 2. remove cmp-emoji as it is rarely used and interfere when I write Python 3. lower the transparency for popup menu --- lua/config/nvim-cmp.lua | 5 +++-- lua/plugin_specs.lua | 1 - viml_conf/options.vim | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index a402f1c7..100c77f0 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -35,7 +35,6 @@ cmp.setup { { name = "ultisnips" }, -- For ultisnips user. { name = "path" }, -- for path completion { name = "buffer", keyword_length = 2 }, -- for buffer word completion - { name = "emoji", insert = true }, -- emoji completion }, completion = { keyword_length = 1, @@ -50,12 +49,14 @@ cmp.setup { menu = { nvim_lsp = "[LSP]", ultisnips = "[US]", - nvim_lua = "[Lua]", path = "[Path]", buffer = "[Buffer]", emoji = "[Emoji]", omni = "[Omni]", }, + show_labelDetails = true, + maxwidth = 40, + ellipsis_char = "...", }, }, } diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 7e1eee0f..3e9127d5 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -32,7 +32,6 @@ local plugin_specs = { "hrsh7th/cmp-path", "hrsh7th/cmp-buffer", "hrsh7th/cmp-omni", - "hrsh7th/cmp-emoji", "quangnguyen30192/cmp-nvim-ultisnips", }, config = function() diff --git a/viml_conf/options.vim b/viml_conf/options.vim index 68e0059f..ca0d66ad 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -121,7 +121,7 @@ set completeopt+=menuone " Show menu even if there is only one item set completeopt-=preview " Disable the preview window set pumheight=10 " Maximum number of items to show in popup menu -set pumblend=10 " pseudo transparency for completion menu +set pumblend=5 " pseudo transparency for completion menu set winblend=0 " pseudo transparency for floating window From 21522bd1948f648659061a46002a2b1fc4b0f392 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 25 Aug 2024 23:33:34 +0200 Subject: [PATCH 044/247] update config for yanky --- lua/config/yanky.lua | 20 ++++++++++++-------- lua/plugin_specs.lua | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lua/config/yanky.lua b/lua/config/yanky.lua index 0f8eceba..2c7b134e 100644 --- a/lua/config/yanky.lua +++ b/lua/config/yanky.lua @@ -1,13 +1,17 @@ -require("yanky").setup({ - ring = { - history_length = 50, - storage = "memory", - }, +require("yanky").setup { preserve_cursor_position = { enabled = false, }, -}) + highlight = { + on_put = true, + on_yank = false, + timer = 300, + }, +} + +vim.keymap.set({ "n", "x" }, "p", "(YankyPutAfter)") +vim.keymap.set({ "n", "x" }, "P", "(YankyPutBefore)") -- cycle through the yank history, only work after paste -vim.keymap.set("n", "[y", "(YankyCycleForward)") -vim.keymap.set("n", "]y", "(YankyCycleBackward)") +vim.keymap.set("n", "[y", "(YankyPreviousEntry)") +vim.keymap.set("n", "]y", "(YankyNextEntry)") diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 3e9127d5..5e1e9b4b 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -293,10 +293,10 @@ local plugin_specs = { -- Manage your yank history { "gbprod/yanky.nvim", - cmd = { "YankyRingHistory" }, config = function() require("config.yanky") end, + event = "VeryLazy", }, -- Handy unix command inside Vim (Rename, Move etc.) From e3930e8aa705cf6dfe66470b000ce637cab034e3 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 25 Aug 2024 23:35:53 +0200 Subject: [PATCH 045/247] remove unused plugins --- lua/config/zen-mode.lua | 15 --------------- lua/plugin_specs.lua | 13 +------------ 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 lua/config/zen-mode.lua diff --git a/lua/config/zen-mode.lua b/lua/config/zen-mode.lua deleted file mode 100644 index b6d52ce6..00000000 --- a/lua/config/zen-mode.lua +++ /dev/null @@ -1,15 +0,0 @@ -require("zen-mode").setup { - window = { - backdrop = 0.8, -- shade the backdrop of the Zen window. Set to 1 to keep the same as Normal - width = 120, - options = { - -- signcolumn = "no", -- disable signcolumn - -- number = false, -- disable number column - -- relativenumber = false, -- disable relative numbers - cursorline = false, -- disable cursorline - cursorcolumn = false, -- disable cursor column - foldcolumn = "0", -- disable fold column - list = false, -- disable whitespace characters - }, - }, -} diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 5e1e9b4b..35d75aa1 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -62,9 +62,6 @@ local plugin_specs = { end, }, - -- Python indent (follows the PEP8 style) - { "Vimjas/vim-python-pep8-indent", ft = { "python" } }, - -- Python-related text object { "jeetsukumaran/vim-pythonsense", ft = { "python" } }, @@ -397,14 +394,6 @@ local plugin_specs = { ft = { "markdown" }, }, - { - "folke/zen-mode.nvim", - cmd = "ZenMode", - config = function() - require("config.zen-mode") - end, - }, - { "rhysd/vim-grammarous", enabled = function() @@ -456,7 +445,7 @@ local plugin_specs = { -- Modern matchit implementation { "andymass/vim-matchup", event = "BufRead" }, - { "tpope/vim-scriptease", cmd = { "Scriptnames", "Message", "Verbose" } }, + { "tpope/vim-scriptease", cmd = { "Scriptnames", "Messages", "Verbose" } }, -- Asynchronous command execution { "skywind3000/asyncrun.vim", lazy = true, cmd = { "AsyncRun" } }, From 12b0ff02b67bc42e961c2223088887397976dd6b Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 27 Aug 2024 23:11:53 +0200 Subject: [PATCH 046/247] Move autocmd in viml to Lua --- init.lua | 2 +- lua/custom-autocmd.lua | 168 ++++++++++++++++++++++++++++++++++++- viml_conf/autocommands.vim | 121 -------------------------- 3 files changed, 166 insertions(+), 125 deletions(-) delete mode 100644 viml_conf/autocommands.vim diff --git a/init.lua b/init.lua index 5199cd72..083054a2 100644 --- a/init.lua +++ b/init.lua @@ -19,7 +19,7 @@ utils.is_compatible_version(expected_version) local core_conf_files = { "globals.lua", -- some global settings "options.vim", -- setting options in nvim - "autocommands.vim", -- various autocommands + "custom-autocmd.lua", -- various autocommands "mappings.lua", -- all the user-defined mappings "plugins.vim", -- all the plugins installed and their configurations "colorschemes.lua", -- colorscheme settings diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 21fa15ca..3da4b408 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -38,8 +38,8 @@ api.nvim_create_autocmd("TextYankPost", { pattern = "*", group = yank_group, callback = function(ev) - if vim.v.event.operator == 'y' then - vim.fn.setpos('.', vim.g.current_cursor_pos) + if vim.v.event.operator == "y" then + vim.fn.setpos(".", vim.g.current_cursor_pos) end end, }) @@ -102,4 +102,166 @@ local function open_nvim_tree(data) require("nvim-tree.api").tree.open() end -vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree }) +api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree }) + +-- Do not use smart case in command line mode, extracted from https://vi.stackexchange.com/a/16511/15292. +api.nvim_create_augroup("dynamic_smartcase", { clear = true }) +api.nvim_create_autocmd("CmdLineEnter", { + group = "dynamic_smartcase", + pattern = ":", + callback = function() + vim.o.smartcase = false + end, +}) + +api.nvim_create_autocmd("CmdLineLeave", { + group = "dynamic_smartcase", + pattern = ":", + callback = function() + vim.o.smartcase = true + end, +}) + +api.nvim_create_autocmd("TermOpen", { + group = api.nvim_create_augroup("term_start", { clear = true }), + pattern = "*", + callback = function() + -- Do not use number and relative number for terminal inside nvim + vim.wo.relativenumber = false + vim.wo.number = false + + -- Go to insert mode by default to start typing command + vim.cmd("startinsert") + end, +}) + +-- Return to last cursor position when opening a file, note that here we cannot use BufReadPost +-- as event. It seems that when BufReadPost is triggered, FileType event is still not run. +-- So the filetype for this buffer is empty string. +api.nvim_create_autocmd("FileType", { + group = api.nvim_create_augroup("resume_cursor_position", { clear = true }), + pattern = "*", + callback = function(ev) + local mark_pos = api.nvim_buf_get_mark(ev.buf, '"') + local last_cursor_line = mark_pos[1] + + local max_line = vim.fn.line("$") + local buf_filetype = api.nvim_get_option_value("filetype", { buf = ev.buf }) + local buftype = api.nvim_get_option_value("buftype", { buf = ev.buf }) + + -- only handle normal files + if buf_filetype == "" or buftype ~= "" then + return + end + + -- Only resume last cursor position when there is no go-to-line command (something like '+23'). + if vim.fn.match(vim.v.argv, [[\v^\+(\d){1,}$]]) ~= -1 then + return + end + + if last_cursor_line > 1 and last_cursor_line <= max_line then + -- vim.print(string.format("mark_pos: %s", vim.inspect(mark_pos))) + -- it seems that without vim.schedule, the cursor position can not be set correctly + vim.schedule(function() + api.nvim_win_set_cursor(0, mark_pos) + end) + end + end, +}) + +local number_toggle_group = api.nvim_create_augroup("numbertoggle", { clear = true }) +api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, { + pattern = "*", + group = number_toggle_group, + desc = "togger line number", + callback = function() + if vim.wo.number then + vim.wo.relativenumber = true + end + end, +}) + +api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "WinLeave" }, { + group = number_toggle_group, + desc = "togger line number", + callback = function() + if vim.wo.number then + vim.wo.relativenumber = false + end + end, +}) + +api.nvim_create_autocmd("ColorScheme", { + group = api.nvim_create_augroup("custom_highlight", { clear = true }), + pattern = "*", + desc = "Define or overrride some highlight groups", + callback = function() + vim.cmd([[ + " For yank highlight + highlight YankColor ctermfg=59 ctermbg=41 guifg=#34495E guibg=#2ECC71 + + " For cursor colors + highlight Cursor cterm=bold gui=bold guibg=#00c918 guifg=black + highlight Cursor2 guifg=red guibg=red + + " For floating windows border highlight + highlight FloatBorder guifg=LightGreen guibg=NONE + + " highlight for matching parentheses + highlight MatchParen cterm=bold,underline gui=bold,underline + ]]) + end, +}) + +api.nvim_create_autocmd("BufEnter", { + pattern = "*", + group = api.nvim_create_augroup("auto_close_win", { clear = true }), + desc = "Quit Nvim if we have only one window, and its filetype match our pattern", + callback = function(ev) + local quit_filetypes = {'qf', 'vista', 'NvimTree'} + + local should_quit = true + local tabwins = api.nvim_tabpage_list_wins(0) + + for _, win in pairs(tabwins) do + local buf = api.nvim_win_get_buf(win) + local bf = fn.getbufvar(buf, '&filetype') + + if fn.index(quit_filetypes, bf) == -1 then + should_quit = false + end + end + + if should_quit then + vim.cmd("qall") + end + end +}) + +api.nvim_create_autocmd({"VimEnter", "DirChanged"}, { + group = api.nvim_create_augroup("git_repo_check", { clear = true }), + pattern = "*", + desc = "check if we are inside Git repo", + command = "call utils#Inside_git_repo()" +}) + +-- ref: https://vi.stackexchange.com/a/169/15292 +api.nvim_create_autocmd("BufReadPre", { + group = api.nvim_create_augroup("large_file", { clear = true }), + pattern = "*", + desc = "check if we are inside Git repo", + callback = function (ev) + local file_size_limit =524288 -- 0.5MB + local f = ev.file + + if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then + vim.o.eventignore = "all" + -- turning off relative number helps a lot + vim.bo.relativenumber = false + + vim.bo.swapfile = false + vim.bo.bufhidden = "unload" + vim.bo.undolevels = -1 + end + end +}) diff --git a/viml_conf/autocommands.vim b/viml_conf/autocommands.vim deleted file mode 100644 index 3b4ec103..00000000 --- a/viml_conf/autocommands.vim +++ /dev/null @@ -1,121 +0,0 @@ -" Do not use smart case in command line mode, extracted from https://vi.stackexchange.com/a/16511/15292. -augroup dynamic_smartcase - autocmd! - autocmd CmdLineEnter : set nosmartcase - autocmd CmdLineLeave : set smartcase -augroup END - -augroup term_settings - autocmd! - " Do not use number and relative number for terminal inside nvim - autocmd TermOpen * setlocal norelativenumber nonumber - " Go to insert mode by default to start typing command - autocmd TermOpen * startinsert -augroup END - -" More accurate syntax highlighting? (see `:h syn-sync`) -augroup accurate_syn_highlight - autocmd! - autocmd BufEnter * :syntax sync fromstart -augroup END - -" Return to last cursor position when opening a file -augroup resume_cursor_position - autocmd! - autocmd BufReadPost * call s:resume_cursor_position() -augroup END - -" Only resume last cursor position when there is no go-to-line command (something like '+23'). -function s:resume_cursor_position() abort - if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit' - let l:args = v:argv " command line arguments - for l:cur_arg in l:args - " Check if a go-to-line command is given. - let idx = match(l:cur_arg, '\v^\+(\d){1,}$') - if idx != -1 - return - endif - endfor - - execute "normal! g`\"zvzz" - endif -endfunction - -augroup numbertoggle - autocmd! - autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif - autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif -augroup END - -" Define or override some highlight groups -augroup custom_highlight - autocmd! - autocmd ColorScheme * call s:custom_highlight() -augroup END - -function! s:custom_highlight() abort - " For yank highlight - highlight YankColor ctermfg=59 ctermbg=41 guifg=#34495E guibg=#2ECC71 - - " For cursor colors - highlight Cursor cterm=bold gui=bold guibg=#00c918 guifg=black - highlight Cursor2 guifg=red guibg=red - - " For floating windows border highlight - highlight FloatBorder guifg=LightGreen guibg=NONE - - " highlight for matching parentheses - highlight MatchParen cterm=bold,underline gui=bold,underline -endfunction - -augroup auto_close_win - autocmd! - autocmd BufEnter * call s:quit_current_win() -augroup END - -" Quit Nvim if we have only one window, and its filetype match our pattern. -function! s:quit_current_win() abort - let l:quit_filetypes = ['qf', 'vista', 'NvimTree'] - - let l:should_quit = v:true - - let l:tabwins = nvim_tabpage_list_wins(0) - for w in l:tabwins - let l:buf = nvim_win_get_buf(w) - let l:bf = getbufvar(l:buf, '&filetype') - - if index(l:quit_filetypes, l:bf) == -1 - let l:should_quit = v:false - endif - endfor - - if l:should_quit - qall - endif -endfunction - -augroup git_repo_check - autocmd! - autocmd VimEnter,DirChanged * call utils#Inside_git_repo() -augroup END - -" ref: https://vi.stackexchange.com/a/169/15292 -function! s:handle_large_file() abort - let g:file_size_limit = 524288 " 0.5MB - let f = expand("") - - if getfsize(f) > g:file_size_limit || getfsize(f) == -2 - setlocal eventignore=all - " turning off relative number helps a lot - setlocal norelativenumber - setlocal noswapfile bufhidden=unload undolevels=-1 - endif -endfunction - -augroup LargeFile - autocmd! - autocmd BufReadPre * call s:handle_large_file() -augroup END - -" Load auto-command defined in Lua -lua require("custom-autocmd") From 4b4ff5f549736f2ad1a189564d885268a0da75c2 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 29 Aug 2024 21:40:06 +0200 Subject: [PATCH 047/247] Add error handling for resuming the cursor This will close issue #328. --- lua/custom-autocmd.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 3da4b408..6a149f9a 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -163,7 +163,11 @@ api.nvim_create_autocmd("FileType", { -- vim.print(string.format("mark_pos: %s", vim.inspect(mark_pos))) -- it seems that without vim.schedule, the cursor position can not be set correctly vim.schedule(function() - api.nvim_win_set_cursor(0, mark_pos) + local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos) + if not status then + api.nvim_err_writeln(string.format("Failed to resume cursor position. Context %s, error: %s", + vim.inspect(ev), result)) + end end) end end, From fa79647a63c9faf48a09367095092f91b76fa6f4 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 29 Aug 2024 21:43:56 +0200 Subject: [PATCH 048/247] Fix type for option relativenumber "relativenumber" should be window local option, not buffer local option. --- lua/custom-autocmd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 6a149f9a..98566879 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -261,7 +261,7 @@ api.nvim_create_autocmd("BufReadPre", { if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then vim.o.eventignore = "all" -- turning off relative number helps a lot - vim.bo.relativenumber = false + vim.wo.relativenumber = false vim.bo.swapfile = false vim.bo.bufhidden = "unload" From 9071e045ebae642135b89865ac58e26f8cdb5590 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 30 Aug 2024 00:57:51 +0200 Subject: [PATCH 049/247] Make * and # search case aware By default, when you press `*` to search word under the cursor, the option `smartcase` is ignored. This means that if you press `*` when your cursor is on `The`, the lower case one `the` is also searched. In this commit, we translate star and # search into normal search so that 'smartcase' option is respected. --- lua/config/hlslens.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua index c682d5c0..cbf540ad 100644 --- a/lua/config/hlslens.lua +++ b/lua/config/hlslens.lua @@ -35,33 +35,48 @@ keymap.set("n", "N", "", { end, }) -local no_word_under_cursor = function() +local check_cursor_word = function() local cursor_word = vim.fn.expand("") - local result = cursor_word == "" if result then local msg = "E348: No string under cursor" api.nvim_err_writeln(msg) end - return result + return result, cursor_word end keymap.set("n", "*", "", { callback = function() - if no_word_under_cursor() then + local cursor_word_empty, cursor_word = check_cursor_word() + if cursor_word_empty then return end - vim.fn.execute("normal! *N") + + local cmd = string.format([[normal! /\v<%s>]], cursor_word) + + -- In order to say that we are pressing Enter key, instead of typing literally the character, + -- we need to replace special notation with their internal representation. + local escaped_enter = vim.api.nvim_replace_termcodes("", true, false, true) + + -- character `N` is used to keep the cursor when pressing `*` + local full_cmd = cmd .. escaped_enter .. "N" + vim.fn.execute(full_cmd) hlslens.start() end, }) keymap.set("n", "#", "", { callback = function() - if no_word_under_cursor() then + local cursor_word_empty, cursor_word = check_cursor_word() + if cursor_word_empty then return end - vim.fn.execute("normal! #N") + + local cmd = string.format([[normal! ?\v<%s>]], cursor_word) + local escaped_enter = vim.api.nvim_replace_termcodes("", true, false, true) + + local full_cmd = cmd .. escaped_enter .. "N" + vim.fn.execute(full_cmd) hlslens.start() end, }) From a9fc298063a2fccf049dc1ec3295c16722a27d5c Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 30 Aug 2024 01:02:29 +0200 Subject: [PATCH 050/247] update documentation for resuming cursor position --- lua/custom-autocmd.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 98566879..51a648ab 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -169,6 +169,10 @@ api.nvim_create_autocmd("FileType", { vim.inspect(ev), result)) end end) + -- the following two ways also seem to work, + -- ref: https://www.reddit.com/r/neovim/comments/104lc26/how_can_i_press_escape_key_using_lua/ + -- vim.api.nvim_feedkeys("g`\"", "n", true) + -- vim.fn.execute("normal! g`\"") end end, }) From 51f81093dad801ff48178d9fc96ed8ccc9767ed9 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 31 Aug 2024 21:24:54 +0200 Subject: [PATCH 051/247] restructure init.lua --- init.lua | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/init.lua b/init.lua index 083054a2..377d9fb3 100644 --- a/init.lua +++ b/init.lua @@ -16,25 +16,15 @@ local utils = require("utils") local expected_version = "0.10.1" utils.is_compatible_version(expected_version) -local core_conf_files = { - "globals.lua", -- some global settings - "options.vim", -- setting options in nvim - "custom-autocmd.lua", -- various autocommands - "mappings.lua", -- all the user-defined mappings - "plugins.vim", -- all the plugins installed and their configurations - "colorschemes.lua", -- colorscheme settings -} - -local viml_conf_dir = vim.fn.stdpath("config") .. "/viml_conf" --- source all the core config files -for _, file_name in ipairs(core_conf_files) do - if vim.endswith(file_name, 'vim') then - local path = string.format("%s/%s", viml_conf_dir, file_name) - local source_cmd = "source " .. path - vim.cmd(source_cmd) - else - local module_name, _ = string.gsub(file_name, "%.lua", "") - package.loaded[module_name] = nil - require(module_name) - end -end +-- some global settings +require("globals") +-- setting options in nvim +vim.cmd("source viml_conf/options.vim") +-- various autocommands +require("custom-autocmd") +-- all the user-defined mappings +require("mappings") +-- all the plugins installed and their configurations +vim.cmd("source viml_conf/plugins.vim") +-- colorscheme settings +require("colorschemes") From db380ca7a7df1f563d25dbdc3f292a61d795ed93 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 1 Sep 2024 21:46:22 +0200 Subject: [PATCH 052/247] remove inspect() from lua _G table Nvim nows provides `vim.inspect()` and `vim.print()`. --- lua/config/lsp.lua | 2 +- lua/globals.lua | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 2b385a18..69c7b7d5 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -43,7 +43,7 @@ local custom_attach = function(client, bufnr) map("n", "wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) map("n", "wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) map("n", "wl", function() - inspect(vim.lsp.buf.list_workspace_folders()) + vim.print(vim.lsp.buf.list_workspace_folders()) end, { desc = "list workspace folder" }) -- Set some key bindings conditional on server capabilities diff --git a/lua/globals.lua b/lua/globals.lua index b0af26ea..ee964273 100644 --- a/lua/globals.lua +++ b/lua/globals.lua @@ -3,11 +3,6 @@ local api = vim.api local utils = require('utils') --- Inspect something -function _G.inspect(item) - vim.print(item) -end - ------------------------------------------------------------------------ -- custom variables -- ------------------------------------------------------------------------ From 81f64ed32eb229ffe22cec030ab0126b981ab9aa Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 2 Sep 2024 22:18:18 +0200 Subject: [PATCH 053/247] Use absolute path for viml config Full path should be used to load viml config, otherwise, when we open nvim in other directories, we see errors that the viml config can not be found. --- init.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 377d9fb3..77e5c42d 100644 --- a/init.lua +++ b/init.lua @@ -16,15 +16,18 @@ local utils = require("utils") local expected_version = "0.10.1" utils.is_compatible_version(expected_version) +local config_dir = vim.fn.stdpath("config") +---@cast config_dir string + -- some global settings require("globals") -- setting options in nvim -vim.cmd("source viml_conf/options.vim") +vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/options.vim")) -- various autocommands require("custom-autocmd") -- all the user-defined mappings require("mappings") -- all the plugins installed and their configurations -vim.cmd("source viml_conf/plugins.vim") +vim.cmd("source ".. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim")) -- colorscheme settings require("colorschemes") From 154cde3d715b6d5c05392f24fc6c00e0a322be5b Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 19 Sep 2024 22:06:20 +0200 Subject: [PATCH 054/247] Add plugin live-command.nvim --- lua/config/live-command.lua | 6 ++++++ lua/plugin_specs.lua | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 lua/config/live-command.lua diff --git a/lua/config/live-command.lua b/lua/config/live-command.lua new file mode 100644 index 00000000..23230135 --- /dev/null +++ b/lua/config/live-command.lua @@ -0,0 +1,6 @@ +require("live-command").setup { + defaults = { + enable_highlighting = false, + inline_highlighting = false, + }, +} diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 35d75aa1..7a163096 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -563,6 +563,16 @@ local plugin_specs = { require("copilot").setup {} end, }, + { + "smjonas/live-command.nvim", + -- live-command supports semantic versioning via Git tags + -- tag = "2.*", + cmd = "Preview", + config = function() + require("config.live-command") + end, + event = "VeryLazy" + }, } require("lazy").setup { From b9cf3cc6edd97e8e1a0b46833e09de3ef1f91f8c Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 20 Sep 2024 21:25:00 +0200 Subject: [PATCH 055/247] update conf for plugin live-command.nvim --- lua/config/live-command.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/config/live-command.lua b/lua/config/live-command.lua index 23230135..7174a8de 100644 --- a/lua/config/live-command.lua +++ b/lua/config/live-command.lua @@ -1,6 +1,4 @@ require("live-command").setup { - defaults = { - enable_highlighting = false, - inline_highlighting = false, - }, + enable_highlighting = true, + inline_highlighting = true, } From 3040fa7969538e5143cdd747d609e1488adf589f Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 9 Oct 2024 17:35:59 +0200 Subject: [PATCH 056/247] use a cmp-fork for now Until cmp is maintained again or switch?? --- lua/plugin_specs.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 7a163096..93499876 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -23,7 +23,8 @@ end local plugin_specs = { -- auto-completion engine { - "hrsh7th/nvim-cmp", + "iguanacucumber/magazine.nvim", + name = "nvim-cmp", -- event = 'InsertEnter', event = "VeryLazy", dependencies = { @@ -38,7 +39,6 @@ local plugin_specs = { require("config.nvim-cmp") end, }, - { "neovim/nvim-lspconfig", event = { "BufRead", "BufNewFile" }, @@ -571,7 +571,7 @@ local plugin_specs = { config = function() require("config.live-command") end, - event = "VeryLazy" + event = "VeryLazy", }, } From d715ce8f31d4251f2695cddf30df5b2f4908d8bd Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 9 Oct 2024 17:58:18 +0200 Subject: [PATCH 057/247] update supported nvim version to 0.10.2 --- README.md | 6 +++--- init.lua | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 76f3de5c..fb5ac952 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Latest release
- Neovim minimum version + Neovim minimum version Top languages @@ -21,8 +21,8 @@ - - + + diff --git a/init.lua b/init.lua index 77e5c42d..f63e3947 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.10.1" +local expected_version = "0.10.2" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") From 5426c88a90326a3f94af864dbb93eeb18dca6f9b Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 Nov 2024 21:42:51 +0100 Subject: [PATCH 058/247] update Leaderf setting Only search file content and not file name when using Leaderf rg --- viml_conf/plugins.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim index 9b223a6d..19e9befe 100644 --- a/viml_conf/plugins.vim +++ b/viml_conf/plugins.vim @@ -79,7 +79,7 @@ let g:Lf_WorkingDirectoryMode = 'a' nnoremap ff :Leaderf file --popup " Grep project files in popup window -nnoremap fg :Leaderf rg --no-messages --popup +nnoremap fg :Leaderf rg --no-messages --popup --nameOnly " Search vim help files nnoremap fh :Leaderf help --popup From 4171f190f2fefb7b9ab3c4f095e957c09f3a46f8 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 Nov 2024 21:46:43 +0100 Subject: [PATCH 059/247] Add plugin nvim-lightbulb to hint code actions --- lua/plugin_specs.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 93499876..0dc3a1a2 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -573,6 +573,14 @@ local plugin_specs = { end, event = "VeryLazy", }, + { + -- show hint for code actions, the user can also implement code actions themselves, + -- see discussion here: https://github.com/neovim/neovim/issues/14869 + "kosayoda/nvim-lightbulb", + config = function() + require("nvim-lightbulb").setup { autocmd = { enabled = true } } + end, + }, } require("lazy").setup { From 590bd6c7e6259ab9107eeb7a22a47b04bafeafa8 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 Nov 2024 21:53:52 +0100 Subject: [PATCH 060/247] use stylua to format lua files --- after/ftplugin/lua.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/after/ftplugin/lua.vim b/after/ftplugin/lua.vim index 914dd843..cb1abf54 100644 --- a/after/ftplugin/lua.vim +++ b/after/ftplugin/lua.vim @@ -3,3 +3,5 @@ set formatoptions-=o set formatoptions-=r nnoremap :luafile % + +nnoremap f !stylua % From 94cade03be3e87bf096d5c6e78d3d520c3c50ddf Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 Nov 2024 21:59:58 +0100 Subject: [PATCH 061/247] enable inlayhint for lua_ls server The client side inlayhint can be enabled by uncommentting the code in this PR. --- lua/config/lsp.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 69c7b7d5..25f1a7d7 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -51,6 +51,10 @@ local custom_attach = function(client, bufnr) map("n", "f", vim.lsp.buf.format, { desc = "format code" }) end + -- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint, + -- but disable this feature by default, so you may need to enable inlay hint in the LSP server config. + -- vim.lsp.inlay_hint.enable(true, {buffer=bufnr}) + api.nvim_create_autocmd("CursorHold", { buffer = bufnr, callback = function() @@ -220,8 +224,8 @@ if utils.executable("bash-language-server") then } end +-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/ if utils.executable("lua-language-server") then - -- settings for lua-language-server can be found on https://github.com/LuaLS/lua-language-server/wiki/Settings . lspconfig.lua_ls.setup { on_attach = custom_attach, settings = { @@ -230,6 +234,9 @@ if utils.executable("lua-language-server") then -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) version = "LuaJIT", }, + hint = { + enable = true + } }, }, capabilities = capabilities, From 97f72936acaaaab1d10bd986ba27febc2e4510b0 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 Nov 2024 22:03:46 +0100 Subject: [PATCH 062/247] Enable LSP format also for visual selection --- lua/config/lsp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 25f1a7d7..6d0b2865 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -48,7 +48,7 @@ local custom_attach = function(client, bufnr) -- Set some key bindings conditional on server capabilities if client.server_capabilities.documentFormattingProvider then - map("n", "f", vim.lsp.buf.format, { desc = "format code" }) + map({"n", "x"}, "f", vim.lsp.buf.format, { desc = "format code" }) end -- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint, From 9769c24633e9302528bd04850e2acd70e2e16062 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 Nov 2024 22:07:09 +0100 Subject: [PATCH 063/247] Switch Python LSP for completion and add ruff pyright servers type checking, completion, and ruff servers linting and diagnostics (ruff can also format Python files, but it is slightly different from black) --- lua/config/lsp.lua | 119 ++++++++++++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 45 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 6d0b2865..8cd83d5c 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -3,6 +3,7 @@ local api = vim.api local keymap = vim.keymap local lsp = vim.lsp local diagnostic = vim.diagnostic +local lspconfig = require("lspconfig") local utils = require("utils") @@ -114,69 +115,97 @@ local custom_attach = function(client, bufnr) end local capabilities = require('cmp_nvim_lsp').default_capabilities() + -- required by nvim-ufo capabilities.textDocument.foldingRange = { dynamicRegistration = false, lineFoldingOnly = true } -local lspconfig = require("lspconfig") +-- For what diagnostic is enabled in which type checking mode, check doc: +-- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-settings-defaults +-- Currently, the pyright also has some issues displaying hover documentation: +-- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/ -if utils.executable("pylsp") then - local venv_path = os.getenv('VIRTUAL_ENV') - local py_path = nil - -- decide which python executable to use for mypy - if venv_path ~= nil then - py_path = venv_path .. "/bin/python3" - else - py_path = vim.g.python3_host_prog - end +if utils.executable('pyright') then + local new_capability = { + -- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from + -- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482 + textDocument = { + publishDiagnostics = { + tagSupport = { + valueSet = { 2 } + } + } + } + } + local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability) - lspconfig.pylsp.setup { + lspconfig.pyright.setup { + cmd = { "delance-langserver", "--stdio" }, on_attach = custom_attach, + -- capabilities = merged_capability, + capabilities = capabilities, settings = { - pylsp = { - plugins = { - -- formatter options - black = { enabled = true }, - autopep8 = { enabled = false }, - yapf = { enabled = false }, - -- linter options - pylint = { enabled = true, executable = "pylint" }, - ruff = { enabled = false }, - pyflakes = { enabled = false }, - pycodestyle = { enabled = false }, - -- type checker - pylsp_mypy = { - enabled = true, - overrides = { "--python-executable", py_path, true }, - report_progress = true, - live_mode = false + pyright = { + -- disable import sorting and use Ruff for this + disableOrganizeImports = true, + disableTaggedHints = false, + }, + python = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "workspace", + typeCheckingMode = "standard", + useLibraryCodeForTypes = true, + -- we can this setting below to redefine some diagnostics + diagnosticSeverityOverrides = { + deprecateTypingAliases = false, + }, + -- inlay hint settings are provided by pylance? + inlayHints = { + callArgumentNames = "partial", + functionReturnTypes = true, + pytestParameters = true, + variableTypes = true, }, - -- auto-completion options - jedi_completion = { fuzzy = true }, - -- import sorting - isort = { enabled = true }, }, }, }, - flags = { - debounce_text_changes = 200, - }, - capabilities = capabilities, } else - vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" }) + vim.notify("pyright not found!", vim.log.levels.WARN, { title = 'Nvim-config' }) +end + +if utils.executable("ruff") then + require('lspconfig').ruff.setup({ + on_attach = custom_attach, + capabilities = capabilities, + init_options = { + -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/ + settings = { + organizeImports = true, + } + } + }) end --- if utils.executable('pyright') then --- lspconfig.pyright.setup{ --- on_attach = custom_attach, --- capabilities = capabilities --- } --- else --- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) --- end +-- Disable ruff hover feature in favor of Pyright +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup('lsp_attach_disable_ruff_hover', { clear = true }), + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + -- vim.print(client.name, client.server_capabilities) + + if client == nil then + return + end + if client.name == 'ruff' then + client.server_capabilities.hoverProvider = false + end + end, + desc = 'LSP: Disable hover capability from Ruff', +}) if utils.executable("ltex-ls") then lspconfig.ltex.setup { From fe3d5e5922f41c4d4576120808b501f4b18888d8 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 Nov 2024 22:16:07 +0100 Subject: [PATCH 064/247] remove plugin committia.vim --- lua/plugin_specs.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 0dc3a1a2..9149ef7c 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -357,9 +357,6 @@ local plugin_specs = { end, }, - -- Better git commit experience - { "rhysd/committia.vim", lazy = true }, - { "sindrets/diffview.nvim", }, From 1141a18c5f113e618ef73ce0c0b35b1786f9764c Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 6 Nov 2024 23:19:29 +0100 Subject: [PATCH 065/247] update config for pyright --- lua/config/lsp.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 8cd83d5c..d5dd354d 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -144,8 +144,7 @@ if utils.executable('pyright') then lspconfig.pyright.setup { cmd = { "delance-langserver", "--stdio" }, on_attach = custom_attach, - -- capabilities = merged_capability, - capabilities = capabilities, + capabilities = merged_capability, settings = { pyright = { -- disable import sorting and use Ruff for this From 8dfae271d020e198e385382c4f31b15ad4d10405 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 7 Nov 2024 21:51:31 +0100 Subject: [PATCH 066/247] use plaintext for pyright hover request see my comment here for the details: https://www.reddit.com/r/neovim/comments/1gdv1rc/comment/lvt9nlm/ --- lua/config/lsp.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index d5dd354d..2f61e91a 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -136,7 +136,11 @@ if utils.executable('pyright') then tagSupport = { valueSet = { 2 } } - } + }, + hover = { + contentFormat = { "plaintext" }, + dynamicRegistration = true, + }, } } local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability) From d86f5994833cc3a108c81787f788fbc76108cdca Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 8 Nov 2024 22:56:53 +0100 Subject: [PATCH 067/247] update the fold level allowed for statuscol.nvim --- lua/config/nvim-statuscol.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/config/nvim-statuscol.lua b/lua/config/nvim-statuscol.lua index a0998de6..3b860479 100644 --- a/lua/config/nvim-statuscol.lua +++ b/lua/config/nvim-statuscol.lua @@ -3,7 +3,7 @@ local ffi = require("statuscol.ffidef") local C = ffi.C -- only show fold level up to this level -local fold_level_limit = 2 +local fold_level_limit = 3 local function foldfunc(args) local foldinfo = C.fold_info(args.wp, args.lnum) if foldinfo.level > fold_level_limit then From 88802681405ecb6458551af53f2e645ce65bd4e1 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 26 Nov 2024 23:57:28 +0100 Subject: [PATCH 068/247] custom command update 1. Add new command `CopyPath` 2. Revise command `JSONFormat`: implemented using the nvim lua interface and fix a few issues. The previous implementation is removed. --- plugin/command.lua | 58 ++++++++++++++++++++++++++++++++++++++++++++++ plugin/command.vim | 3 --- 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 plugin/command.lua diff --git a/plugin/command.lua b/plugin/command.lua new file mode 100644 index 00000000..b8b744cf --- /dev/null +++ b/plugin/command.lua @@ -0,0 +1,58 @@ +-- Copy file path to clipboard +vim.api.nvim_create_user_command("CopyPath", function(context) + local full_path = vim.fn.glob("%:p") + + local file_path = nil + if context["args"] == "nameonly" then + file_path = vim.fn.fnamemodify(full_path, ":t") + end + + -- get the file path relative to project root + if context["args"] == "relative" then + local project_marker = { ".git", "pyproject.toml" } + local project_root = vim.fs.root(0, project_marker) + if project_root == nil then + vim.print("can not find project root") + return + end + + file_path = string.gsub(full_path, project_root, "") + end + + if context["args"] == "absolute" then + file_path = full_path + end + + vim.fn.setreg("+", file_path) + vim.print("Filepath copied to clipboard!") +end, { + bang = false, + nargs = 1, + force = true, + desc = "Copy current file path to clipboard", + complete = function() + return { "nameonly", "relative", "absolute" } + end, +}) + +-- JSON format part of or the whole file +vim.api.nvim_create_user_command("JSONFormat", function(context) + local range = context["range"] + local line1 = context["line1"] + local line2 = context["line2"] + + if range == 0 then + -- the command is invoked without range, then we assume whole buffer + local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2) + vim.fn.execute(cmd_str) + elseif range == 2 then + -- the command is invoked with some range + local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2) + vim.fn.execute(cmd_str) + else + vim.api.nvim_err_write(string.format("unsupported range: %s", range)) + end +end, { + desc = "Format JSON string", + range = "%", +}) diff --git a/plugin/command.vim b/plugin/command.vim index 68b11f4d..5ed7b738 100644 --- a/plugin/command.vim +++ b/plugin/command.vim @@ -45,6 +45,3 @@ function! s:md_to_pdf() abort echoerr "Error running command" endif endfunction - -" json format -command! -range JSONFormat ,!python -m json.tool From 7645751dc1a3769995defaafb04d61f71f37cd63 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 27 Nov 2024 00:04:44 +0100 Subject: [PATCH 069/247] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb5ac952..24c7ea13 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,6 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu | `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down | | `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser | | `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser | -| `ob` | Normal/Visual | macOS/Win | Open link under cursor or search visual selection | | `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case | | `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case | | `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging | @@ -206,6 +205,7 @@ In addition to commands provided by various plugins, I have also created some cu | `Edit` | edit multiple files at the same time, supports globing | `Edit *.vim` | | `Datetime` | print current date and time or convert Unix time stamp to date and time | `Datetime 12345` or `Datetime` | | `JSONFormat` | format a JSON file | `JSONFormat` | +| `CopyPath` | copy current file path to clipboard | `CopyPath relative` | # Contributing From ab75189231d8a787d011fda4d38a1ee90c27c5e6 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 29 Nov 2024 23:24:03 +0100 Subject: [PATCH 070/247] Fix command CopyPath issue the string.gsub in lua is not flexible and use vim.fn.substitute() instead. --- plugin/command.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/command.lua b/plugin/command.lua index b8b744cf..560dea15 100644 --- a/plugin/command.lua +++ b/plugin/command.lua @@ -16,7 +16,7 @@ vim.api.nvim_create_user_command("CopyPath", function(context) return end - file_path = string.gsub(full_path, project_root, "") + file_path = vim.fn.substitute(full_path, project_root, "", "g") end if context["args"] == "absolute" then From d941be482b69d6dc997eeead02eea2d68ad9d972 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 8 Dec 2024 21:34:08 +0100 Subject: [PATCH 071/247] update lualine config --- lua/config/lualine.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index 08ead79a..dc996310 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -140,13 +140,15 @@ require("lualine").setup { options = { icons_enabled = true, theme = "auto", + component_separators = { left = '⏐', right = '⏐' }, section_separators = "", - component_separators = "", disabled_filetypes = {}, always_divide_middle = true, }, sections = { - lualine_a = { "mode" }, + lualine_a = { + "mode", + }, lualine_b = { { "branch", @@ -154,6 +156,7 @@ require("lualine").setup { -- truncate branch name in case the name is too long return string.sub(name, 1, 20) end, + color = { gui = "italic,bold" }, }, { virtual_env, @@ -192,7 +195,7 @@ require("lualine").setup { }, }, lualine_y = { - "encoding", + { "encoding", fmt = string.upper }, { "fileformat", symbols = { @@ -212,7 +215,8 @@ require("lualine").setup { mixed_indent, color = "WarningMsg", }, - "progress" + "location", + "progress", }, }, inactive_sections = { From 64b41fbd58382e42946bfc3d75ed4b5ff3039db4 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 19 Dec 2024 22:00:21 +0100 Subject: [PATCH 072/247] use native lua api instead of vim.cmd --- lua/custom-autocmd.lua | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 51a648ab..b3ec858b 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -165,8 +165,9 @@ api.nvim_create_autocmd("FileType", { vim.schedule(function() local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos) if not status then - api.nvim_err_writeln(string.format("Failed to resume cursor position. Context %s, error: %s", - vim.inspect(ev), result)) + api.nvim_err_writeln( + string.format("Failed to resume cursor position. Context %s, error: %s", vim.inspect(ev), result) + ) end end) -- the following two ways also seem to work, @@ -204,20 +205,18 @@ api.nvim_create_autocmd("ColorScheme", { pattern = "*", desc = "Define or overrride some highlight groups", callback = function() - vim.cmd([[ - " For yank highlight - highlight YankColor ctermfg=59 ctermbg=41 guifg=#34495E guibg=#2ECC71 + -- For yank highlight + vim.api.nvim_set_hl(0, "YankColor", { fg = "#34495E", bg = "#2ECC71", ctermfg = 59, ctermbg = 41 }) - " For cursor colors - highlight Cursor cterm=bold gui=bold guibg=#00c918 guifg=black - highlight Cursor2 guifg=red guibg=red + -- For cursor colors + vim.api.nvim_set_hl(0, "Cursor", { fg = "black", bg = "#00c918", bold = true }) + vim.api.nvim_set_hl(0, "Cursor2", { fg = "red", bg = "red" }) - " For floating windows border highlight - highlight FloatBorder guifg=LightGreen guibg=NONE + -- For floating windows border highlight + vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen" }) - " highlight for matching parentheses - highlight MatchParen cterm=bold,underline gui=bold,underline - ]]) + -- highlight for matching parentheses + vim.api.nvim_set_hl(0, "MatchParen", { bold = true, underline = true }) end, }) @@ -226,14 +225,14 @@ api.nvim_create_autocmd("BufEnter", { group = api.nvim_create_augroup("auto_close_win", { clear = true }), desc = "Quit Nvim if we have only one window, and its filetype match our pattern", callback = function(ev) - local quit_filetypes = {'qf', 'vista', 'NvimTree'} + local quit_filetypes = { "qf", "vista", "NvimTree" } local should_quit = true local tabwins = api.nvim_tabpage_list_wins(0) for _, win in pairs(tabwins) do local buf = api.nvim_win_get_buf(win) - local bf = fn.getbufvar(buf, '&filetype') + local bf = fn.getbufvar(buf, "&filetype") if fn.index(quit_filetypes, bf) == -1 then should_quit = false @@ -243,14 +242,14 @@ api.nvim_create_autocmd("BufEnter", { if should_quit then vim.cmd("qall") end - end + end, }) -api.nvim_create_autocmd({"VimEnter", "DirChanged"}, { +api.nvim_create_autocmd({ "VimEnter", "DirChanged" }, { group = api.nvim_create_augroup("git_repo_check", { clear = true }), pattern = "*", desc = "check if we are inside Git repo", - command = "call utils#Inside_git_repo()" + command = "call utils#Inside_git_repo()", }) -- ref: https://vi.stackexchange.com/a/169/15292 @@ -258,8 +257,8 @@ api.nvim_create_autocmd("BufReadPre", { group = api.nvim_create_augroup("large_file", { clear = true }), pattern = "*", desc = "check if we are inside Git repo", - callback = function (ev) - local file_size_limit =524288 -- 0.5MB + callback = function(ev) + local file_size_limit = 524288 -- 0.5MB local f = ev.file if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then @@ -271,5 +270,5 @@ api.nvim_create_autocmd("BufReadPre", { vim.bo.bufhidden = "unload" vim.bo.undolevels = -1 end - end + end, }) From 54eb3ca811a4d6a47c035dfafa5410779024003c Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 19 Dec 2024 22:08:22 +0100 Subject: [PATCH 073/247] install new plugins --- lua/plugin_specs.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 9149ef7c..bd522f11 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -542,7 +542,6 @@ local plugin_specs = { }, { "CopilotC-Nvim/CopilotChat.nvim", - branch = "canary", dependencies = { { "zbirenbaum/copilot.lua" }, -- or github/copilot.vim { "nvim-lua/plenary.nvim" }, -- for curl, log wrapper @@ -578,6 +577,17 @@ local plugin_specs = { require("nvim-lightbulb").setup { autocmd = { enabled = true } } end, }, + { + "Bekaboo/dropbar.nvim", + }, + { + "vhyrro/luarocks.nvim", + priority = 1000, -- Very high priority is required, luarocks.nvim should run as the first plugin in your config. + opts = { + rocks = { "lua-toml" }, -- specifies a list of rocks to install + -- luarocks_build_args = { "--with-lua=/my/path" }, -- extra options to pass to luarocks's configuration script + }, + }, } require("lazy").setup { @@ -589,5 +599,6 @@ require("lazy").setup { }, rocks = { enabled = false, + hererocks = false, }, } From 917ab82ffbc4065d4d061fdec080a5f6f31666d4 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 19 Dec 2024 22:12:40 +0100 Subject: [PATCH 074/247] update dict --- spell/en.utf-8.add | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spell/en.utf-8.add b/spell/en.utf-8.add index 42e271e3..da182b78 100644 --- a/spell/en.utf-8.add +++ b/spell/en.utf-8.add @@ -470,3 +470,9 @@ qpdf Elasticsearch kibana submodule +unix +GCP +Kubernetes +pubsub +Luarocks +luarocks From 5328c477a89706ac5f7184744cfb128ae27f4f1c Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 19 Dec 2024 22:15:48 +0100 Subject: [PATCH 075/247] reformat with stylua --- init.lua | 2 +- lua/colorschemes.lua | 8 ++-- lua/config/dashboard-nvim.lua | 14 +++---- lua/config/git-linker.lua | 22 ++++++++--- lua/config/gitsigns.lua | 8 ++-- lua/config/hlslens.lua | 2 +- lua/config/lsp.lua | 73 ++++++++++++++++++----------------- lua/config/lualine.lua | 2 +- lua/config/nvim_hop.lua | 4 +- lua/config/treesitter.lua | 2 +- lua/config/which-key.lua | 4 +- lua/globals.lua | 24 ++++++------ 12 files changed, 89 insertions(+), 76 deletions(-) diff --git a/init.lua b/init.lua index f63e3947..bd897828 100644 --- a/init.lua +++ b/init.lua @@ -28,6 +28,6 @@ require("custom-autocmd") -- all the user-defined mappings require("mappings") -- all the plugins installed and their configurations -vim.cmd("source ".. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim")) +vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim")) -- colorscheme settings require("colorschemes") diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 132e3c28..36b66593 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -50,18 +50,18 @@ M.colorscheme_conf = { end, onedarkpro = function() -- set colorscheme after options - vim.cmd('colorscheme onedark_vivid') + vim.cmd("colorscheme onedark_vivid") end, material = function() vim.g.material_style = "oceanic" - vim.cmd('colorscheme material') + vim.cmd("colorscheme material") end, - arctic = function () + arctic = function() vim.cmd("colorscheme arctic") end, kanagawa = function() vim.cmd("colorscheme kanagawa-wave") - end + end, } --- Use a random colorscheme from the pre-defined list of colorschemes. diff --git a/lua/config/dashboard-nvim.lua b/lua/config/dashboard-nvim.lua index 9017d961..562c124a 100644 --- a/lua/config/dashboard-nvim.lua +++ b/lua/config/dashboard-nvim.lua @@ -59,17 +59,17 @@ conf.center = { }, } -dashboard.setup({ - theme = 'doom', - shortcut_type = 'number', - config = conf -}) +dashboard.setup { + theme = "doom", + shortcut_type = "number", + config = conf, +} api.nvim_create_autocmd("FileType", { pattern = "dashboard", group = api.nvim_create_augroup("dashboard_enter", { clear = true }), - callback = function () + callback = function() keymap.set("n", "q", ":qa", { buffer = true, silent = true }) keymap.set("n", "e", ":enew", { buffer = true, silent = true }) - end + end, }) diff --git a/lua/config/git-linker.lua b/lua/config/git-linker.lua index e3fb3e67..cbb42420 100644 --- a/lua/config/git-linker.lua +++ b/lua/config/git-linker.lua @@ -5,16 +5,26 @@ gitlinker.setup { callbacks = { ["dev.azure.com"] = function(url_data) vim.print(url_data) - local url = require"gitlinker.hosts".get_base_https_url(url_data) + local url = require("gitlinker.hosts").get_base_https_url(url_data) if url_data.lstart then if url_data.lend == nil then url_data.lend = url_data.lstart end - url = url .. "?path=/" .. url_data.file .. "&version=GC" .. url_data.rev .. "&line=" .. url_data.lstart .. "&lineEnd=" .. url_data.lend .. "&lineStartColumn=1" .. "&lineEndColumn=120" + url = url + .. "?path=/" + .. url_data.file + .. "&version=GC" + .. url_data.rev + .. "&line=" + .. url_data.lstart + .. "&lineEnd=" + .. url_data.lend + .. "&lineStartColumn=1" + .. "&lineEndColumn=120" end return url - end + end, }, mappings = nil, } @@ -28,9 +38,9 @@ end, { }) keymap.set("n", "gbr", function() - gitlinker.get_repo_url({ - action_callback = gitlinker.actions.open_in_browser - }) + gitlinker.get_repo_url { + action_callback = gitlinker.actions.open_in_browser, + } end, { silent = true, desc = "Git: browse repo in browser", diff --git a/lua/config/gitsigns.lua b/lua/config/gitsigns.lua index f272dcc9..8bad6b6d 100644 --- a/lua/config/gitsigns.lua +++ b/lua/config/gitsigns.lua @@ -45,13 +45,13 @@ gs.setup { end, } -vim.api.nvim_create_autocmd('ColorScheme', { +vim.api.nvim_create_autocmd("ColorScheme", { pattern = "*", callback = function() - vim.cmd [[ + vim.cmd([[ hi GitSignsChangeInline gui=reverse hi GitSignsAddInline gui=reverse hi GitSignsDeleteInline gui=reverse - ]] - end + ]]) + end, }) diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua index cbf540ad..0f59bca8 100644 --- a/lua/config/hlslens.lua +++ b/lua/config/hlslens.lua @@ -14,7 +14,7 @@ local activate_hlslens = function(direction) -- Deal with the case that there is no such pattern in current buffer. if not status then - local start_idx, _ = string.find(msg, 'E486', 1, true) + local start_idx, _ = string.find(msg, "E486", 1, true) local msg_part = string.sub(msg, start_idx) api.nvim_err_writeln(msg_part) return diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 2f61e91a..87d88fc5 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -13,10 +13,10 @@ local set_qflist = function(buf_num, severity) diagnostics = diagnostic.get(buf_num, { severity = severity }) local qf_items = diagnostic.toqflist(diagnostics) - vim.fn.setqflist({}, ' ', { title = 'Diagnostics', items = qf_items }) + vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items }) -- open quickfix by default - vim.cmd[[copen]] + vim.cmd([[copen]]) end local custom_attach = function(client, bufnr) @@ -39,7 +39,9 @@ local custom_attach = function(client, bufnr) -- this puts diagnostics from opened files to quickfix map("n", "qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" }) -- this puts diagnostics from current buffer to quickfix - map("n", "qb", function() set_qflist(bufnr) end, { desc = "put buffer diagnostics to qf" }) + map("n", "qb", function() + set_qflist(bufnr) + end, { desc = "put buffer diagnostics to qf" }) map("n", "ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) map("n", "wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) map("n", "wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) @@ -49,7 +51,7 @@ local custom_attach = function(client, bufnr) -- Set some key bindings conditional on server capabilities if client.server_capabilities.documentFormattingProvider then - map({"n", "x"}, "f", vim.lsp.buf.format, { desc = "format code" }) + map({ "n", "x" }, "f", vim.lsp.buf.format, { desc = "format code" }) end -- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint, @@ -72,8 +74,9 @@ local custom_attach = function(client, bufnr) end local cursor_pos = api.nvim_win_get_cursor(0) - if (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) - and #diagnostic.get() > 0 + if + (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) + and #diagnostic.get() > 0 then diagnostic.open_float(nil, float_opts) end @@ -91,20 +94,20 @@ local custom_attach = function(client, bufnr) ]]) local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true }) - api.nvim_create_autocmd("CursorHold" , { + api.nvim_create_autocmd("CursorHold", { group = gid, buffer = bufnr, - callback = function () + callback = function() lsp.buf.document_highlight() - end + end, }) - api.nvim_create_autocmd("CursorMoved" , { + api.nvim_create_autocmd("CursorMoved", { group = gid, buffer = bufnr, - callback = function () + callback = function() lsp.buf.clear_references() - end + end, }) end @@ -114,12 +117,12 @@ local custom_attach = function(client, bufnr) end end -local capabilities = require('cmp_nvim_lsp').default_capabilities() +local capabilities = require("cmp_nvim_lsp").default_capabilities() -- required by nvim-ufo capabilities.textDocument.foldingRange = { - dynamicRegistration = false, - lineFoldingOnly = true + dynamicRegistration = false, + lineFoldingOnly = true, } -- For what diagnostic is enabled in which type checking mode, check doc: @@ -127,21 +130,21 @@ capabilities.textDocument.foldingRange = { -- Currently, the pyright also has some issues displaying hover documentation: -- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/ -if utils.executable('pyright') then +if utils.executable("pyright") then local new_capability = { -- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from -- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482 textDocument = { publishDiagnostics = { tagSupport = { - valueSet = { 2 } - } + valueSet = { 2 }, + }, }, hover = { contentFormat = { "plaintext" }, dynamicRegistration = true, }, - } + }, } local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability) @@ -177,25 +180,25 @@ if utils.executable('pyright') then }, } else - vim.notify("pyright not found!", vim.log.levels.WARN, { title = 'Nvim-config' }) + vim.notify("pyright not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end if utils.executable("ruff") then - require('lspconfig').ruff.setup({ + require("lspconfig").ruff.setup { on_attach = custom_attach, capabilities = capabilities, init_options = { -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/ settings = { organizeImports = true, - } - } - }) + }, + }, + } end -- Disable ruff hover feature in favor of Pyright vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup('lsp_attach_disable_ruff_hover', { clear = true }), + group = vim.api.nvim_create_augroup("lsp_attach_disable_ruff_hover", { clear = true }), callback = function(args) local client = vim.lsp.get_client_by_id(args.data.client_id) -- vim.print(client.name, client.server_capabilities) @@ -203,11 +206,11 @@ vim.api.nvim_create_autocmd("LspAttach", { if client == nil then return end - if client.name == 'ruff' then + if client.name == "ruff" then client.server_capabilities.hoverProvider = false end end, - desc = 'LSP: Disable hover capability from Ruff', + desc = "LSP: Disable hover capability from Ruff", }) if utils.executable("ltex-ls") then @@ -217,11 +220,11 @@ if utils.executable("ltex-ls") then filetypes = { "text", "plaintex", "tex", "markdown" }, settings = { ltex = { - language = "en" + language = "en", }, }, flags = { debounce_text_changes = 300 }, -} + } end if utils.executable("clangd") then @@ -267,8 +270,8 @@ if utils.executable("lua-language-server") then version = "LuaJIT", }, hint = { - enable = true - } + enable = true, + }, }, }, capabilities = capabilities, @@ -276,10 +279,10 @@ if utils.executable("lua-language-server") then end -- Change diagnostic signs. -fn.sign_define("DiagnosticSignError", { text = '🆇', texthl = "DiagnosticSignError" }) -fn.sign_define("DiagnosticSignWarn", { text = '⚠️', texthl = "DiagnosticSignWarn" }) -fn.sign_define("DiagnosticSignInfo", { text = 'ℹ️', texthl = "DiagnosticSignInfo" }) -fn.sign_define("DiagnosticSignHint", { text = '', texthl = "DiagnosticSignHint" }) +fn.sign_define("DiagnosticSignError", { text = "🆇", texthl = "DiagnosticSignError" }) +fn.sign_define("DiagnosticSignWarn", { text = "⚠️", texthl = "DiagnosticSignWarn" }) +fn.sign_define("DiagnosticSignInfo", { text = "ℹ️", texthl = "DiagnosticSignInfo" }) +fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) -- global config for diagnostic diagnostic.config { diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index dc996310..d41e2e69 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -140,7 +140,7 @@ require("lualine").setup { options = { icons_enabled = true, theme = "auto", - component_separators = { left = '⏐', right = '⏐' }, + component_separators = { left = "⏐", right = "⏐" }, section_separators = "", disabled_filetypes = {}, always_divide_middle = true, diff --git a/lua/config/nvim_hop.lua b/lua/config/nvim_hop.lua index 11aa60dc..205543d5 100644 --- a/lua/config/nvim_hop.lua +++ b/lua/config/nvim_hop.lua @@ -4,7 +4,7 @@ hop.setup { case_insensitive = true, char2_fallback_key = "", quit_key = "", - match_mappings = { "zh_sc" } + match_mappings = { "zh_sc" }, } keymap.set({ "n", "v", "o" }, "f", "", { @@ -24,5 +24,5 @@ vim.api.nvim_create_autocmd("ColorScheme", { hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff ]]) - end + end, }) diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 41118594..2b455531 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -3,6 +3,6 @@ require("nvim-treesitter.configs").setup { ignore_install = {}, -- List of parsers to ignore installing highlight = { enable = true, -- false will disable the whole extension - disable = { 'help' }, -- list of language that will be disabled + disable = { "help" }, -- list of language that will be disabled }, } diff --git a/lua/config/which-key.lua b/lua/config/which-key.lua index 13b736c9..136895a4 100644 --- a/lua/config/which-key.lua +++ b/lua/config/which-key.lua @@ -1,6 +1,6 @@ require("which-key").setup { preset = "modern", icons = { - mappings = false - } + mappings = false, + }, } diff --git a/lua/globals.lua b/lua/globals.lua index ee964273..7e651765 100644 --- a/lua/globals.lua +++ b/lua/globals.lua @@ -1,28 +1,28 @@ local fn = vim.fn local api = vim.api -local utils = require('utils') +local utils = require("utils") ------------------------------------------------------------------------ -- custom variables -- ------------------------------------------------------------------------ vim.g.is_win = (utils.has("win32") or utils.has("win64")) and true or false vim.g.is_linux = (utils.has("unix") and (not utils.has("macunix"))) and true or false -vim.g.is_mac = utils.has("macunix") and true or false +vim.g.is_mac = utils.has("macunix") and true or false vim.g.logging_level = "info" ------------------------------------------------------------------------ -- builtin variables -- ------------------------------------------------------------------------ -vim.g.loaded_perl_provider = 0 -- Disable perl provider -vim.g.loaded_ruby_provider = 0 -- Disable ruby provider -vim.g.loaded_node_provider = 0 -- Disable node provider -vim.g.did_install_default_menus = 1 -- do not load menu +vim.g.loaded_perl_provider = 0 -- Disable perl provider +vim.g.loaded_ruby_provider = 0 -- Disable ruby provider +vim.g.loaded_node_provider = 0 -- Disable node provider +vim.g.did_install_default_menus = 1 -- do not load menu -if utils.executable('python3') then +if utils.executable("python3") then if vim.g.is_win then - vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", '', 'g') + vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", "", "g") else vim.g.python3_host_prog = fn.exepath("python3") end @@ -32,18 +32,18 @@ else end -- Custom mapping (see `:h mapleader` for more info) -vim.g.mapleader = ',' +vim.g.mapleader = "," -- Enable highlighting for lua HERE doc inside vim script -vim.g.vimsyn_embed = 'l' +vim.g.vimsyn_embed = "l" -- Use English as main language -vim.cmd [[language en_US.UTF-8]] +vim.cmd([[language en_US.UTF-8]]) -- Disable loading certain plugins -- Whether to load netrw by default, see https://github.com/bling/dotvim/issues/4 -vim.g.loaded_netrw = 1 +vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 vim.g.netrw_liststyle = 3 if vim.g.is_win then From 1d66475cae7cfd52433bf6a20ab6776734f18087 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 19 Dec 2024 23:37:03 +0100 Subject: [PATCH 076/247] make option showcmd shown in statusline instead Related issues: + https://groups.google.com/g/vim_dev/c/YwFLUaduXTQ + https://github.com/neovim/neovim/pull/21202 + https://github.com/nvim-lualine/lualine.nvim/issues/949 --- lua/config/lualine.lua | 8 ++++++-- viml_conf/options.vim | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index d41e2e69..587e6ac5 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -175,8 +175,8 @@ require("lualine").setup { source = diff, }, { - ime_state, - color = { fg = "black", bg = "#f46868" }, + "%S", + color = { gui = "bold", fg = "cyan" }, }, { spell, @@ -184,6 +184,10 @@ require("lualine").setup { }, }, lualine_x = { + { + ime_state, + color = { fg = "black", bg = "#f46868" }, + }, { get_active_lsp, icon = " LSP:", diff --git a/viml_conf/options.vim b/viml_conf/options.vim index ca0d66ad..ee4466fa 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -179,3 +179,5 @@ set diffopt+=linematch:60 set nowrap " do no wrap set noruler + +set showcmdloc=statusline From 7e706515a85f9a8931c8bdd14440ac9419405061 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 19 Dec 2024 23:43:40 +0100 Subject: [PATCH 077/247] silently format lua file using stylua We need to disable the mapping set for LSP, otherwise the mapping set in lua.vim will be overridden. --- after/ftplugin/lua.vim | 2 +- lua/config/lsp.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/after/ftplugin/lua.vim b/after/ftplugin/lua.vim index cb1abf54..1c60d66a 100644 --- a/after/ftplugin/lua.vim +++ b/after/ftplugin/lua.vim @@ -4,4 +4,4 @@ set formatoptions-=r nnoremap :luafile % -nnoremap f !stylua % +nnoremap f silent !stylua % diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 87d88fc5..f2c8492c 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -50,7 +50,7 @@ local custom_attach = function(client, bufnr) end, { desc = "list workspace folder" }) -- Set some key bindings conditional on server capabilities - if client.server_capabilities.documentFormattingProvider then + if client.server_capabilities.documentFormattingProvider and client.name ~= "lua_ls" then map({ "n", "x" }, "f", vim.lsp.buf.format, { desc = "format code" }) end From f95d4c09b4245f53eec2397ab3ece9fd4a8c45b9 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 20 Dec 2024 23:54:09 +0100 Subject: [PATCH 078/247] disable mouse --- viml_conf/options.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/viml_conf/options.vim b/viml_conf/options.vim index ee4466fa..23c24661 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -72,7 +72,7 @@ set wildmode=list:longest set scrolloff=3 " Use mouse to select and resize windows, etc. -set mouse=nic " Enable mouse in several mode +set mouse= set mousemodel=popup " Set the behaviour of mouse set mousescroll=ver:1,hor:0 From a02f317a1dfc8f48f53c8da4c9772b19551593ab Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 22 Dec 2024 13:55:53 +0100 Subject: [PATCH 079/247] update supported nvim version to v0.10.3 --- README.md | 6 +++--- init.lua | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 24c7ea13..9c86471b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Latest release - Neovim minimum version + Neovim minimum version Top languages @@ -21,8 +21,8 @@ - - + + diff --git a/init.lua b/init.lua index bd897828..c40ee79e 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.10.2" +local expected_version = "0.10.3" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") From c7fb090e4ce94e72414169a247ac62f049d6b03b Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 22 Dec 2024 13:58:11 +0100 Subject: [PATCH 080/247] update README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c86471b..3813bf09 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ Windows - - Latest release - Neovim minimum version + + Latest release + Top languages From 9a6584bec3d4e459b1521248e6e7df766df9a230 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 29 Jan 2025 00:20:39 +0100 Subject: [PATCH 081/247] add plugin colorzier --- lua/plugin_specs.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index bd522f11..890a4c88 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -588,6 +588,12 @@ local plugin_specs = { -- luarocks_build_args = { "--with-lua=/my/path" }, -- extra options to pass to luarocks's configuration script }, }, + { + "catgoose/nvim-colorizer.lua", + event = "BufReadPre", + opts = { -- set to setup table + }, + }, } require("lazy").setup { From 70e9943aacfa3d9c3cc3846d9bc8762de903df42 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 12 Feb 2025 23:31:18 +0100 Subject: [PATCH 082/247] update supported nvim version to latest stable Update a few plugins --- README.md | 5 +---- init.lua | 2 +- lua/plugin_specs.lua | 15 ++++++++------- viml_conf/plugins.vim | 3 --- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3813bf09..b4a7bef1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows - Neovim minimum version + Neovim minimum version Latest release @@ -21,9 +21,6 @@ - - - diff --git a/init.lua b/init.lua index c40ee79e..cd15458f 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.10.3" +local expected_version = "0.10.4" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 890a4c88..bdc9e5dd 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -278,15 +278,9 @@ local plugin_specs = { -- Multiple cursor plugin like Sublime Text? -- 'mg979/vim-visual-multi' - -- Autosave files on certain events - { "907th/vim-auto-save", event = "InsertEnter" }, - -- Show undo history visually { "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } }, - -- better UI for some nvim actions - { "stevearc/dressing.nvim" }, - -- Manage your yank history { "gbprod/yanky.nvim", @@ -513,7 +507,14 @@ local plugin_specs = { require("config.which-key") end, }, - + { + "folke/snacks.nvim", + priority = 1000, + lazy = false, + opts = { + input = { enabled = true }, + }, + }, -- show and trim trailing whitespaces { "jdhao/whitespace.nvim", event = "VeryLazy" }, diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim index 19e9befe..415bd786 100644 --- a/viml_conf/plugins.vim +++ b/viml_conf/plugins.vim @@ -384,6 +384,3 @@ function! s:wilder_init() abort echohl Error |echomsg "Wilder.nvim missing"| echohl None endtry endfunction - -""""""""""""""""""""""""""""""vim-auto-save settings"""""""""""""""""""""""""""""" -let g:auto_save = 1 " enable AutoSave on Vim startup From 94497c0a73e283d86895ca9ec528d3d86a787b63 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 13 Feb 2025 00:40:35 +0100 Subject: [PATCH 083/247] snack config update --- lua/plugin_specs.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index bdc9e5dd..3a07173e 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -512,7 +512,16 @@ local plugin_specs = { priority = 1000, lazy = false, opts = { - input = { enabled = true }, + -- more beautiful vim.ui.input + input = { + enabled = true, + win = { + relative = "cursor", + backdrop = true, + }, + }, + -- more beautiful vim.ui.select + picker = { enabled = true }, }, }, -- show and trim trailing whitespaces From 7f5374325584d0a5df8929c978343b48f9102362 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 14 Feb 2025 22:03:52 +0100 Subject: [PATCH 084/247] remove automcd to go to last place This conflicts with the fuzzy finder, if you grep for a word using fuzzy finder and then press enter to go to the place, it does not work anymore, it will go the line where you are last time. --- lua/custom-autocmd.lua | 43 ------------------------------------------ 1 file changed, 43 deletions(-) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index b3ec858b..0d6b1b0c 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -135,49 +135,6 @@ api.nvim_create_autocmd("TermOpen", { end, }) --- Return to last cursor position when opening a file, note that here we cannot use BufReadPost --- as event. It seems that when BufReadPost is triggered, FileType event is still not run. --- So the filetype for this buffer is empty string. -api.nvim_create_autocmd("FileType", { - group = api.nvim_create_augroup("resume_cursor_position", { clear = true }), - pattern = "*", - callback = function(ev) - local mark_pos = api.nvim_buf_get_mark(ev.buf, '"') - local last_cursor_line = mark_pos[1] - - local max_line = vim.fn.line("$") - local buf_filetype = api.nvim_get_option_value("filetype", { buf = ev.buf }) - local buftype = api.nvim_get_option_value("buftype", { buf = ev.buf }) - - -- only handle normal files - if buf_filetype == "" or buftype ~= "" then - return - end - - -- Only resume last cursor position when there is no go-to-line command (something like '+23'). - if vim.fn.match(vim.v.argv, [[\v^\+(\d){1,}$]]) ~= -1 then - return - end - - if last_cursor_line > 1 and last_cursor_line <= max_line then - -- vim.print(string.format("mark_pos: %s", vim.inspect(mark_pos))) - -- it seems that without vim.schedule, the cursor position can not be set correctly - vim.schedule(function() - local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos) - if not status then - api.nvim_err_writeln( - string.format("Failed to resume cursor position. Context %s, error: %s", vim.inspect(ev), result) - ) - end - end) - -- the following two ways also seem to work, - -- ref: https://www.reddit.com/r/neovim/comments/104lc26/how_can_i_press_escape_key_using_lua/ - -- vim.api.nvim_feedkeys("g`\"", "n", true) - -- vim.fn.execute("normal! g`\"") - end - end, -}) - local number_toggle_group = api.nvim_create_augroup("numbertoggle", { clear = true }) api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, { pattern = "*", From ee4bce46710e4c58e65e1c41ec5530440768ac9d Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 15 Feb 2025 14:36:24 +0100 Subject: [PATCH 085/247] enable mouse in normal mode --- viml_conf/options.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/viml_conf/options.vim b/viml_conf/options.vim index 23c24661..1e3d2ae4 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -72,7 +72,7 @@ set wildmode=list:longest set scrolloff=3 " Use mouse to select and resize windows, etc. -set mouse= +set mouse=n set mousemodel=popup " Set the behaviour of mouse set mousescroll=ver:1,hor:0 From 28bda349e84a0da79dffb14faba449554f6f9f18 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 15 Feb 2025 18:58:15 +0100 Subject: [PATCH 086/247] Update lualine config (#375) - components are re-ordered - add new component to show git ahead/behind info - remove some unused component --- lua/config/lualine.lua | 165 ++++++++++++++++++++++++++++++++++------- 1 file changed, 139 insertions(+), 26 deletions(-) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index 587e6ac5..6a932e2f 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -1,5 +1,111 @@ local fn = vim.fn +local git_status_cache = {} + +local get_cmd_out = function(cmd) + local result = vim.system(cmd, { text = true }):wait() + + if result.code ~= 0 then + -- vim.print(vim.inspect(result)) + return false, result.stderr + end + + return true, result.stdout +end + +local function split_cmd_string(cmd_str) + return vim.tbl_filter(function(element) + if element ~= "" then + return true + end + return false + end, vim.split(cmd_str, " ")) +end + +local function get_branch_name() + local branch_cmd_str = "git rev-parse --abbrev-ref HEAD" + local branch_cmd = split_cmd_string(branch_cmd_str) + local success, branch_output = get_cmd_out(branch_cmd) + + if not success then + return + end + local branch_name = string.gsub(branch_output, "\n$", "") + -- print(string.format("branch: %s", branch_name)) + + return branch_name +end + +local function update_git_status() + -- Fetch the latest changes from the remote repository (replace 'origin' if needed) + local fetch_cmd = split_cmd_string("git fetch origin") + + local fetch_success, _ = get_cmd_out(fetch_cmd) + if not fetch_success then + return + end + + local branch_name = get_branch_name() + if branch_name == nil then + return + end + + -- Get the number of commits behind + local behind_cmd_str = string.format("git rev-list --count %s..origin/%s", branch_name, branch_name) + local behind_cmd = split_cmd_string(behind_cmd_str) + local behind_success, behind_output = get_cmd_out(behind_cmd) + if behind_success then + local behind_count = tonumber(behind_output:match("(%d+)")) or 0 + git_status_cache.behind = behind_count + end + + -- Get the number of commits ahead + local ahead_cmd_str = string.format("git rev-list --count origin/%s..%s", branch_name, branch_name) + local ahead_cmd = split_cmd_string(ahead_cmd_str) + local ahead_success, ahead_output = get_cmd_out(ahead_cmd) + if ahead_success then + local ahead_count = tonumber(ahead_output:match("(%d+)")) or 0 + git_status_cache.ahead = ahead_count + end +end + +local function get_ahead_behind_info() + local status = git_status_cache + if not status then + return "" + end + + local msg = "" + + if type(status.behind) == "number" and status.behind > 0 then + local behind_str = string.format("↓[%d] ", status.behind) + msg = msg .. behind_str + end + + if type(status.ahead) == "number" and status.ahead > 0 then + local ahead_str = string.format("↑[%d] ", status.ahead) + msg = msg .. ahead_str + end + + return msg +end + +local timer = vim.uv.new_timer() + +local branch_name = get_branch_name() +-- run frequency in seconds +local interval = 30 +local ms = interval * 1000 +if branch_name ~= nil then + timer:start( + 0, + ms, + vim.schedule_wrap(function() + update_git_status() + end) + ) +end + local function spell() if vim.o.spell then return string.format("[SPELL]") @@ -119,7 +225,7 @@ local virtual_env = function() end local get_active_lsp = function() - local msg = "No Active Lsp" + local msg = "🚫" local buf_ft = vim.api.nvim_get_option_value("filetype", {}) local clients = vim.lsp.get_clients { bufnr = 0 } if next(clients) == nil then @@ -147,7 +253,12 @@ require("lualine").setup { }, sections = { lualine_a = { - "mode", + { + "filename", + symbols = { + readonly = "[🔒]", + }, + }, }, lualine_b = { { @@ -159,21 +270,20 @@ require("lualine").setup { color = { gui = "italic,bold" }, }, { - virtual_env, - color = { fg = "black", bg = "#F1CA81" }, - }, - }, - lualine_c = { - { - "filename", - symbols = { - readonly = "[🔒]", - }, + get_ahead_behind_info, + -- "", + color = { fg = "#E0C479" }, }, { "diff", source = diff, }, + { + virtual_env, + color = { fg = "black", bg = "#F1CA81" }, + }, + }, + lualine_c = { { "%S", color = { gui = "bold", fg = "cyan" }, @@ -184,22 +294,29 @@ require("lualine").setup { }, }, lualine_x = { - { - ime_state, - color = { fg = "black", bg = "#f46868" }, - }, { get_active_lsp, - icon = " LSP:", + icon = "📡", }, { "diagnostics", sources = { "nvim_diagnostic" }, symbols = { error = "🆇 ", warn = "⚠️ ", info = "ℹ️ ", hint = " " }, }, + { + trailing_space, + color = "WarningMsg", + }, + { + mixed_indent, + color = "WarningMsg", + }, }, lualine_y = { - { "encoding", fmt = string.upper }, + { + "encoding", + fmt = string.upper, + }, { "fileformat", symbols = { @@ -209,16 +326,12 @@ require("lualine").setup { }, }, "filetype", - }, - lualine_z = { - { - trailing_space, - color = "WarningMsg", - }, { - mixed_indent, - color = "WarningMsg", + ime_state, + color = { fg = "black", bg = "#f46868" }, }, + }, + lualine_z = { "location", "progress", }, From ac421715d364949e72aa030afd83bd77fa49161a Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 16 Feb 2025 01:15:07 +0100 Subject: [PATCH 087/247] Lualine async git info (#376) make everything async and non-blocking and also remove the branch name fetching. It is not needed if we use the @{upstream} notation. --- lua/config/lualine.lua | 101 ++++++++++++----------------------------- 1 file changed, 30 insertions(+), 71 deletions(-) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index 6a932e2f..f2e54f9c 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -2,71 +2,44 @@ local fn = vim.fn local git_status_cache = {} -local get_cmd_out = function(cmd) - local result = vim.system(cmd, { text = true }):wait() - - if result.code ~= 0 then - -- vim.print(vim.inspect(result)) - return false, result.stderr +local on_exit_fetch = function(result) + if result.code == 0 then + git_status_cache.fetch_success = true end - - return true, result.stdout end -local function split_cmd_string(cmd_str) - return vim.tbl_filter(function(element) - if element ~= "" then - return true +local function handle_numeric_result(cache_key) + return function(result) + if result.code == 0 then + git_status_cache[cache_key] = tonumber(result.stdout:match("(%d+)")) or 0 end - return false - end, vim.split(cmd_str, " ")) + end end -local function get_branch_name() - local branch_cmd_str = "git rev-parse --abbrev-ref HEAD" - local branch_cmd = split_cmd_string(branch_cmd_str) - local success, branch_output = get_cmd_out(branch_cmd) - - if not success then - return - end - local branch_name = string.gsub(branch_output, "\n$", "") - -- print(string.format("branch: %s", branch_name)) +local async_cmd = function(cmd_str, on_exit) + local cmd = vim.tbl_filter(function(element) + return element ~= "" + end, vim.split(cmd_str, " ")) - return branch_name + vim.system(cmd, { text = true }, on_exit) end -local function update_git_status() +local async_git_status_update = function() -- Fetch the latest changes from the remote repository (replace 'origin' if needed) - local fetch_cmd = split_cmd_string("git fetch origin") - - local fetch_success, _ = get_cmd_out(fetch_cmd) - if not fetch_success then - return - end - - local branch_name = get_branch_name() - if branch_name == nil then + async_cmd("git fetch origin", on_exit_fetch) + if not git_status_cache.fetch_success then return end -- Get the number of commits behind - local behind_cmd_str = string.format("git rev-list --count %s..origin/%s", branch_name, branch_name) - local behind_cmd = split_cmd_string(behind_cmd_str) - local behind_success, behind_output = get_cmd_out(behind_cmd) - if behind_success then - local behind_count = tonumber(behind_output:match("(%d+)")) or 0 - git_status_cache.behind = behind_count - end + -- the @{upstream} notation is inspired by post: https://www.reddit.com/r/neovim/comments/t48x5i/git_branch_aheadbehind_info_status_line_component/ + -- note that here we should use double dots instead of triple dots + local behind_cmd_str = "git rev-list --count HEAD..@{upstream}" + async_cmd(behind_cmd_str, handle_numeric_result("behind_count")) -- Get the number of commits ahead - local ahead_cmd_str = string.format("git rev-list --count origin/%s..%s", branch_name, branch_name) - local ahead_cmd = split_cmd_string(ahead_cmd_str) - local ahead_success, ahead_output = get_cmd_out(ahead_cmd) - if ahead_success then - local ahead_count = tonumber(ahead_output:match("(%d+)")) or 0 - git_status_cache.ahead = ahead_count - end + local ahead_cmd_str = "git rev-list --count @{upstream}..HEAD" + async_cmd(ahead_cmd_str, handle_numeric_result("ahead_count")) end local function get_ahead_behind_info() @@ -77,34 +50,21 @@ local function get_ahead_behind_info() local msg = "" - if type(status.behind) == "number" and status.behind > 0 then - local behind_str = string.format("↓[%d] ", status.behind) - msg = msg .. behind_str + if type(status.ahead_count) == "number" and status.ahead_count > 0 then + local ahead_str = string.format("↑[%d] ", status.ahead_count) + msg = msg .. ahead_str end - if type(status.ahead) == "number" and status.ahead > 0 then - local ahead_str = string.format("↑[%d] ", status.ahead) - msg = msg .. ahead_str + if type(status.behind_count) == "number" and status.behind_count > 0 then + local behind_str = string.format("↓[%d] ", status.behind_count) + msg = msg .. behind_str end return msg end -local timer = vim.uv.new_timer() - -local branch_name = get_branch_name() --- run frequency in seconds -local interval = 30 -local ms = interval * 1000 -if branch_name ~= nil then - timer:start( - 0, - ms, - vim.schedule_wrap(function() - update_git_status() - end) - ) -end +local timer = vim.loop.new_timer() +timer:start(0, 1000, async_git_status_update) local function spell() if vim.o.spell then @@ -271,7 +231,6 @@ require("lualine").setup { }, { get_ahead_behind_info, - -- "", color = { fg = "#E0C479" }, }, { From 2242961925be4549e81ecdca5505f9845158d116 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 16 Feb 2025 19:13:24 +0100 Subject: [PATCH 088/247] Remove obsolete func (#377) - remove function: SynGroup, HasColorscheme and GetGitBranch - rewrite Inside_git_repo in lua instead --- autoload/utils.vim | 38 -------------------------------------- lua/custom-autocmd.lua | 6 ++++-- lua/mappings.lua | 3 --- lua/utils.lua | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/autoload/utils.vim b/autoload/utils.vim index a004bd58..14fb651e 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -10,23 +10,6 @@ function! s:Single_quote(str) abort return "'" . substitute(copy(a:str), "'", "''", 'g') . "'" endfunction -" Check the syntax group in the current cursor position, see -" https://stackoverflow.com/q/9464844/6064933 and -" https://jordanelver.co.uk/blog/2015/05/27/working-with-vim-colorschemes/ -function! utils#SynGroup() abort - if !exists('*synstack') - return - endif - echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') -endfunction - -" Check if a colorscheme exists in runtimepath. -" The following two functions are inspired by https://stackoverflow.com/a/5703164/6064933. -function! utils#HasColorscheme(name) abort - let l:pat = printf('colors/%s.vim', a:name) - return !empty(globpath(&runtimepath, l:pat)) -endfunction - " Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292 function! utils#VimFolds(lnum) abort " get content of current line and the line below @@ -146,27 +129,6 @@ function! utils#iso_time(timestamp) abort endfunction -" Check if we are inside a Git repo. -function! utils#Inside_git_repo() abort - let res = system('git rev-parse --is-inside-work-tree') - if match(res, 'true') == -1 - return v:false - else - " Manually trigger a special user autocmd InGitRepo (used lazyloading. - doautocmd User InGitRepo - return v:true - endif -endfunction - -function! utils#GetGitBranch() - let l:res = systemlist('git rev-parse --abbrev-ref HEAD')[0] - if match(l:res, 'fatal') != -1 - return '' - else - return l:res - endif -endfunction - " Redirect command output to a register for later processing. " Ref: https://stackoverflow.com/q/2573021/6064933 and https://unix.stackexchange.com/q/8101/221410 . function! utils#CaptureCommandOutput(command) abort diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 0d6b1b0c..e03a0222 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -206,14 +206,16 @@ api.nvim_create_autocmd({ "VimEnter", "DirChanged" }, { group = api.nvim_create_augroup("git_repo_check", { clear = true }), pattern = "*", desc = "check if we are inside Git repo", - command = "call utils#Inside_git_repo()", + callback = function() + utils.inside_git_repo() + end, }) -- ref: https://vi.stackexchange.com/a/169/15292 api.nvim_create_autocmd("BufReadPre", { group = api.nvim_create_augroup("large_file", { clear = true }), pattern = "*", - desc = "check if we are inside Git repo", + desc = "optimize for large file", callback = function(ev) local file_size_limit = 524288 -- 0.5MB local f = ev.file diff --git a/lua/mappings.lua b/lua/mappings.lua index 7b4980ea..368035bf 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -143,9 +143,6 @@ keymap.set("x", "c", '"_c') -- Remove trailing whitespace characters keymap.set("n", "", "StripTrailingWhitespace", { desc = "remove trailing space" }) --- check the syntax group of current cursor position -keymap.set("n", "st", "call utils#SynGroup()", { desc = "check syntax group" }) - -- Copy entire buffer. keymap.set("n", "y", "%yank", { desc = "yank entire buffer" }) diff --git a/lua/utils.lua b/lua/utils.lua index 86a97d08..a1a37777 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -79,4 +79,18 @@ function M.is_compatible_version(expected_version) return true end +--- check if we are inside a git repo +--- @return boolean +function M.inside_git_repo() + local result = vim.system({ "git", "rev-parse", "--is-inside-work-tree" }, { text = true }):wait() + if result.code ~= 0 then + return false + end + + -- Manually trigger a special user autocmd InGitRepo (used lazyloading. + vim.cmd([[doautocmd User InGitRepo]]) + + return true +end + return M From 4b8c490abd5d6b9cad33841b61142674cab26e67 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 16 Feb 2025 19:20:21 +0100 Subject: [PATCH 089/247] fix gitsign word_diff flickering issue (#378) I guess it is due to the reason that we are doing constant git fetch, and somehow gitsigns word diff is affected. Changing the gitsigns debounce or changing lualine refresh rate do not seem to help. So gitsigns word diff is disabled. --- lua/config/gitsigns.lua | 6 +++--- lua/config/lualine.lua | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lua/config/gitsigns.lua b/lua/config/gitsigns.lua index 8bad6b6d..c7216b7e 100644 --- a/lua/config/gitsigns.lua +++ b/lua/config/gitsigns.lua @@ -8,7 +8,7 @@ gs.setup { topdelete = { text = "‾" }, changedelete = { text = "│" }, }, - word_diff = true, + word_diff = false, on_attach = function(bufnr) local function map(mode, l, r, opts) opts = opts or {} @@ -38,10 +38,10 @@ gs.setup { end, { expr = true, desc = "previous hunk" }) -- Actions - map("n", "hp", gs.preview_hunk) + map("n", "hp", gs.preview_hunk, { desc = "preview hunk" }) map("n", "hb", function() gs.blame_line { full = true } - end) + end, { desc = "blame hunk" }) end, } diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index f2e54f9c..a9bfdbf9 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -42,7 +42,9 @@ local async_git_status_update = function() async_cmd(ahead_cmd_str, handle_numeric_result("ahead_count")) end -local function get_ahead_behind_info() +local function get_git_ahead_behind_info() + async_git_status_update() + local status = git_status_cache if not status then return "" @@ -63,9 +65,6 @@ local function get_ahead_behind_info() return msg end -local timer = vim.loop.new_timer() -timer:start(0, 1000, async_git_status_update) - local function spell() if vim.o.spell then return string.format("[SPELL]") @@ -210,6 +209,9 @@ require("lualine").setup { section_separators = "", disabled_filetypes = {}, always_divide_middle = true, + refresh = { + statusline = 500, + }, }, sections = { lualine_a = { @@ -230,7 +232,7 @@ require("lualine").setup { color = { gui = "italic,bold" }, }, { - get_ahead_behind_info, + get_git_ahead_behind_info, color = { fg = "#E0C479" }, }, { From 93166c65a57c846212cc98d988a8012c65cb1db7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 16 Feb 2025 19:52:34 +0100 Subject: [PATCH 090/247] update colorscheme config (#379) --- lua/colorschemes.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 36b66593..12149699 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -1,5 +1,4 @@ --- This module will load a random colorscheme on nvim startup process. - local utils = require("utils") local M = {} @@ -8,9 +7,14 @@ local M = {} -- the same as the colorscheme name itself. M.colorscheme_conf = { onedark = function() - vim.cmd([[colorscheme onedark]]) + -- Lua + require("onedark").setup { + style = "darker", + } + require("onedark").load() end, edge = function() + vim.g.edge_style = "default" vim.g.edge_enable_italic = 1 vim.g.edge_better_performance = 1 @@ -26,13 +30,14 @@ M.colorscheme_conf = { -- foreground option can be material, mix, or original vim.g.gruvbox_material_foreground = "original" --background option can be hard, medium, soft - vim.g.gruvbox_material_background = "medium" + vim.g.gruvbox_material_background = "hard" vim.g.gruvbox_material_enable_italic = 1 vim.g.gruvbox_material_better_performance = 1 vim.cmd([[colorscheme gruvbox-material]]) end, everforest = function() + vim.g.everforest_background = "hard" vim.g.everforest_enable_italic = 1 vim.g.everforest_better_performance = 1 @@ -50,10 +55,11 @@ M.colorscheme_conf = { end, onedarkpro = function() -- set colorscheme after options - vim.cmd("colorscheme onedark_vivid") + -- onedark_vivid does not enough contrast + vim.cmd("colorscheme onedark_dark") end, material = function() - vim.g.material_style = "oceanic" + vim.g.material_style = "darker" vim.cmd("colorscheme material") end, arctic = function() @@ -67,6 +73,7 @@ M.colorscheme_conf = { --- Use a random colorscheme from the pre-defined list of colorschemes. M.rand_colorscheme = function() local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf)) + colorscheme = "gruvbox_material" if not vim.tbl_contains(vim.tbl_keys(M.colorscheme_conf), colorscheme) then local msg = "Invalid colorscheme: " .. colorscheme From ab059bbb6d440322af791b93024d1711e4d13b28 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 16 Feb 2025 20:15:41 +0100 Subject: [PATCH 091/247] use treesitter-textobjects instead (#380) Note that we should keep the branch of nvim-treesitter and nvim-treesitter-textobjects the same. `main` is targeted at nightly neovim and `master` is for stable neovim. See also https://github.com/nvim-treesitter/nvim-treesitter/issues/4767 --- lua/config/treesitter-textobjects.lua | 44 +++++++++++++++++++++++++++ lua/plugin_specs.lua | 12 +++++--- 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 lua/config/treesitter-textobjects.lua diff --git a/lua/config/treesitter-textobjects.lua b/lua/config/treesitter-textobjects.lua new file mode 100644 index 00000000..32e9e5f6 --- /dev/null +++ b/lua/config/treesitter-textobjects.lua @@ -0,0 +1,44 @@ +require("nvim-treesitter.configs").setup { + textobjects = { + select = { + enable = true, + + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + -- You can optionally set descriptions to the mappings (used in the desc parameter of + -- nvim_buf_set_keymap) which plugins like which-key display + ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" }, + }, + -- You can choose the select mode (default is charwise 'v') + -- + -- Can also be a function which gets passed a table with the keys + -- * query_string: eg '@function.inner' + -- * method: eg 'v' or 'o' + -- and should return the mode ('v', 'V', or '') or a table + -- mapping query_strings to modes. + selection_modes = { + ["@function.inner"] = "V", -- linewise + ["@function.outer"] = "V", -- linewise + ["@class.outer"] = "V", -- linewise + ["@class.inner"] = "V", -- linewise + ["@parameter.outer"] = "v", -- charwise + }, + -- If you set this to `true` (default is `false`) then any textobject is + -- extended to include preceding or succeeding whitespace. Succeeding + -- whitespace has priority in order to act similarly to eg the built-in + -- `ap`. + -- + -- Can also be a function which gets passed a table with the keys + -- * query_string: eg '@function.inner' + -- * selection_mode: eg 'v' + -- and should return true or false + include_surrounding_whitespace = false, + }, + }, +} diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 3a07173e..9342b6d6 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -61,10 +61,14 @@ local plugin_specs = { require("config.treesitter") end, }, - - -- Python-related text object - { "jeetsukumaran/vim-pythonsense", ft = { "python" } }, - + { + "nvim-treesitter/nvim-treesitter-textobjects", + event = "VeryLazy", + branch = "master", + config = function() + require("config.treesitter-textobjects") + end, + }, { "machakann/vim-swap", event = "VeryLazy" }, -- IDE for Lisp From 2383eb70755ce72e0375169051309c01dd33c480 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 16 Feb 2025 21:03:17 +0100 Subject: [PATCH 092/247] switch back to nvim-cmp (#381) --- lua/config/lsp.lua | 2 +- lua/plugin_specs.lua | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index f2c8492c..1496010e 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -117,7 +117,7 @@ local custom_attach = function(client, bufnr) end end -local capabilities = require("cmp_nvim_lsp").default_capabilities() +local capabilities = vim.lsp.protocol.make_client_capabilities() -- required by nvim-ufo capabilities.textDocument.foldingRange = { diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 9342b6d6..6f6faa12 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -23,7 +23,7 @@ end local plugin_specs = { -- auto-completion engine { - "iguanacucumber/magazine.nvim", + "hrsh7th/nvim-cmp", name = "nvim-cmp", -- event = 'InsertEnter', event = "VeryLazy", @@ -39,6 +39,7 @@ local plugin_specs = { require("config.nvim-cmp") end, }, + { "neovim/nvim-lspconfig", event = { "BufRead", "BufNewFile" }, @@ -385,7 +386,7 @@ local plugin_specs = { end return false end, - build = "cd app && npm install", + build = "cd app && npm install && git restore .", ft = { "markdown" }, }, From a00e1fd92a6ce35ea315b723553ff40265f0ab8c Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 5 Mar 2025 23:08:27 +0100 Subject: [PATCH 093/247] Remove luarocks (#383) remove luarocks.nvim as it is causing startup delays --- .gitignore | 1 + lua/plugin_specs.lua | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 75dbbbba..178e9446 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ en.utf-8.add.spl .netrwhist *.log .DS_Store +lazy-lock.json diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 6f6faa12..5a8b3383 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -595,14 +595,6 @@ local plugin_specs = { { "Bekaboo/dropbar.nvim", }, - { - "vhyrro/luarocks.nvim", - priority = 1000, -- Very high priority is required, luarocks.nvim should run as the first plugin in your config. - opts = { - rocks = { "lua-toml" }, -- specifies a list of rocks to install - -- luarocks_build_args = { "--with-lua=/my/path" }, -- extra options to pass to luarocks's configuration script - }, - }, { "catgoose/nvim-colorizer.lua", event = "BufReadPre", From 8cba1ba234604069cee272eb55649203c21d9dde Mon Sep 17 00:00:00 2001 From: Okarin Date: Fri, 21 Mar 2025 14:42:33 +0100 Subject: [PATCH 094/247] Install treesitter on all systems (#384) For some reason treesitter gets only installed on mac os. This conflicts with treesitter-textobjects which gets installed for every system. --- lua/plugin_specs.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 5a8b3383..ba229206 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -50,12 +50,6 @@ local plugin_specs = { { "nvim-treesitter/nvim-treesitter", - enabled = function() - if vim.g.is_mac then - return true - end - return false - end, event = "VeryLazy", build = ":TSUpdate", config = function() From f005a8303d5e275a07ec423a0b42c5e0f4083c21 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 26 Mar 2025 22:33:39 +0100 Subject: [PATCH 095/247] Nvim version bump (#385) * update nvim version to 0.11.0 * replace deprecated nvim_err_write/nvim_err_writeln call * replace deprecated func for diagnostic and lsp * use vim.hl instead * use new way to define diagnostic signs --- README.md | 2 +- init.lua | 2 +- lua/config/hlslens.lua | 4 ++-- lua/config/lsp.lua | 39 +++++++++++++++++---------------------- lua/custom-autocmd.lua | 2 +- lua/globals.lua | 3 ++- lua/utils.lua | 4 ++-- plugin/command.lua | 3 ++- viml_conf/options.vim | 1 + 9 files changed, 29 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index b4a7bef1..e3b9542c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows - Neovim minimum version + Neovim minimum version Latest release diff --git a/init.lua b/init.lua index cd15458f..aa7d3c39 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.10.4" +local expected_version = "0.11.0" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua index 0f59bca8..e216a645 100644 --- a/lua/config/hlslens.lua +++ b/lua/config/hlslens.lua @@ -16,7 +16,7 @@ local activate_hlslens = function(direction) if not status then local start_idx, _ = string.find(msg, "E486", 1, true) local msg_part = string.sub(msg, start_idx) - api.nvim_err_writeln(msg_part) + api.nvim_echo({ { msg_part } }, true, { err = true }) return end @@ -40,7 +40,7 @@ local check_cursor_word = function() local result = cursor_word == "" if result then local msg = "E348: No string under cursor" - api.nvim_err_writeln(msg) + api.nvim_echo({ { msg } }, true, { err = true }) end return result, cursor_word diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 1496010e..a9633d5d 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -30,12 +30,18 @@ local custom_attach = function(client, bufnr) map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) map("n", "", vim.lsp.buf.definition) - map("n", "K", vim.lsp.buf.hover) + map("n", "K", function() + vim.lsp.buf.hover { border = "rounded" } + end) map("n", "", vim.lsp.buf.signature_help) map("n", "rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) - map("n", "[d", diagnostic.goto_prev, { desc = "previous diagnostic" }) - map("n", "]d", diagnostic.goto_next, { desc = "next diagnostic" }) + map("n", "[d", function() + diagnostic.jump { count = -1, float = true } + end, { desc = "previous diagnostic" }) + map("n", "]d", function() + diagnostic.jump { count = 1, float = true } + end, { desc = "next diagnostic" }) -- this puts diagnostics from opened files to quickfix map("n", "qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" }) -- this puts diagnostics from current buffer to quickfix @@ -278,28 +284,17 @@ if utils.executable("lua-language-server") then } end --- Change diagnostic signs. -fn.sign_define("DiagnosticSignError", { text = "🆇", texthl = "DiagnosticSignError" }) -fn.sign_define("DiagnosticSignWarn", { text = "⚠️", texthl = "DiagnosticSignWarn" }) -fn.sign_define("DiagnosticSignInfo", { text = "ℹ️", texthl = "DiagnosticSignInfo" }) -fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) - -- global config for diagnostic diagnostic.config { underline = false, virtual_text = false, - signs = true, + signs = { + text = { + [diagnostic.severity.ERROR] = "🆇", + [diagnostic.severity.WARN] = "⚠️", + [diagnostic.severity.INFO] = "ℹ️", + [diagnostic.severity.HINT] = "", + }, + }, severity_sort = true, } - --- lsp.handlers["textDocument/publishDiagnostics"] = lsp.with(lsp.diagnostic.on_publish_diagnostics, { --- underline = false, --- virtual_text = false, --- signs = true, --- update_in_insert = false, --- }) - --- Change border of documentation hover window, See https://github.com/neovim/neovim/pull/13998. -lsp.handlers["textDocument/hover"] = lsp.with(vim.lsp.handlers.hover, { - border = "rounded", -}) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index e03a0222..3cbe54d5 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -22,7 +22,7 @@ api.nvim_create_autocmd({ "TextYankPost" }, { pattern = "*", group = yank_group, callback = function() - vim.highlight.on_yank { higroup = "YankColor", timeout = 300 } + vim.hl.on_yank { higroup = "YankColor", timeout = 300 } end, }) diff --git a/lua/globals.lua b/lua/globals.lua index 7e651765..e0bdad69 100644 --- a/lua/globals.lua +++ b/lua/globals.lua @@ -27,7 +27,8 @@ if utils.executable("python3") then vim.g.python3_host_prog = fn.exepath("python3") end else - api.nvim_err_writeln("Python3 executable not found! You must install Python3 and set its PATH correctly!") + local msg = "Python3 executable not found! You must install Python3 and set its PATH correctly!" + api.nvim_echo({ { msg } }, true, { err = true }) return end diff --git a/lua/utils.lua b/lua/utils.lua index a1a37777..d77dc1a9 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -61,7 +61,7 @@ function M.is_compatible_version(expected_version) if expect_ver == nil then local msg = string.format("Unsupported version string: %s", expected_version) - vim.api.nvim_err_writeln(msg) + vim.api.nvim_echo({ { msg } }, true, { err = true }) return false end @@ -73,7 +73,7 @@ function M.is_compatible_version(expected_version) expected_version, _ver ) - vim.api.nvim_err_writeln(msg) + vim.api.nvim_echo({ { msg } }, true, { err = true }) end return true diff --git a/plugin/command.lua b/plugin/command.lua index 560dea15..006e3724 100644 --- a/plugin/command.lua +++ b/plugin/command.lua @@ -50,7 +50,8 @@ vim.api.nvim_create_user_command("JSONFormat", function(context) local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2) vim.fn.execute(cmd_str) else - vim.api.nvim_err_write(string.format("unsupported range: %s", range)) + local msg = string.format("unsupported range: %s", range) + vim.api.nvim_echo({ { msg } }, true, { err = true }) end end, { desc = "Format JSON string", diff --git a/viml_conf/options.vim b/viml_conf/options.vim index 1e3d2ae4..d0e813d2 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -124,6 +124,7 @@ set pumheight=10 " Maximum number of items to show in popup menu set pumblend=5 " pseudo transparency for completion menu set winblend=0 " pseudo transparency for floating window +set winborder=none " Insert mode key word completion setting set complete+=kspell complete-=w complete-=b complete-=u complete-=t From 5f662f143b2589260f88522027a859ab9d502629 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 28 Mar 2025 20:27:02 +0100 Subject: [PATCH 096/247] update various config after nvim 0.11 release (#386) --- lua/config/lsp.lua | 61 +++++++++++++++++++++---------------------- lua/globals.lua | 3 +++ lua/mappings.lua | 13 --------- viml_conf/options.vim | 2 ++ 4 files changed, 35 insertions(+), 44 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index a9633d5d..32dc0ecf 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -1,4 +1,3 @@ -local fn = vim.fn local api = vim.api local keymap = vim.keymap local lsp = vim.lsp @@ -31,16 +30,16 @@ local custom_attach = function(client, bufnr) map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) map("n", "", vim.lsp.buf.definition) map("n", "K", function() - vim.lsp.buf.hover { border = "rounded" } + vim.lsp.buf.hover { border = "single", max_height = 25 } end) map("n", "", vim.lsp.buf.signature_help) map("n", "rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) map("n", "[d", function() - diagnostic.jump { count = -1, float = true } + diagnostic.jump { count = -1 } end, { desc = "previous diagnostic" }) map("n", "]d", function() - diagnostic.jump { count = 1, float = true } + diagnostic.jump { count = 1 } end, { desc = "next diagnostic" }) -- this puts diagnostics from opened files to quickfix map("n", "qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" }) @@ -64,33 +63,6 @@ local custom_attach = function(client, bufnr) -- but disable this feature by default, so you may need to enable inlay hint in the LSP server config. -- vim.lsp.inlay_hint.enable(true, {buffer=bufnr}) - api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local float_opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = "rounded", - source = "always", -- show source in diagnostic popup window - prefix = " ", - } - - if not vim.b.diagnostics_pos then - vim.b.diagnostics_pos = { nil, nil } - end - - local cursor_pos = api.nvim_win_get_cursor(0) - if - (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) - and #diagnostic.get() > 0 - then - diagnostic.open_float(nil, float_opts) - end - - vim.b.diagnostics_pos = cursor_pos - end, - }) - -- The blow command will highlight the current variable and its usages in the buffer. if client.server_capabilities.documentHighlightProvider then vim.cmd([[ @@ -288,6 +260,7 @@ end diagnostic.config { underline = false, virtual_text = false, + virtual_lines = false, signs = { text = { [diagnostic.severity.ERROR] = "🆇", @@ -297,4 +270,30 @@ diagnostic.config { }, }, severity_sort = true, + float = { + source = true, + header = "Diagnostics:", + prefix = " ", + border = "single", + }, } + +api.nvim_create_autocmd("CursorHold", { + pattern = "*", + callback = function() + if #vim.diagnostic.get(0) == 0 then + return + end + + if not vim.b.diagnostics_pos then + vim.b.diagnostics_pos = { nil, nil } + end + + local cursor_pos = api.nvim_win_get_cursor(0) + if cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2] then + diagnostic.open_float() + end + + vim.b.diagnostics_pos = cursor_pos + end, +}) diff --git a/lua/globals.lua b/lua/globals.lua index e0bdad69..2163360a 100644 --- a/lua/globals.lua +++ b/lua/globals.lua @@ -69,3 +69,6 @@ vim.g.loaded_matchparen = 1 -- Disable sql omni completion, it is broken. vim.g.loaded_sql_completion = 1 + +-- control how to show health check window +vim.g.health = { style = nil } diff --git a/lua/mappings.lua b/lua/mappings.lua index 368035bf..9915ef5c 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -23,19 +23,6 @@ keymap.set("n", "q", "x", { silent = true, desc = "quit current -- Quit all opened buffers keymap.set("n", "Q", "qa!", { silent = true, desc = "quit nvim" }) --- Navigation in the location and quickfix list -keymap.set("n", "[l", "lpreviouszv", { silent = true, desc = "previous location item" }) -keymap.set("n", "]l", "lnextzv", { silent = true, desc = "next location item" }) - -keymap.set("n", "[L", "lfirstzv", { silent = true, desc = "first location item" }) -keymap.set("n", "]L", "llastzv", { silent = true, desc = "last location item" }) - -keymap.set("n", "[q", "cpreviouszv", { silent = true, desc = "previous qf item" }) -keymap.set("n", "]q", "cnextzv", { silent = true, desc = "next qf item" }) - -keymap.set("n", "[Q", "cfirstzv", { silent = true, desc = "first qf item" }) -keymap.set("n", "]Q", "clastzv", { silent = true, desc = "last qf item" }) - -- Close location list or quickfix list if they are present, see https://superuser.com/q/355325/736190 keymap.set("n", [[\x]], "windo lclose cclose ", { silent = true, diff --git a/viml_conf/options.vim b/viml_conf/options.vim index d0e813d2..31902859 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -115,6 +115,8 @@ set shortmess+=S " Disable showing intro message (:intro) set shortmess+=I +set messagesopt=wait:5000,history:500 + " Completion behaviour " set completeopt+=noinsert " Auto select the first completion entry set completeopt+=menuone " Show menu even if there is only one item From a8a1b929212c9d2a015a14215dd58d94bc7bdfe8 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 28 Mar 2025 20:29:39 +0100 Subject: [PATCH 097/247] update floating window highlight (#387) --- lua/custom-autocmd.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 3cbe54d5..2f7356a6 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -170,7 +170,11 @@ api.nvim_create_autocmd("ColorScheme", { vim.api.nvim_set_hl(0, "Cursor2", { fg = "red", bg = "red" }) -- For floating windows border highlight - vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen" }) + vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen", bg = "None", bold = true }) + + local hl = vim.api.nvim_get_hl(0, { name = "NormalFloat" }) + -- change the background color of floating window to None, so it blenders better + vim.api.nvim_set_hl(0, "NormalFloat", { fg = hl.fg, bg = "None" }) -- highlight for matching parentheses vim.api.nvim_set_hl(0, "MatchParen", { bold = true, underline = true }) From 12147bec86d83f85c7ea59921f8248760d6f42f0 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 30 Mar 2025 17:55:51 +0200 Subject: [PATCH 098/247] Use glance.nvim for lsp references/implementations preview (#388) --- lua/config/glance.lua | 12 ++++++++++++ lua/plugin_specs.lua | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 lua/config/glance.lua diff --git a/lua/config/glance.lua b/lua/config/glance.lua new file mode 100644 index 00000000..daaef828 --- /dev/null +++ b/lua/config/glance.lua @@ -0,0 +1,12 @@ +local glance = require("glance") + +glance.setup { + height = 25, + border = { + enable = true, + }, +} + +vim.keymap.set("n", "gd", "Glance definitions") +vim.keymap.set("n", "gr", "Glance references") +vim.keymap.set("n", "gi", "Glance implementations") diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index ba229206..2bdbd623 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -47,7 +47,13 @@ local plugin_specs = { require("config.lsp") end, }, - + { + "dnlhc/glance.nvim", + config = function() + require("config.glance") + end, + envnt = "VeryLazy", + }, { "nvim-treesitter/nvim-treesitter", event = "VeryLazy", From 0816faee76a4d4308816fea6c74342212e6e291e Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 30 Mar 2025 17:58:09 +0200 Subject: [PATCH 099/247] Separate diagnostic config from lsp ones (#389) --- init.lua | 9 ++++- lua/config/lsp.lua | 75 +---------------------------------------- lua/diagnostic-conf.lua | 66 ++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 75 deletions(-) create mode 100644 lua/diagnostic-conf.lua diff --git a/init.lua b/init.lua index aa7d3c39..4beead9f 100644 --- a/init.lua +++ b/init.lua @@ -29,5 +29,12 @@ require("custom-autocmd") require("mappings") -- all the plugins installed and their configurations vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim")) + +-- diagnostic related config +require("diagnostic-conf") + -- colorscheme settings -require("colorschemes") +local color_scheme = require("colorschemes") + +-- Load a random colorscheme +color_scheme.rand_colorscheme() diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 32dc0ecf..374ab88d 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -6,18 +6,6 @@ local lspconfig = require("lspconfig") local utils = require("utils") --- set quickfix list from diagnostics in a certain buffer, not the whole workspace -local set_qflist = function(buf_num, severity) - local diagnostics = nil - diagnostics = diagnostic.get(buf_num, { severity = severity }) - - local qf_items = diagnostic.toqflist(diagnostics) - vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items }) - - -- open quickfix by default - vim.cmd([[copen]]) -end - local custom_attach = function(client, bufnr) -- Mappings. local map = function(mode, l, r, opts) @@ -30,23 +18,10 @@ local custom_attach = function(client, bufnr) map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) map("n", "", vim.lsp.buf.definition) map("n", "K", function() - vim.lsp.buf.hover { border = "single", max_height = 25 } + vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 } end) map("n", "", vim.lsp.buf.signature_help) map("n", "rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) - map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) - map("n", "[d", function() - diagnostic.jump { count = -1 } - end, { desc = "previous diagnostic" }) - map("n", "]d", function() - diagnostic.jump { count = 1 } - end, { desc = "next diagnostic" }) - -- this puts diagnostics from opened files to quickfix - map("n", "qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" }) - -- this puts diagnostics from current buffer to quickfix - map("n", "qb", function() - set_qflist(bufnr) - end, { desc = "put buffer diagnostics to qf" }) map("n", "ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) map("n", "wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) map("n", "wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) @@ -65,12 +40,6 @@ local custom_attach = function(client, bufnr) -- The blow command will highlight the current variable and its usages in the buffer. if client.server_capabilities.documentHighlightProvider then - vim.cmd([[ - hi! link LspReferenceRead Visual - hi! link LspReferenceText Visual - hi! link LspReferenceWrite Visual - ]]) - local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true }) api.nvim_create_autocmd("CursorHold", { group = gid, @@ -255,45 +224,3 @@ if utils.executable("lua-language-server") then capabilities = capabilities, } end - --- global config for diagnostic -diagnostic.config { - underline = false, - virtual_text = false, - virtual_lines = false, - signs = { - text = { - [diagnostic.severity.ERROR] = "🆇", - [diagnostic.severity.WARN] = "⚠️", - [diagnostic.severity.INFO] = "ℹ️", - [diagnostic.severity.HINT] = "", - }, - }, - severity_sort = true, - float = { - source = true, - header = "Diagnostics:", - prefix = " ", - border = "single", - }, -} - -api.nvim_create_autocmd("CursorHold", { - pattern = "*", - callback = function() - if #vim.diagnostic.get(0) == 0 then - return - end - - if not vim.b.diagnostics_pos then - vim.b.diagnostics_pos = { nil, nil } - end - - local cursor_pos = api.nvim_win_get_cursor(0) - if cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2] then - diagnostic.open_float() - end - - vim.b.diagnostics_pos = cursor_pos - end, -}) diff --git a/lua/diagnostic-conf.lua b/lua/diagnostic-conf.lua new file mode 100644 index 00000000..e50a4be9 --- /dev/null +++ b/lua/diagnostic-conf.lua @@ -0,0 +1,66 @@ +local diagnostic = vim.diagnostic +local api = vim.api + +-- global config for diagnostic +diagnostic.config { + underline = false, + virtual_text = false, + virtual_lines = false, + signs = { + text = { + [diagnostic.severity.ERROR] = "🆇", + [diagnostic.severity.WARN] = "⚠️", + [diagnostic.severity.INFO] = "ℹ️", + [diagnostic.severity.HINT] = "", + }, + }, + severity_sort = true, + float = { + source = true, + header = "Diagnostics:", + prefix = " ", + border = "single", + }, +} + +-- set quickfix list from diagnostics in a certain buffer, not the whole workspace +local set_qflist = function(buf_num, severity) + local diagnostics = nil + diagnostics = diagnostic.get(buf_num, { severity = severity }) + + local qf_items = diagnostic.toqflist(diagnostics) + vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items }) + + -- open quickfix by default + vim.cmd([[copen]]) +end + +-- this puts diagnostics from opened files to quickfix +vim.keymap.set("n", "qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" }) + +-- this puts diagnostics from current buffer to quickfix +vim.keymap.set("n", "qb", function() + set_qflist(0) +end, { desc = "put buffer diagnostics to qf" }) + +-- automatically show diagnostic in float win for current line +api.nvim_create_autocmd("CursorHold", { + pattern = "*", + callback = function() + if #vim.diagnostic.get(0) == 0 then + return + end + + if not vim.b.diagnostics_pos then + vim.b.diagnostics_pos = { nil, nil } + end + + local cursor_pos = api.nvim_win_get_cursor(0) + + if not vim.deep_equal(cursor_pos, vim.b.diagnostics_pos) then + diagnostic.open_float { width = 100 } + end + + vim.b.diagnostics_pos = cursor_pos + end, +}) From b82c1c112fd59bddd770f05932028d9a7bd0b336 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 30 Mar 2025 18:02:28 +0200 Subject: [PATCH 100/247] update colorscheme (#390) 1. Remove catppuccin, it is too purple/blue for me 2. use another nightfox variant --- lua/colorschemes.lua | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 12149699..978af758 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -44,14 +44,7 @@ M.colorscheme_conf = { vim.cmd([[colorscheme everforest]]) end, nightfox = function() - vim.cmd([[colorscheme nordfox]]) - end, - catppuccin = function() - -- available option: latte, frappe, macchiato, mocha - vim.g.catppuccin_flavour = "frappe" - require("catppuccin").setup() - - vim.cmd([[colorscheme catppuccin]]) + vim.cmd([[colorscheme carbonfox]]) end, onedarkpro = function() -- set colorscheme after options @@ -73,14 +66,6 @@ M.colorscheme_conf = { --- Use a random colorscheme from the pre-defined list of colorschemes. M.rand_colorscheme = function() local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf)) - colorscheme = "gruvbox_material" - - if not vim.tbl_contains(vim.tbl_keys(M.colorscheme_conf), colorscheme) then - local msg = "Invalid colorscheme: " .. colorscheme - vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" }) - - return - end -- Load the colorscheme and its settings M.colorscheme_conf[colorscheme]() @@ -92,5 +77,4 @@ M.rand_colorscheme = function() end end --- Load a random colorscheme -M.rand_colorscheme() +return M From 265f171172beb1289806bbc22c632c39048cfb86 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 30 Mar 2025 18:58:23 +0200 Subject: [PATCH 101/247] remove unused variable --- lua/config/lsp.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 374ab88d..abc10167 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -1,7 +1,6 @@ local api = vim.api local keymap = vim.keymap local lsp = vim.lsp -local diagnostic = vim.diagnostic local lspconfig = require("lspconfig") local utils = require("utils") From 625a4ffa475ee3d6ce6a66dc6d92840f6033f98e Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 30 Mar 2025 20:21:35 +0200 Subject: [PATCH 102/247] update config for lazydev and nvim-lightbulb (#391) --- lua/config/lightbulb.lua | 20 ++++++++++++++++++++ lua/plugin_specs.lua | 11 +++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 lua/config/lightbulb.lua diff --git a/lua/config/lightbulb.lua b/lua/config/lightbulb.lua new file mode 100644 index 00000000..8f49746b --- /dev/null +++ b/lua/config/lightbulb.lua @@ -0,0 +1,20 @@ +---@diagnostic disable: missing-fields +require("nvim-lightbulb").setup { + autocmd = { + enabled = true, + updatetime = -1, + }, + ---@diagnostic disable-next-line: unused-local + filter = function(client_name, result) + -- Ruff always sends these two actions even if there are no action to take, + -- so it is better to just ignore this to avoid noise. See also discussion below: + -- https://github.com/astral-sh/ruff-lsp/issues/91 + local ignored_kinds = { "source.fixAll.ruff", "source.organizeImports.ruff" } + + if vim.tbl_contains(ignored_kinds, result.kind) then + return false + end + + return true + end, +} diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 2bdbd623..b5d64b3d 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -553,7 +553,13 @@ local plugin_specs = { { "folke/lazydev.nvim", ft = "lua", -- only load on lua files - opts = {}, + opts = { + library = { + -- See the configuration section for more details + -- Load luvit types when the `vim.uv` word is found + { path = "${3rd}/luv/library", words = { "vim%.uv" } }, + }, + }, }, { "CopilotC-Nvim/CopilotChat.nvim", @@ -589,7 +595,7 @@ local plugin_specs = { -- see discussion here: https://github.com/neovim/neovim/issues/14869 "kosayoda/nvim-lightbulb", config = function() - require("nvim-lightbulb").setup { autocmd = { enabled = true } } + require("config.lightbulb") end, }, { @@ -603,6 +609,7 @@ local plugin_specs = { }, } +---@diagnostic disable-next-line: missing-fields require("lazy").setup { spec = plugin_specs, ui = { From 72e6480933339a993643e8023b93b8fa57bf088c Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 30 Mar 2025 20:54:53 +0200 Subject: [PATCH 103/247] Use LspAttach to configure buffer behavior (#392) --- lua/config/lsp.lua | 152 +++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 81 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index abc10167..42d263f1 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -5,63 +5,77 @@ local lspconfig = require("lspconfig") local utils = require("utils") -local custom_attach = function(client, bufnr) - -- Mappings. - local map = function(mode, l, r, opts) - opts = opts or {} - opts.silent = true - opts.buffer = bufnr - keymap.set(mode, l, r, opts) - end - - map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) - map("n", "", vim.lsp.buf.definition) - map("n", "K", function() - vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 } - end) - map("n", "", vim.lsp.buf.signature_help) - map("n", "rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) - map("n", "ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) - map("n", "wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) - map("n", "wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) - map("n", "wl", function() - vim.print(vim.lsp.buf.list_workspace_folders()) - end, { desc = "list workspace folder" }) - - -- Set some key bindings conditional on server capabilities - if client.server_capabilities.documentFormattingProvider and client.name ~= "lua_ls" then - map({ "n", "x" }, "f", vim.lsp.buf.format, { desc = "format code" }) - end - - -- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint, - -- but disable this feature by default, so you may need to enable inlay hint in the LSP server config. - -- vim.lsp.inlay_hint.enable(true, {buffer=bufnr}) - - -- The blow command will highlight the current variable and its usages in the buffer. - if client.server_capabilities.documentHighlightProvider then - local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true }) - api.nvim_create_autocmd("CursorHold", { - group = gid, - buffer = bufnr, - callback = function() - lsp.buf.document_highlight() - end, - }) - - api.nvim_create_autocmd("CursorMoved", { - group = gid, - buffer = bufnr, - callback = function() - lsp.buf.clear_references() - end, - }) - end - - if vim.g.logging_level == "debug" then - local msg = string.format("Language server %s started!", client.name) - vim.notify(msg, vim.log.levels.DEBUG, { title = "Nvim-config" }) - end -end +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("buf_behavior_conf", { clear = true }), + callback = function(event_context) + local client = vim.lsp.get_client_by_id(event_context.data.client_id) + -- vim.print(client.name, client.server_capabilities) + + if not client then + return + end + + local bufnr = event_context.buf + + -- Mappings. + local map = function(mode, l, r, opts) + opts = opts or {} + opts.silent = true + opts.buffer = bufnr + keymap.set(mode, l, r, opts) + end + + map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) + map("n", "", vim.lsp.buf.definition) + map("n", "K", function() + vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 } + end) + map("n", "", vim.lsp.buf.signature_help) + map("n", "rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) + map("n", "ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) + map("n", "wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) + map("n", "wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) + map("n", "wl", function() + vim.print(vim.lsp.buf.list_workspace_folders()) + end, { desc = "list workspace folder" }) + + -- Set some key bindings conditional on server capabilities + if client.server_capabilities.documentFormattingProvider and client.name ~= "lua_ls" then + map({ "n", "x" }, "f", vim.lsp.buf.format, { desc = "format code" }) + end + + -- Disable ruff hover feature in favor of Pyright + if client.name == "ruff" then + client.server_capabilities.hoverProvider = false + end + + -- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint, + -- but disable this feature by default, so you may need to enable inlay hint in the LSP server config. + -- vim.lsp.inlay_hint.enable(true, {buffer=bufnr}) + + -- The blow command will highlight the current variable and its usages in the buffer. + if client.server_capabilities.documentHighlightProvider then + local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true }) + api.nvim_create_autocmd("CursorHold", { + group = gid, + buffer = bufnr, + callback = function() + lsp.buf.document_highlight() + end, + }) + + api.nvim_create_autocmd("CursorMoved", { + group = gid, + buffer = bufnr, + callback = function() + lsp.buf.clear_references() + end, + }) + end + end, + nested = true, + desc = "Configure buffer keymap and behavior based on LSP", +}) local capabilities = vim.lsp.protocol.make_client_capabilities() @@ -96,7 +110,6 @@ if utils.executable("pyright") then lspconfig.pyright.setup { cmd = { "delance-langserver", "--stdio" }, - on_attach = custom_attach, capabilities = merged_capability, settings = { pyright = { @@ -131,7 +144,6 @@ end if utils.executable("ruff") then require("lspconfig").ruff.setup { - on_attach = custom_attach, capabilities = capabilities, init_options = { -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/ @@ -142,26 +154,8 @@ if utils.executable("ruff") then } end --- Disable ruff hover feature in favor of Pyright -vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("lsp_attach_disable_ruff_hover", { clear = true }), - callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - -- vim.print(client.name, client.server_capabilities) - - if client == nil then - return - end - if client.name == "ruff" then - client.server_capabilities.hoverProvider = false - end - end, - desc = "LSP: Disable hover capability from Ruff", -}) - if utils.executable("ltex-ls") then lspconfig.ltex.setup { - on_attach = custom_attach, cmd = { "ltex-ls" }, filetypes = { "text", "plaintex", "tex", "markdown" }, settings = { @@ -175,7 +169,6 @@ end if utils.executable("clangd") then lspconfig.clangd.setup { - on_attach = custom_attach, capabilities = capabilities, filetypes = { "c", "cpp", "cc" }, flags = { @@ -187,7 +180,6 @@ end -- set up vim-language-server if utils.executable("vim-language-server") then lspconfig.vimls.setup { - on_attach = custom_attach, flags = { debounce_text_changes = 500, }, @@ -200,7 +192,6 @@ end -- set up bash-language-server if utils.executable("bash-language-server") then lspconfig.bashls.setup { - on_attach = custom_attach, capabilities = capabilities, } end @@ -208,7 +199,6 @@ end -- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/ if utils.executable("lua-language-server") then lspconfig.lua_ls.setup { - on_attach = custom_attach, settings = { Lua = { runtime = { From bfc531656a5de86e1209cbc1a78b71cddaa53099 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 30 Mar 2025 20:56:43 +0200 Subject: [PATCH 104/247] Add option messagesopt config --- viml_conf/options.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/viml_conf/options.vim b/viml_conf/options.vim index 31902859..08d984bd 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -115,7 +115,7 @@ set shortmess+=S " Disable showing intro message (:intro) set shortmess+=I -set messagesopt=wait:5000,history:500 +set messagesopt=hit-enter,history:500 " Completion behaviour " set completeopt+=noinsert " Auto select the first completion entry From d17289cd6ba06138ab06f99fc208c0cd0fa91c84 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 30 Mar 2025 21:00:21 +0200 Subject: [PATCH 105/247] use builtin log level enum to specify log level (#393) --- lua/colorschemes.lua | 6 ------ lua/globals.lua | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 978af758..2365e5cd 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -69,12 +69,6 @@ M.rand_colorscheme = function() -- Load the colorscheme and its settings M.colorscheme_conf[colorscheme]() - - if vim.g.logging_level == "debug" then - local msg = "Colorscheme: " .. colorscheme - - vim.notify(msg, vim.log.levels.DEBUG, { title = "nvim-config" }) - end end return M diff --git a/lua/globals.lua b/lua/globals.lua index 2163360a..d1a06a76 100644 --- a/lua/globals.lua +++ b/lua/globals.lua @@ -10,7 +10,7 @@ vim.g.is_win = (utils.has("win32") or utils.has("win64")) and true or false vim.g.is_linux = (utils.has("unix") and (not utils.has("macunix"))) and true or false vim.g.is_mac = utils.has("macunix") and true or false -vim.g.logging_level = "info" +vim.g.logging_level = vim.log.levels.INFO ------------------------------------------------------------------------ -- builtin variables -- From f76ef3dbb46711c1de2b25b92d7092f8d5a13272 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 30 Mar 2025 21:01:02 +0200 Subject: [PATCH 106/247] fix diagnostic issues --- lua/custom-autocmd.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 2f7356a6..dba479e7 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -37,7 +37,8 @@ api.nvim_create_autocmd({ "CursorMoved" }, { api.nvim_create_autocmd("TextYankPost", { pattern = "*", group = yank_group, - callback = function(ev) + ---@diagnostic disable-next-line: unused-local + callback = function(context) if vim.v.event.operator == "y" then vim.fn.setpos(".", vim.g.current_cursor_pos) end @@ -185,7 +186,8 @@ api.nvim_create_autocmd("BufEnter", { pattern = "*", group = api.nvim_create_augroup("auto_close_win", { clear = true }), desc = "Quit Nvim if we have only one window, and its filetype match our pattern", - callback = function(ev) + ---@diagnostic disable-next-line: unused-local + callback = function(context) local quit_filetypes = { "qf", "vista", "NvimTree" } local should_quit = true @@ -193,9 +195,9 @@ api.nvim_create_autocmd("BufEnter", { for _, win in pairs(tabwins) do local buf = api.nvim_win_get_buf(win) - local bf = fn.getbufvar(buf, "&filetype") + local buf_type = vim.api.nvim_get_option_value("filetype", { buf = buf }) - if fn.index(quit_filetypes, bf) == -1 then + if not vim.tbl_contains(quit_filetypes, buf_type) then should_quit = false end end From 7fa77fbfbfc4ac0a67df90b9e61ac55d5e893ef5 Mon Sep 17 00:00:00 2001 From: Ya Zhuang <499038+zhuangya@users.noreply.github.com> Date: Mon, 31 Mar 2025 14:50:35 +0800 Subject: [PATCH 107/247] fix typo (#394) --- lua/plugin_specs.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index b5d64b3d..475006c0 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -52,7 +52,7 @@ local plugin_specs = { config = function() require("config.glance") end, - envnt = "VeryLazy", + event = "VeryLazy", }, { "nvim-treesitter/nvim-treesitter", From 60852c0473c88065c1c3d7bc95e9823eacb0e335 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 2 Apr 2025 18:20:01 +0200 Subject: [PATCH 108/247] Switch from LeaderF to Fzf-lua as the default fuzzy finder (#395) --- README.md | 7 ++-- lua/config/dashboard-nvim.lua | 6 +-- lua/plugin_specs.lua | 28 ++++++------- viml_conf/plugins.vim | 79 ----------------------------------- 4 files changed, 18 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index e3b9542c..a03da8f2 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ and how to set up on different platforms (Linux, macOS, and Windows). + Language server protocol (LSP) support via [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig). + Git integration via [vim-fugitive](https://github.com/tpope/vim-fugitive). + Better escaping from insert mode via [better-escape.vim](https://github.com/nvim-zh/better-escape.vim). -+ Ultra-fast project-wide fuzzy searching via [LeaderF](https://github.com/Yggdroot/LeaderF). ++ Ultra-fast project-wide fuzzy searching via [fzf-lua](https://github.com/ibhagwan/fzf-lua). + Faster code commenting via [vim-commentary](https://github.com/tpope/vim-commentary). + Faster matching pair insertion and jump via [nvim-autopairs](https://github.com/windwp/nvim-autopairs). + Smarter and faster matching pair management (add, replace or delete) via [vim-sandwich](https://github.com/machakann/vim-sandwich). @@ -79,7 +79,6 @@ and how to set up on different platforms (Linux, macOS, and Windows). + LaTeX editing and previewing via [vimtex](https://github.com/lervag/vimtex) + Animated GUI style notification via [nvim-notify](https://github.com/rcarriga/nvim-notify). + Tags navigation via [vista](https://github.com/liuchengxu/vista.vim). -+ Code formatting via [Neoformat](https://github.com/sbdchd/neoformat). + Undo management via [vim-mundo](https://github.com/simnalamburt/vim-mundo) + Code folding with [nvim-ufo](https://github.com/kevinhwang91/nvim-ufo) and [statuscol.nvim](https://github.com/luukvbaal/statuscol.nvim) + ...... @@ -94,10 +93,10 @@ For more UI demos, check [here](https://github.com/jdhao/nvim-config/issues/15).

-## File fuzzy finding using LeaderF +## File fuzzy finding using fzf-lua

- +

## Code autocompletion with nvim-cmp diff --git a/lua/config/dashboard-nvim.lua b/lua/config/dashboard-nvim.lua index 562c124a..fd921717 100644 --- a/lua/config/dashboard-nvim.lua +++ b/lua/config/dashboard-nvim.lua @@ -23,19 +23,19 @@ conf.center = { { icon = "󰈞 ", desc = "Find File ", - action = "Leaderf file --popup", + action = "FzfLua files", key = " f f", }, { icon = "󰈢 ", desc = "Recently opened files ", - action = "Leaderf mru --popup", + action = "FzfLua oldfiles", key = " f r", }, { icon = "󰈬 ", desc = "Project grep ", - action = "Leaderf rg --popup", + action = "FzfLua live_grep", key = " f g", }, { diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 475006c0..5f201bd5 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -106,20 +106,6 @@ local plugin_specs = { require("config.hlslens") end, }, - { - "Yggdroot/LeaderF", - cmd = "Leaderf", - build = function() - local leaderf_path = plugin_dir .. "/LeaderF" - vim.opt.runtimepath:append(leaderf_path) - vim.cmd("runtime! plugin/leaderf.vim") - - if not vim.g.is_win then - vim.cmd("LeaderfInstallCExtension") - end - end, - }, - "nvim-lua/plenary.nvim", { "nvim-telescope/telescope.nvim", cmd = "Telescope", @@ -132,8 +118,18 @@ local plugin_specs = { -- optional for icon support dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() - -- calling `setup` is optional for customization - require("fzf-lua").setup {} + require("fzf-lua").setup { + winopts = { + row = 0.5, + height = 0.7, + }, + } + + vim.keymap.set("n", "ff", "FzfLua files", { desc = "Fuzzy find files" }) + vim.keymap.set("n", "fg", "FzfLua live_grep", { desc = "Fuzzy grep files" }) + vim.keymap.set("n", "fh", "FzfLua helptags", { desc = "Fuzzy grep tags in help files" }) + vim.keymap.set("n", "ft", "FzfLua btags", { desc = "Fuzzy search buffer tags" }) + vim.keymap.set("n", "fb", "FzfLua buffers", { desc = "Fuzzy search opened buffers" }) end, }, { diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim index 415bd786..cbf8ec4f 100644 --- a/viml_conf/plugins.vim +++ b/viml_conf/plugins.vim @@ -34,85 +34,6 @@ let g:UltiSnipsSnippetDirectories=['UltiSnips', 'my_snippets'] """""""""""""""""""""""""" vlime settings """""""""""""""""""""""""""""""" command! -nargs=0 StartVlime call jobstart(printf("sbcl --load %s/vlime/lisp/start-vlime.lisp", g:package_home)) -"""""""""""""""""""""""""""""LeaderF settings""""""""""""""""""""" -" Do not use cache file -let g:Lf_UseCache = 0 -" Refresh each time we call leaderf -let g:Lf_UseMemoryCache = 0 - -" Ignore certain files and directories when searching files -let g:Lf_WildIgnore = { - \ 'dir': ['.git', '__pycache__', '.DS_Store', '*_cache'], - \ 'file': ['*.exe', '*.dll', '*.so', '*.o', '*.pyc', '*.jpg', '*.png', - \ '*.gif', '*.svg', '*.ico', '*.db', '*.tgz', '*.tar.gz', '*.gz', - \ '*.zip', '*.bin', '*.pptx', '*.xlsx', '*.docx', '*.pdf', '*.tmp', - \ '*.wmv', '*.mkv', '*.mp4', '*.rmvb', '*.ttf', '*.ttc', '*.otf', - \ '*.mp3', '*.aac'] - \} - -" Do not show fancy icons for Linux server. -if g:is_linux - let g:Lf_ShowDevIcons = 0 -endif - -" Only fuzzy-search files names -let g:Lf_DefaultMode = 'FullPath' - -" Do not use version control tool to list files under a directory since -" submodules are not searched by default. -let g:Lf_UseVersionControlTool = 0 - -" Use rg as the default search tool -let g:Lf_DefaultExternalTool = "rg" - -" show dot files -let g:Lf_ShowHidden = 1 - -" Disable default mapping -let g:Lf_ShortcutF = '' -let g:Lf_ShortcutB = '' - -" set up working directory for git repository -let g:Lf_WorkingDirectoryMode = 'a' - -" Search files in popup window -nnoremap ff :Leaderf file --popup - -" Grep project files in popup window -nnoremap fg :Leaderf rg --no-messages --popup --nameOnly - -" Search vim help files -nnoremap fh :Leaderf help --popup - -" Search tags in current buffer -nnoremap ft :Leaderf bufTag --popup - -" Switch buffers -nnoremap fb :Leaderf buffer --popup - -" Search recent files -nnoremap fr :Leaderf mru --popup --absolute-path - -let g:Lf_PopupColorscheme = 'gruvbox_material' - -" Change keybinding in LeaderF prompt mode, use ctrl-n and ctrl-p to navigate -" items. -let g:Lf_CommandMap = {'': [''], '': ['']} - -" do not preview results, it will add the file to buffer list -let g:Lf_PreviewResult = { - \ 'File': 0, - \ 'Buffer': 0, - \ 'Mru': 0, - \ 'Tag': 0, - \ 'BufTag': 1, - \ 'Function': 1, - \ 'Line': 0, - \ 'Colorscheme': 0, - \ 'Rg': 0, - \ 'Gtags': 0 - \} - """"""""""""""""""""""""""" vista settings """""""""""""""""""""""""""""""""" let g:vista#renderer#icons = { \ 'member': '', From c4160b6f85c93ad482d91a45f134e22970cb9d36 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 2 Apr 2025 21:30:25 +0200 Subject: [PATCH 109/247] update handling of large files (#396) --- lua/custom-autocmd.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index dba479e7..62b6e7eb 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -228,8 +228,13 @@ api.nvim_create_autocmd("BufReadPre", { if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then vim.o.eventignore = "all" + + -- show ruler + vim.o.ruler = true + -- turning off relative number helps a lot vim.wo.relativenumber = false + vim.wo.number = false vim.bo.swapfile = false vim.bo.bufhidden = "unload" From 9e6be1f00128bc23d4217666c51fdead0763e882 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 2 Apr 2025 21:33:32 +0200 Subject: [PATCH 110/247] update type hints --- lua/utils.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lua/utils.lua b/lua/utils.lua index d77dc1a9..f9963e71 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -3,12 +3,11 @@ local version = vim.version local M = {} +--- Check if an executable exists +--- @param name string An executable name/path +--- @return boolean function M.executable(name) - if fn.executable(name) > 0 then - return true - end - - return false + return fn.executable(name) > 0 end --- check whether a feature exists in Nvim From ad4a0e82dc49d9b019a6fd82dfe953ed01ecbe41 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 2 Apr 2025 21:57:37 +0200 Subject: [PATCH 111/247] Simplify condition check (#397) --- lua/plugin_specs.lua | 64 ++++++++++---------------------------------- 1 file changed, 14 insertions(+), 50 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 5f201bd5..d2025249 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -77,10 +77,7 @@ local plugin_specs = { { "vlime/vlime", enabled = function() - if utils.executable("sbcl") then - return true - end - return false + return utils.executable("sbcl") end, config = function(plugin) vim.opt.rtp:append(plugin.dir .. "/vim") @@ -236,11 +233,7 @@ local plugin_specs = { vim.g.netrw_nogx = 1 -- disable netrw gx end, enabled = function() - if vim.g.is_win or vim.g.is_mac then - return true - else - return false - end + return vim.g.is_win or vim.g.is_mac end, dependencies = { "nvim-lua/plenary.nvim" }, config = true, -- default settings @@ -252,11 +245,7 @@ local plugin_specs = { { "liuchengxu/vista.vim", enabled = function() - if utils.executable("ctags") then - return true - else - return false - end + return utils.executable("ctags") end, cmd = "Vista", }, @@ -302,10 +291,7 @@ local plugin_specs = { { "lyokha/vim-xkbswitch", enabled = function() - if vim.g.is_mac and utils.executable("xkbswitch") then - return true - end - return false + return vim.g.is_mac and utils.executable("xkbswitch") end, event = { "InsertEnter" }, }, @@ -313,10 +299,7 @@ local plugin_specs = { { "Neur1n/neuims", enabled = function() - if vim.g.is_win then - return true - end - return false + return vim.g.is_win end, event = { "InsertEnter" }, }, @@ -365,22 +348,19 @@ local plugin_specs = { }, -- Another markdown plugin - { "preservim/vim-markdown", ft = { "markdown" } }, + -- { "preservim/vim-markdown", ft = { "markdown" } }, -- Faster footnote generation { "vim-pandoc/vim-markdownfootnotes", ft = { "markdown" } }, -- Vim tabular plugin for manipulate tabular, required by markdown plugins - { "godlygeek/tabular", cmd = { "Tabularize" } }, + { "godlygeek/tabular", ft = { "markdown" } }, -- Markdown previewing (only for Mac and Windows) { "iamcco/markdown-preview.nvim", enabled = function() - if vim.g.is_win or vim.g.is_mac then - return true - end - return false + return vim.g.is_win or vim.g.is_mac end, build = "cd app && npm install && git restore .", ft = { "markdown" }, @@ -389,10 +369,7 @@ local plugin_specs = { { "rhysd/vim-grammarous", enabled = function() - if vim.g.is_mac then - return true - end - return false + return vim.g.is_mac end, ft = { "markdown" }, }, @@ -413,10 +390,7 @@ local plugin_specs = { { "lervag/vimtex", enabled = function() - if utils.executable("latex") then - return true - end - return false + return utils.executable("latex") end, ft = { "tex" }, }, @@ -427,10 +401,7 @@ local plugin_specs = { { "tmux-plugins/vim-tmux", enabled = function() - if utils.executable("tmux") then - return true - end - return false + return utils.executable("tmux") end, ft = { "tmux" }, }, @@ -447,8 +418,7 @@ local plugin_specs = { { "glacambre/firenvim", enabled = function() - local result = vim.g.is_win or vim.g.is_mac - return result + return vim.g.is_win or vim.g.is_mac end, -- it seems that we can only call the firenvim function directly. -- Using vim.fn or vim.cmd to call this function will fail. @@ -471,10 +441,7 @@ local plugin_specs = { { "sakhnik/nvim-gdb", enabled = function() - if vim.g.is_win or vim.g.is_linux then - return true - end - return false + return vim.g.is_win or vim.g.is_linux end, build = { "bash install.sh" }, lazy = true, @@ -486,10 +453,7 @@ local plugin_specs = { { "ojroques/vim-oscyank", enabled = function() - if vim.g.is_linux then - return true - end - return false + return vim.g.is_linux end, cmd = { "OSCYank", "OSCYankReg" }, }, From ea2b4a728dd837a4b844cf45de26f3f3251c638e Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 4 Apr 2025 18:16:20 +0200 Subject: [PATCH 112/247] remove plugin vim-markdown (#398) use tree-sitter based markdown render instead. --- lua/plugin_specs.lua | 16 +--------------- viml_conf/plugins.vim | 19 ------------------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index d2025249..7f4281fb 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -115,18 +115,7 @@ local plugin_specs = { -- optional for icon support dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() - require("fzf-lua").setup { - winopts = { - row = 0.5, - height = 0.7, - }, - } - - vim.keymap.set("n", "ff", "FzfLua files", { desc = "Fuzzy find files" }) - vim.keymap.set("n", "fg", "FzfLua live_grep", { desc = "Fuzzy grep files" }) - vim.keymap.set("n", "fh", "FzfLua helptags", { desc = "Fuzzy grep tags in help files" }) - vim.keymap.set("n", "ft", "FzfLua btags", { desc = "Fuzzy search buffer tags" }) - vim.keymap.set("n", "fb", "FzfLua buffers", { desc = "Fuzzy search opened buffers" }) + require("config.fzf-lua") end, }, { @@ -347,9 +336,6 @@ local plugin_specs = { end, }, - -- Another markdown plugin - -- { "preservim/vim-markdown", ft = { "markdown" } }, - -- Faster footnote generation { "vim-pandoc/vim-markdownfootnotes", ft = { "markdown" } }, diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim index cbf8ec4f..70a74467 100644 --- a/viml_conf/plugins.vim +++ b/viml_conf/plugins.vim @@ -72,25 +72,6 @@ let g:neoformat_c_clangformat = { let g:neoformat_enabled_cpp = ['clangformat'] let g:neoformat_enabled_c = ['clangformat'] -"""""""""""""""""""""""""vim-markdown settings""""""""""""""""""" -" Disable header folding -let g:vim_markdown_folding_disabled = 1 - -" Whether to use conceal feature in markdown -let g:vim_markdown_conceal = 1 - -" Disable math tex conceal and syntax highlight -let g:tex_conceal = '' -let g:vim_markdown_math = 0 - -" Support front matter of various format -let g:vim_markdown_frontmatter = 1 " for YAML format -let g:vim_markdown_toml_frontmatter = 1 " for TOML format -let g:vim_markdown_json_frontmatter = 1 " for JSON format - -" Let the TOC window autofit so that it doesn't take too much space -let g:vim_markdown_toc_autofit = 1 - """""""""""""""""""""""""markdown-preview settings""""""""""""""""""" " Only setting this for suitable platforms if g:is_win || g:is_mac From 58261611609ec4b3e134aa42edeb31e8cc01a288 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 4 Apr 2025 18:17:24 +0200 Subject: [PATCH 113/247] move fzf-lua config to separate file --- lua/config/fzf-lua.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lua/config/fzf-lua.lua diff --git a/lua/config/fzf-lua.lua b/lua/config/fzf-lua.lua new file mode 100644 index 00000000..7d818c2f --- /dev/null +++ b/lua/config/fzf-lua.lua @@ -0,0 +1,15 @@ +require("fzf-lua").setup { + winopts = { + row = 0.5, + height = 0.7, + }, + files = { + previewer = false, + }, +} + +vim.keymap.set("n", "ff", "FzfLua files", { desc = "Fuzzy find files" }) +vim.keymap.set("n", "fg", "FzfLua live_grep", { desc = "Fuzzy grep files" }) +vim.keymap.set("n", "fh", "FzfLua helptags", { desc = "Fuzzy grep tags in help files" }) +vim.keymap.set("n", "ft", "FzfLua btags", { desc = "Fuzzy search buffer tags" }) +vim.keymap.set("n", "fb", "FzfLua buffers", { desc = "Fuzzy search opened buffers" }) From aadfdae677af624ecadf46a2e85502b44f93a90a Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 8 Apr 2025 19:11:20 +0200 Subject: [PATCH 114/247] switch from nvim-web-devicons to mini.icons (#399) --- lua/config/fzf-lua.lua | 3 ++ lua/config/nvim-cmp.lua | 31 ++++++++-------- lua/plugin_specs.lua | 79 ++++++++++++++++++++++------------------- 3 files changed, 62 insertions(+), 51 deletions(-) diff --git a/lua/config/fzf-lua.lua b/lua/config/fzf-lua.lua index 7d818c2f..a0cc176c 100644 --- a/lua/config/fzf-lua.lua +++ b/lua/config/fzf-lua.lua @@ -1,4 +1,7 @@ require("fzf-lua").setup { + defaults = { + file_icons = "mini", + }, winopts = { row = 0.5, height = 0.7, diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index 100c77f0..f7f01c47 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -1,6 +1,14 @@ -- Setup nvim-cmp. local cmp = require("cmp") -local lspkind = require("lspkind") + +-- The extentions needed by nvim-cmp should be loaded beforehand +require("cmp_nvim_lsp") +require("cmp_path") +require("cmp_buffer") +require("cmp_omni") +require("cmp_nvim_ultisnips") + +local MiniIcons = require("mini.icons") cmp.setup { snippet = { @@ -43,21 +51,14 @@ cmp.setup { view = { entries = "custom", }, + -- solution taken from https://github.com/echasnovski/mini.nvim/issues/1007#issuecomment-2258929830 formatting = { - format = lspkind.cmp_format { - mode = "symbol_text", - menu = { - nvim_lsp = "[LSP]", - ultisnips = "[US]", - path = "[Path]", - buffer = "[Buffer]", - emoji = "[Emoji]", - omni = "[Omni]", - }, - show_labelDetails = true, - maxwidth = 40, - ellipsis_char = "...", - }, + format = function(_, vim_item) + local icon, hl = MiniIcons.get("lsp", vim_item.kind) + vim_item.kind = icon .. " " .. vim_item.kind + vim_item.kind_hl_group = hl + return vim_item + end, }, } diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 7f4281fb..a63e609a 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -22,24 +22,19 @@ end local plugin_specs = { -- auto-completion engine + { "hrsh7th/cmp-nvim-lsp", lazy = true }, + { "hrsh7th/cmp-path", lazy = true }, + { "hrsh7th/cmp-buffer", lazy = true }, + { "hrsh7th/cmp-omni", lazy = true }, + { "quangnguyen30192/cmp-nvim-ultisnips", lazy = true }, { "hrsh7th/nvim-cmp", name = "nvim-cmp", - -- event = 'InsertEnter', - event = "VeryLazy", - dependencies = { - "hrsh7th/cmp-nvim-lsp", - "onsails/lspkind-nvim", - "hrsh7th/cmp-path", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-omni", - "quangnguyen30192/cmp-nvim-ultisnips", - }, + event = "InsertEnter", config = function() require("config.nvim-cmp") end, }, - { "neovim/nvim-lspconfig", event = { "BufRead", "BufNewFile" }, @@ -56,7 +51,7 @@ local plugin_specs = { }, { "nvim-treesitter/nvim-treesitter", - event = "VeryLazy", + lazy = true, build = ":TSUpdate", config = function() require("config.treesitter") @@ -88,7 +83,7 @@ local plugin_specs = { -- Super fast buffer jump { "smoka7/hop.nvim", - event = "VeryLazy", + keys = { "f" }, config = function() require("config.nvim_hop") end, @@ -112,8 +107,6 @@ local plugin_specs = { }, { "ibhagwan/fzf-lua", - -- optional for icon support - dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() require("config.fzf-lua") end, @@ -122,7 +115,6 @@ local plugin_specs = { "MeanderingProgrammer/markdown.nvim", main = "render-markdown", opts = {}, - dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-tree/nvim-web-devicons" }, }, -- A list of colorscheme plugin you may want to try. Find what suits you. { "navarasu/onedark.nvim", lazy = true }, @@ -141,7 +133,18 @@ local plugin_specs = { branch = "v2", }, { "rebelot/kanagawa.nvim", lazy = true }, - { "nvim-tree/nvim-web-devicons", event = "VeryLazy" }, + + -- plugins to provide nerdfont icons + { + "echasnovski/mini.icons", + version = false, + config = function() + -- this is the compatibility fix for plugins that only support nvim-web-devicons + require("mini.icons").mock_nvim_web_devicons() + require("mini.icons").tweak_lsp_kind() + end, + lazy = true, + }, { "nvim-lualine/lualine.nvim", @@ -171,11 +174,16 @@ local plugin_specs = { }, { - "lukas-reineke/indent-blankline.nvim", - event = "VeryLazy", - main = "ibl", + "echasnovski/mini.indentscope", + version = false, config = function() - require("config.indent-blankline") + local mini_indent = require("mini.indentscope") + mini_indent.setup { + draw = { + animation = mini_indent.gen_animation.none(), + }, + symbol = "▏", + } end, }, { @@ -201,7 +209,7 @@ local plugin_specs = { end, }, -- Highlight URLs inside vim - { "itchyny/vim-highlighturl", event = "VeryLazy" }, + { "itchyny/vim-highlighturl", event = "BufReadPost" }, -- notification plugin { @@ -212,6 +220,8 @@ local plugin_specs = { end, }, + { "nvim-lua/plenary.nvim", lazy = true }, + -- For Windows and Mac, we can open an URL in the browser. For Linux, it may -- not be possible since we maybe in a server which disables GUI. { @@ -224,7 +234,6 @@ local plugin_specs = { enabled = function() return vim.g.is_win or vim.g.is_mac end, - dependencies = { "nvim-lua/plenary.nvim" }, config = true, -- default settings submodules = false, -- not needed, submodules are required only for tests }, @@ -252,7 +261,10 @@ local plugin_specs = { }, -- Comment plugin - { "tpope/vim-commentary", event = "VeryLazy" }, + { "tpope/vim-commentary", keys = { + { "gc", mode = "n" }, + { "gc", mode = "v" }, + } }, -- Multiple cursor plugin like Sublime Text? -- 'mg979/vim-visual-multi' @@ -266,7 +278,7 @@ local plugin_specs = { config = function() require("config.yanky") end, - event = "VeryLazy", + cmd = "YankyRingHistory", }, -- Handy unix command inside Vim (Rename, Move etc.) @@ -360,7 +372,7 @@ local plugin_specs = { ft = { "markdown" }, }, - { "chrisbra/unicode.vim", event = "VeryLazy" }, + { "chrisbra/unicode.vim", keys = { "ga" }, cmd = { "UnicodeSearch" } }, -- Additional powerful text object for vim, this plugin should be studied -- carefully to use its full power @@ -369,9 +381,6 @@ local plugin_specs = { -- Plugin to manipulate character pairs quickly { "machakann/vim-sandwich", event = "VeryLazy" }, - -- Add indent object for vim (useful for languages like Python) - { "michaeljsmith/vim-indent-object", event = "VeryLazy" }, - -- Only use these plugin on Windows and Mac and when LaTeX is installed { "lervag/vimtex", @@ -481,8 +490,7 @@ local plugin_specs = { -- file explorer { "nvim-tree/nvim-tree.lua", - event = "VeryLazy", - dependencies = { "nvim-tree/nvim-web-devicons" }, + keys = { "s" }, config = function() require("config.nvim-tree") end, @@ -490,8 +498,7 @@ local plugin_specs = { { "j-hui/fidget.nvim", - event = "VeryLazy", - tag = "legacy", + event = "BufRead", config = function() require("config.fidget-nvim") end, @@ -511,13 +518,12 @@ local plugin_specs = { "CopilotC-Nvim/CopilotChat.nvim", dependencies = { { "zbirenbaum/copilot.lua" }, -- or github/copilot.vim - { "nvim-lua/plenary.nvim" }, -- for curl, log wrapper }, opts = { debug = true, -- Enable debugging -- See Configuration section for rest }, - -- See Commands section for default commands if you want to lazy load on them + cmd = { "CopilotChat" }, }, { "zbirenbaum/copilot.lua", @@ -534,7 +540,6 @@ local plugin_specs = { config = function() require("config.live-command") end, - event = "VeryLazy", }, { -- show hint for code actions, the user can also implement code actions themselves, @@ -543,9 +548,11 @@ local plugin_specs = { config = function() require("config.lightbulb") end, + event = "VeryLazy", }, { "Bekaboo/dropbar.nvim", + event = "VeryLazy", }, { "catgoose/nvim-colorizer.lua", From adddbc0ba6dde26cc0ed678a2a6cb1a7c8875b84 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 8 Apr 2025 19:13:01 +0200 Subject: [PATCH 115/247] remove indent-blankline and use mini.indentscope --- lua/config/indent-blankline.lua | 36 --------------------------------- 1 file changed, 36 deletions(-) delete mode 100644 lua/config/indent-blankline.lua diff --git a/lua/config/indent-blankline.lua b/lua/config/indent-blankline.lua deleted file mode 100644 index 9b210d7d..00000000 --- a/lua/config/indent-blankline.lua +++ /dev/null @@ -1,36 +0,0 @@ -local api = vim.api - -local exclude_ft = { "help", "git", "markdown", "snippets", "text", "gitconfig", "alpha", "dashboard" } - -require("ibl").setup { - indent = { - -- -- U+2502 may also be a good choice, it will be on the middle of cursor. - -- -- U+250A is also a good choice - char = "▏", - }, - scope = { - show_start = false, - show_end = false, - }, - exclude = { - filetypes = exclude_ft, - buftypes = { "terminal" }, - }, -} - -local gid = api.nvim_create_augroup("indent_blankline", { clear = true }) -api.nvim_create_autocmd("InsertEnter", { - pattern = "*", - group = gid, - command = "IBLDisable", -}) - -api.nvim_create_autocmd("InsertLeave", { - pattern = "*", - group = gid, - callback = function() - if not vim.tbl_contains(exclude_ft, vim.bo.filetype) then - vim.cmd([[IBLEnable]]) - end - end, -}) From e08b17f33551f92e8591075d076729d608523cc1 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 8 Apr 2025 19:35:47 +0200 Subject: [PATCH 116/247] optimize nvim startup time with lazy.nvim (#400) --- lua/plugin_specs.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index a63e609a..d9e0c915 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -110,11 +110,13 @@ local plugin_specs = { config = function() require("config.fzf-lua") end, + event = "VeryLazy", }, { "MeanderingProgrammer/markdown.nvim", main = "render-markdown", opts = {}, + ft = { "markdown" }, }, -- A list of colorscheme plugin you may want to try. Find what suits you. { "navarasu/onedark.nvim", lazy = true }, @@ -148,7 +150,7 @@ local plugin_specs = { { "nvim-lualine/lualine.nvim", - event = "VeryLazy", + event = "BufRead", cond = firenvim_not_active, config = function() require("config.lualine") @@ -334,10 +336,12 @@ local plugin_specs = { config = function() require("config.gitsigns") end, + event = "BufRead", }, { "sindrets/diffview.nvim", + cmd = { "DiffviewOpen" }, }, { @@ -548,7 +552,7 @@ local plugin_specs = { config = function() require("config.lightbulb") end, - event = "VeryLazy", + event = "LspAttach", }, { "Bekaboo/dropbar.nvim", From 510a5501c52848ee688d3fe101a1a1e35410433d Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 11 Apr 2025 21:06:23 +0200 Subject: [PATCH 117/247] update config for git-conflict.nvim (#401) --- lua/config/git-conflict.lua | 12 ++++++++++++ lua/plugin_specs.lua | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lua/config/git-conflict.lua diff --git a/lua/config/git-conflict.lua b/lua/config/git-conflict.lua new file mode 100644 index 00000000..ffcc3854 --- /dev/null +++ b/lua/config/git-conflict.lua @@ -0,0 +1,12 @@ +require("git-conflict").setup {} + +vim.api.nvim_create_autocmd("User", { + pattern = "GitConflictResolved", + callback = function() + -- clear qf list + vim.fn.setqflist({}, "r") + + -- reopen it? + vim.cmd([[GitConflictListQf]]) + end, +}) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index d9e0c915..28c786c3 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -321,7 +321,14 @@ local plugin_specs = { -- Better git log display { "rbong/vim-flog", cmd = { "Flog" } }, - { "akinsho/git-conflict.nvim", version = "*", config = true }, + { + "akinsho/git-conflict.nvim", + version = "*", + event = "VeryLazy", + config = function() + require("config.git-conflict") + end, + }, { "ruifm/gitlinker.nvim", event = "User InGitRepo", From e23d4bb6613f4eb3fa511458feab0a5fb223c0fb Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 11 Apr 2025 21:06:53 +0200 Subject: [PATCH 118/247] use black to format python file --- after/ftplugin/python.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/after/ftplugin/python.vim b/after/ftplugin/python.vim index 7e8b33ba..49563df5 100644 --- a/after/ftplugin/python.vim +++ b/after/ftplugin/python.vim @@ -12,3 +12,5 @@ set tabstop=4 " number of visual spaces per TAB set softtabstop=4 " number of spaces in tab when editing set shiftwidth=4 " number of spaces to use for autoindent set expandtab " expand tab to spaces so that tabs are spaces + +nnoremap f silent !black % From 488ba526446d0c6897998cfce4397c8238a8c5e9 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 22 Apr 2025 17:54:29 +0200 Subject: [PATCH 119/247] use new api vim.lsp.config for lsp configuration (#402) Now nvim-lspconfig serves as ready made configuration for different lsp server configurations. See also related PR in lspconfig: https://github.com/neovim/nvim-lspconfig/pull/3659 --- lua/config/lsp.lua | 59 ++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 42d263f1..1af07ccd 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -1,8 +1,3 @@ -local api = vim.api -local keymap = vim.keymap -local lsp = vim.lsp -local lspconfig = require("lspconfig") - local utils = require("utils") vim.api.nvim_create_autocmd("LspAttach", { @@ -22,7 +17,7 @@ vim.api.nvim_create_autocmd("LspAttach", { opts = opts or {} opts.silent = true opts.buffer = bufnr - keymap.set(mode, l, r, opts) + vim.keymap.set(mode, l, r, opts) end map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) @@ -55,20 +50,20 @@ vim.api.nvim_create_autocmd("LspAttach", { -- The blow command will highlight the current variable and its usages in the buffer. if client.server_capabilities.documentHighlightProvider then - local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true }) - api.nvim_create_autocmd("CursorHold", { + local gid = vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true }) + vim.api.nvim_create_autocmd("CursorHold", { group = gid, buffer = bufnr, callback = function() - lsp.buf.document_highlight() + vim.lsp.buf.document_highlight() end, }) - api.nvim_create_autocmd("CursorMoved", { + vim.api.nvim_create_autocmd("CursorMoved", { group = gid, buffer = bufnr, callback = function() - lsp.buf.clear_references() + vim.lsp.buf.clear_references() end, }) end @@ -108,7 +103,7 @@ if utils.executable("pyright") then } local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability) - lspconfig.pyright.setup { + vim.lsp.config("pyright", { cmd = { "delance-langserver", "--stdio" }, capabilities = merged_capability, settings = { @@ -137,13 +132,15 @@ if utils.executable("pyright") then }, }, }, - } + }) + + vim.lsp.enable("pyright") else vim.notify("pyright not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end if utils.executable("ruff") then - require("lspconfig").ruff.setup { + vim.lsp.config("ruff", { capabilities = capabilities, init_options = { -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/ @@ -151,12 +148,12 @@ if utils.executable("ruff") then organizeImports = true, }, }, - } + }) + vim.lsp.enable("ruff") end if utils.executable("ltex-ls") then - lspconfig.ltex.setup { - cmd = { "ltex-ls" }, + vim.lsp.config("ltex", { filetypes = { "text", "plaintex", "tex", "markdown" }, settings = { ltex = { @@ -164,41 +161,49 @@ if utils.executable("ltex-ls") then }, }, flags = { debounce_text_changes = 300 }, - } + }) + + vim.lsp.enable("ltex") end if utils.executable("clangd") then - lspconfig.clangd.setup { + vim.lsp.config("clangd", { capabilities = capabilities, filetypes = { "c", "cpp", "cc" }, flags = { debounce_text_changes = 500, }, - } + }) + + vim.lsp.enable("clangd") end -- set up vim-language-server if utils.executable("vim-language-server") then - lspconfig.vimls.setup { + vim.lsp.config("vimls", { flags = { debounce_text_changes = 500, }, capabilities = capabilities, - } + }) + + vim.lsp.enable("vimls") else vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end -- set up bash-language-server if utils.executable("bash-language-server") then - lspconfig.bashls.setup { + vim.lsp.config("bashls", { capabilities = capabilities, - } + }) + + vim.lsp.enable("bashls") end -- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/ if utils.executable("lua-language-server") then - lspconfig.lua_ls.setup { + vim.lsp.config("lua_ls", { settings = { Lua = { runtime = { @@ -211,5 +216,7 @@ if utils.executable("lua-language-server") then }, }, capabilities = capabilities, - } + }) + + vim.lsp.enable("lua_ls") end From be862a83d607a1dc7489ba2429891d29ce7d9e3e Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 26 Apr 2025 17:19:46 +0200 Subject: [PATCH 120/247] Use new lsp configuration structure (#403) In this new structure, the main configuration for a LSP server is provided by the plugin nvim-lspconfig. Some of the config may be overridden by the configuration under directory `after/lsp/xxx.lua`, where `xxx` is the lsp server name used by nvim-lspconfig. Note that it is necessary to put the custom lsp server configuration under `after/` directory, in order to correctly override the config provided by nvim-lspconfig. --- after/lsp/bashls.lua | 5 ++ after/lsp/clangd.lua | 9 +++ after/lsp/ltex.lua | 12 +++ after/lsp/lua_ls.lua | 17 +++++ after/lsp/pyright.lua | 56 ++++++++++++++ after/lsp/ruff.lua | 11 +++ after/lsp/vimls.lua | 8 ++ lua/config/lsp.lua | 169 ++++++------------------------------------ lua/lsp_utils.lua | 15 ++++ 9 files changed, 156 insertions(+), 146 deletions(-) create mode 100644 after/lsp/bashls.lua create mode 100644 after/lsp/clangd.lua create mode 100644 after/lsp/ltex.lua create mode 100644 after/lsp/lua_ls.lua create mode 100644 after/lsp/pyright.lua create mode 100644 after/lsp/ruff.lua create mode 100644 after/lsp/vimls.lua create mode 100644 lua/lsp_utils.lua diff --git a/after/lsp/bashls.lua b/after/lsp/bashls.lua new file mode 100644 index 00000000..8aa4921e --- /dev/null +++ b/after/lsp/bashls.lua @@ -0,0 +1,5 @@ +local lsp_utils = require("lsp_utils") + +return { + capabilities = lsp_utils.get_default_capabilities(), +} diff --git a/after/lsp/clangd.lua b/after/lsp/clangd.lua new file mode 100644 index 00000000..189fd958 --- /dev/null +++ b/after/lsp/clangd.lua @@ -0,0 +1,9 @@ +local lsp_utils = require("lsp_utils") + +return { + filetypes = { "c", "cpp", "cc" }, + flags = { + debounce_text_changes = 500, + }, + capabilities = lsp_utils.get_default_capabilities(), +} diff --git a/after/lsp/ltex.lua b/after/lsp/ltex.lua new file mode 100644 index 00000000..e488bc1b --- /dev/null +++ b/after/lsp/ltex.lua @@ -0,0 +1,12 @@ +local lsp_utils = require("lsp_utils") + +return { + filetypes = { "text", "plaintex", "tex", "markdown" }, + settings = { + ltex = { + language = "en", + }, + }, + flags = { debounce_text_changes = 300 }, + capabilities = lsp_utils.get_default_capabilities(), +} diff --git a/after/lsp/lua_ls.lua b/after/lsp/lua_ls.lua new file mode 100644 index 00000000..eae9a949 --- /dev/null +++ b/after/lsp/lua_ls.lua @@ -0,0 +1,17 @@ +local lsp_utils = require("lsp_utils") + +-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/ +return { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + hint = { + enable = true, + }, + }, + }, + capabilities = lsp_utils.get_default_capabilities(), +} diff --git a/after/lsp/pyright.lua b/after/lsp/pyright.lua new file mode 100644 index 00000000..8c5aa328 --- /dev/null +++ b/after/lsp/pyright.lua @@ -0,0 +1,56 @@ +local lsp_utils = require("lsp_utils") + +-- For what diagnostic is enabled in which type checking mode, check doc: +-- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-settings-defaults +-- Currently, the pyright also has some issues displaying hover documentation: +-- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/ + +local new_capability = { + -- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from + -- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482 + textDocument = { + publishDiagnostics = { + tagSupport = { + valueSet = { 2 }, + }, + }, + hover = { + contentFormat = { "plaintext" }, + dynamicRegistration = true, + }, + }, +} + +local capabilities = lsp_utils.get_default_capabilities() +local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability) + +return { + cmd = { "delance-langserver", "--stdio" }, + settings = { + pyright = { + -- disable import sorting and use Ruff for this + disableOrganizeImports = true, + disableTaggedHints = false, + }, + python = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "workspace", + typeCheckingMode = "standard", + useLibraryCodeForTypes = true, + -- we can this setting below to redefine some diagnostics + diagnosticSeverityOverrides = { + deprecateTypingAliases = false, + }, + -- inlay hint settings are provided by pylance? + inlayHints = { + callArgumentNames = "partial", + functionReturnTypes = true, + pytestParameters = true, + variableTypes = true, + }, + }, + }, + }, + capabilities = merged_capability, +} diff --git a/after/lsp/ruff.lua b/after/lsp/ruff.lua new file mode 100644 index 00000000..adf4e98d --- /dev/null +++ b/after/lsp/ruff.lua @@ -0,0 +1,11 @@ +local lsp_utils = require("lsp_utils") + +return { + init_options = { + -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/ + settings = { + organizeImports = true, + }, + }, + capabilities = lsp_utils.get_default_capabilities(), +} diff --git a/after/lsp/vimls.lua b/after/lsp/vimls.lua new file mode 100644 index 00000000..950e44c5 --- /dev/null +++ b/after/lsp/vimls.lua @@ -0,0 +1,8 @@ +local lsp_utils = require("lsp_utils") + +return { + flags = { + debounce_text_changes = 500, + }, + capabilities = lsp_utils.get_default_capabilities(), +} diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 1af07ccd..fcad0a84 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -1,7 +1,7 @@ local utils = require("utils") vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("buf_behavior_conf", { clear = true }), + group = vim.api.nvim_create_augroup("lsp_buf_conf", { clear = true }), callback = function(event_context) local client = vim.lsp.get_client_by_id(event_context.data.client_id) -- vim.print(client.name, client.server_capabilities) @@ -72,151 +72,28 @@ vim.api.nvim_create_autocmd("LspAttach", { desc = "Configure buffer keymap and behavior based on LSP", }) -local capabilities = vim.lsp.protocol.make_client_capabilities() - --- required by nvim-ufo -capabilities.textDocument.foldingRange = { - dynamicRegistration = false, - lineFoldingOnly = true, +-- Enable lsp servers when they are available + +-- A mapping from lsp server name to the executable name +local enabled_lsp_servers = { + pyright = "delance-langserver", + ruff = "ruff", + ltex = "ltex-ls", + clangd = "clangd", + vimls = "vim-language-server", + bashls = "bash-language-server", + lua_ls = "lua-language-server", } --- For what diagnostic is enabled in which type checking mode, check doc: --- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-settings-defaults --- Currently, the pyright also has some issues displaying hover documentation: --- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/ - -if utils.executable("pyright") then - local new_capability = { - -- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from - -- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482 - textDocument = { - publishDiagnostics = { - tagSupport = { - valueSet = { 2 }, - }, - }, - hover = { - contentFormat = { "plaintext" }, - dynamicRegistration = true, - }, - }, - } - local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability) - - vim.lsp.config("pyright", { - cmd = { "delance-langserver", "--stdio" }, - capabilities = merged_capability, - settings = { - pyright = { - -- disable import sorting and use Ruff for this - disableOrganizeImports = true, - disableTaggedHints = false, - }, - python = { - analysis = { - autoSearchPaths = true, - diagnosticMode = "workspace", - typeCheckingMode = "standard", - useLibraryCodeForTypes = true, - -- we can this setting below to redefine some diagnostics - diagnosticSeverityOverrides = { - deprecateTypingAliases = false, - }, - -- inlay hint settings are provided by pylance? - inlayHints = { - callArgumentNames = "partial", - functionReturnTypes = true, - pytestParameters = true, - variableTypes = true, - }, - }, - }, - }, - }) - - vim.lsp.enable("pyright") -else - vim.notify("pyright not found!", vim.log.levels.WARN, { title = "Nvim-config" }) -end - -if utils.executable("ruff") then - vim.lsp.config("ruff", { - capabilities = capabilities, - init_options = { - -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/ - settings = { - organizeImports = true, - }, - }, - }) - vim.lsp.enable("ruff") -end - -if utils.executable("ltex-ls") then - vim.lsp.config("ltex", { - filetypes = { "text", "plaintex", "tex", "markdown" }, - settings = { - ltex = { - language = "en", - }, - }, - flags = { debounce_text_changes = 300 }, - }) - - vim.lsp.enable("ltex") -end - -if utils.executable("clangd") then - vim.lsp.config("clangd", { - capabilities = capabilities, - filetypes = { "c", "cpp", "cc" }, - flags = { - debounce_text_changes = 500, - }, - }) - - vim.lsp.enable("clangd") -end - --- set up vim-language-server -if utils.executable("vim-language-server") then - vim.lsp.config("vimls", { - flags = { - debounce_text_changes = 500, - }, - capabilities = capabilities, - }) - - vim.lsp.enable("vimls") -else - vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" }) -end - --- set up bash-language-server -if utils.executable("bash-language-server") then - vim.lsp.config("bashls", { - capabilities = capabilities, - }) - - vim.lsp.enable("bashls") -end - --- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/ -if utils.executable("lua-language-server") then - vim.lsp.config("lua_ls", { - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - hint = { - enable = true, - }, - }, - }, - capabilities = capabilities, - }) - - vim.lsp.enable("lua_ls") +for server_name, lsp_executable in pairs(enabled_lsp_servers) do + if utils.executable(lsp_executable) then + vim.lsp.enable(server_name) + else + local msg = string.format( + "Executable '%s' for server '%s' not found! Server will not be enabled", + lsp_executable, + server_name + ) + vim.notify(msg, vim.log.levels.WARN, { title = "Nvim-config" }) + end end diff --git a/lua/lsp_utils.lua b/lua/lsp_utils.lua new file mode 100644 index 00000000..4345c3c9 --- /dev/null +++ b/lua/lsp_utils.lua @@ -0,0 +1,15 @@ +local M = {} + +M.get_default_capabilities = function() + local capabilities = vim.lsp.protocol.make_client_capabilities() + + -- required by nvim-ufo + capabilities.textDocument.foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true, + } + + return capabilities +end + +return M From 6c620ecc32b8aa6e8ce05dbf41285519fddd9ee2 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 26 Apr 2025 18:59:25 +0200 Subject: [PATCH 121/247] update the enabled lsp server list --- lua/config/lsp.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index fcad0a84..0db99077 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -78,11 +78,11 @@ vim.api.nvim_create_autocmd("LspAttach", { local enabled_lsp_servers = { pyright = "delance-langserver", ruff = "ruff", - ltex = "ltex-ls", - clangd = "clangd", + lua_ls = "lua-language-server", + -- ltex = "ltex-ls", + -- clangd = "clangd", vimls = "vim-language-server", bashls = "bash-language-server", - lua_ls = "lua-language-server", } for server_name, lsp_executable in pairs(enabled_lsp_servers) do From ba991064b6baf4a78ad6384048410408087a0db6 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 26 Apr 2025 19:00:11 +0200 Subject: [PATCH 122/247] change lualine refresh interval --- lua/config/lualine.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index a9bfdbf9..dfd3bd50 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -210,7 +210,7 @@ require("lualine").setup { disabled_filetypes = {}, always_divide_middle = true, refresh = { - statusline = 500, + statusline = 1000, }, }, sections = { From 88392014500313aa1f16c49e2e34c54217c41ce6 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 26 Apr 2025 21:48:18 +0200 Subject: [PATCH 123/247] upgrade nvim to 0.11.1 (#404) --- README.md | 2 +- init.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a03da8f2..3d905011 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows
- Neovim minimum version + Neovim minimum version Latest release diff --git a/init.lua b/init.lua index 4beead9f..6c63a02d 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.11.0" +local expected_version = "0.11.1" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") From ea23f913b4f67e3ea18ba79b4d946922809a3ce0 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 26 Apr 2025 22:02:48 +0200 Subject: [PATCH 124/247] set default conf for all LSP in one place (#405) --- after/lsp/bashls.lua | 5 ----- after/lsp/clangd.lua | 6 ------ after/lsp/ltex.lua | 4 ---- after/lsp/lua_ls.lua | 3 --- after/lsp/pyright.lua | 7 +------ after/lsp/ruff.lua | 3 --- after/lsp/vimls.lua | 8 -------- lua/config/lsp.lua | 9 +++++++++ 8 files changed, 10 insertions(+), 35 deletions(-) delete mode 100644 after/lsp/bashls.lua delete mode 100644 after/lsp/vimls.lua diff --git a/after/lsp/bashls.lua b/after/lsp/bashls.lua deleted file mode 100644 index 8aa4921e..00000000 --- a/after/lsp/bashls.lua +++ /dev/null @@ -1,5 +0,0 @@ -local lsp_utils = require("lsp_utils") - -return { - capabilities = lsp_utils.get_default_capabilities(), -} diff --git a/after/lsp/clangd.lua b/after/lsp/clangd.lua index 189fd958..96016e7f 100644 --- a/after/lsp/clangd.lua +++ b/after/lsp/clangd.lua @@ -1,9 +1,3 @@ -local lsp_utils = require("lsp_utils") - return { filetypes = { "c", "cpp", "cc" }, - flags = { - debounce_text_changes = 500, - }, - capabilities = lsp_utils.get_default_capabilities(), } diff --git a/after/lsp/ltex.lua b/after/lsp/ltex.lua index e488bc1b..65da2859 100644 --- a/after/lsp/ltex.lua +++ b/after/lsp/ltex.lua @@ -1,5 +1,3 @@ -local lsp_utils = require("lsp_utils") - return { filetypes = { "text", "plaintex", "tex", "markdown" }, settings = { @@ -7,6 +5,4 @@ return { language = "en", }, }, - flags = { debounce_text_changes = 300 }, - capabilities = lsp_utils.get_default_capabilities(), } diff --git a/after/lsp/lua_ls.lua b/after/lsp/lua_ls.lua index eae9a949..382ac7b1 100644 --- a/after/lsp/lua_ls.lua +++ b/after/lsp/lua_ls.lua @@ -1,5 +1,3 @@ -local lsp_utils = require("lsp_utils") - -- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/ return { settings = { @@ -13,5 +11,4 @@ return { }, }, }, - capabilities = lsp_utils.get_default_capabilities(), } diff --git a/after/lsp/pyright.lua b/after/lsp/pyright.lua index 8c5aa328..cd69e82a 100644 --- a/after/lsp/pyright.lua +++ b/after/lsp/pyright.lua @@ -1,5 +1,3 @@ -local lsp_utils = require("lsp_utils") - -- For what diagnostic is enabled in which type checking mode, check doc: -- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-settings-defaults -- Currently, the pyright also has some issues displaying hover documentation: @@ -21,9 +19,6 @@ local new_capability = { }, } -local capabilities = lsp_utils.get_default_capabilities() -local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability) - return { cmd = { "delance-langserver", "--stdio" }, settings = { @@ -52,5 +47,5 @@ return { }, }, }, - capabilities = merged_capability, + capabilities = new_capability, } diff --git a/after/lsp/ruff.lua b/after/lsp/ruff.lua index adf4e98d..49120a9e 100644 --- a/after/lsp/ruff.lua +++ b/after/lsp/ruff.lua @@ -1,5 +1,3 @@ -local lsp_utils = require("lsp_utils") - return { init_options = { -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/ @@ -7,5 +5,4 @@ return { organizeImports = true, }, }, - capabilities = lsp_utils.get_default_capabilities(), } diff --git a/after/lsp/vimls.lua b/after/lsp/vimls.lua deleted file mode 100644 index 950e44c5..00000000 --- a/after/lsp/vimls.lua +++ /dev/null @@ -1,8 +0,0 @@ -local lsp_utils = require("lsp_utils") - -return { - flags = { - debounce_text_changes = 500, - }, - capabilities = lsp_utils.get_default_capabilities(), -} diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 0db99077..34fbdfdd 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -74,6 +74,15 @@ vim.api.nvim_create_autocmd("LspAttach", { -- Enable lsp servers when they are available +local capabilities = require("lsp_utils").get_default_capabilities() + +vim.lsp.config("*", { + capabilities = capabilities, + flags = { + debounce_text_changes = 500, + }, +}) + -- A mapping from lsp server name to the executable name local enabled_lsp_servers = { pyright = "delance-langserver", From b69dcb3a6b3798156636e3432773bdb712a11010 Mon Sep 17 00:00:00 2001 From: Alessandro Zini Date: Wed, 30 Apr 2025 11:00:50 +0200 Subject: [PATCH 125/247] fix neovim link for linux install script (#408) --- docs/nvim_setup_linux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/nvim_setup_linux.sh b/docs/nvim_setup_linux.sh index ed207a45..9d0ec3b6 100755 --- a/docs/nvim_setup_linux.sh +++ b/docs/nvim_setup_linux.sh @@ -221,7 +221,7 @@ fi NVIM_DIR=$HOME/tools/nvim NVIM_SRC_NAME=$HOME/packages/nvim-linux64.tar.gz NVIM_CONFIG_DIR=$HOME/.config/nvim -NVIM_LINK="https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz" +NVIM_LINK="https://github.com/neovim/neovim/releases/download/stable/nvim-linux-x86_64.tar.gz" if [[ ! -f "$NVIM_DIR/bin/nvim" ]]; then echo "Installing Nvim" echo "Creating nvim directory under tools directory" From 999a1733cf693ab78c26eb1e6a2ab74935762997 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 30 Apr 2025 19:01:57 +0200 Subject: [PATCH 126/247] use nvim-cmp for cmd line completion - remove wilder.nvim and its config - add blink.cmp config as backup solution --- README.md | 7 --- lua/config/nvim-cmp.lua | 18 ++++++++ lua/mappings.lua | 2 +- lua/plugin_specs.lua | 96 +++++++++++++++++++++++++++++++++-------- viml_conf/plugins.vim | 46 -------------------- 5 files changed, 98 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 3d905011..f46d6e41 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,6 @@ and how to set up on different platforms (Linux, macOS, and Windows). + File tree explorer via [nvim-tree.lua](https://github.com/nvim-tree/nvim-tree.lua). + Better quickfix list with [nvim-bqf](https://github.com/kevinhwang91/nvim-bqf). + Show search index and count with [nvim-hlslens](https://github.com/kevinhwang91/nvim-hlslens). -+ Command line auto-completion via [wilder.nvim](https://github.com/gelguy/wilder.nvim). + User-defined mapping hint via [which-key.nvim](https://github.com/folke/which-key.nvim). + Asynchronous code execution via [asyncrun.vim](https://github.com/skywind3000/asyncrun.vim). + Code highlighting via [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter). @@ -111,12 +110,6 @@ For more UI demos, check [here](https://github.com/jdhao/nvim-config/issues/15).

-## Command-line autocompletion with wilder.nvim - -

- -

- ## Tags

diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index f7f01c47..b5fc78eb 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -7,6 +7,7 @@ require("cmp_path") require("cmp_buffer") require("cmp_omni") require("cmp_nvim_ultisnips") +require("cmp_cmdline") local MiniIcons = require("mini.icons") @@ -71,6 +72,23 @@ cmp.setup.filetype("tex", { }, }) +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 }, +}) + -- see https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-add-visual-studio-code-dark-theme-colors-to-the-menu vim.cmd([[ highlight! link CmpItemMenu Comment diff --git a/lua/mappings.lua b/lua/mappings.lua index 9915ef5c..f5fb950d 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -104,7 +104,7 @@ keymap.set("n", "v", "printf('`[%s`]', getregtype()[0])", { }) -- Always use very magic mode for searching -keymap.set("n", "/", [[/\v]]) +-- keymap.set("n", "/", [[/\v]]) -- Search in selected region -- xnoremap / :call feedkeys('/\%>'.(line("'<")-1).'l\%<'.(line("'>")+1)."l") diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 28c786c3..c977f610 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -26,15 +26,79 @@ local plugin_specs = { { "hrsh7th/cmp-path", lazy = true }, { "hrsh7th/cmp-buffer", lazy = true }, { "hrsh7th/cmp-omni", lazy = true }, + { "hrsh7th/cmp-cmdline", lazy = true }, { "quangnguyen30192/cmp-nvim-ultisnips", lazy = true }, { "hrsh7th/nvim-cmp", name = "nvim-cmp", - event = "InsertEnter", + event = "VeryLazy", config = function() require("config.nvim-cmp") end, }, + --{ + -- "saghen/blink.cmp", + -- -- optional: provides snippets for the snippet source + -- dependencies = { "rafamadriz/friendly-snippets" }, + + -- -- use a release tag to download pre-built binaries + -- version = "1.*", + + -- ---@module 'blink.cmp' + -- ---@type blink.cmp.Config + -- opts = { + -- -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept) + -- -- 'super-tab' for mappings similar to vscode (tab to accept) + -- -- 'enter' for enter to accept + -- -- 'none' for no mappings + -- -- + -- keymap = { + -- preset = "default", + -- [""] = { "select_next", "fallback" }, + -- [""] = { "select_prev", "fallback" }, + -- [""] = { "select_and_accept", "fallback" }, + -- [""] = { "scroll_documentation_up", "fallback" }, + -- [""] = { "scroll_documentation_down", "fallback" }, + -- }, + + -- appearance = { + -- -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- -- Adjusts spacing to ensure icons are aligned + -- nerd_font_variant = "mono", + -- }, + + -- -- (Default) Only show the documentation popup when manually triggered + -- completion = { + -- documentation = { + -- auto_show = true, + -- }, + -- }, + + -- -- Default list of enabled providers defined so that you can extend it + -- -- elsewhere in your config, without redefining it, due to `opts_extend` + -- sources = { + -- default = { "lsp", "path", "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" }, + -- cmdline = { + -- completion = { + -- menu = { + -- auto_show = true, + -- }, + -- }, + -- keymap = { + -- [""] = { "select_and_accept", "fallback" }, + -- }, + -- }, + -- }, + -- opts_extend = { "sources.default" }, + --}, { "neovim/nvim-lspconfig", event = { "BufRead", "BufNewFile" }, @@ -251,9 +315,13 @@ local plugin_specs = { }, -- Snippet engine and snippet template - { "SirVer/ultisnips", dependencies = { - "honza/vim-snippets", - }, event = "InsertEnter" }, + { + "SirVer/ultisnips", + dependencies = { + "honza/vim-snippets", + }, + event = "InsertEnter", + }, -- Automatic insertion and deletion of a pair of characters { @@ -263,10 +331,13 @@ local plugin_specs = { }, -- Comment plugin - { "tpope/vim-commentary", keys = { - { "gc", mode = "n" }, - { "gc", mode = "v" }, - } }, + { + "tpope/vim-commentary", + keys = { + { "gc", mode = "n" }, + { "gc", mode = "v" }, + }, + }, -- Multiple cursor plugin like Sublime Text? -- 'mg979/vim-visual-multi' @@ -307,9 +378,6 @@ local plugin_specs = { event = { "InsertEnter" }, }, - -- Auto format tools - { "sbdchd/neoformat", cmd = { "Neoformat" } }, - -- Git command inside vim { "tpope/vim-fugitive", @@ -464,12 +532,6 @@ local plugin_specs = { cmd = { "OSCYank", "OSCYankReg" }, }, - -- The missing auto-completion for cmdline! - { - "gelguy/wilder.nvim", - build = ":UpdateRemotePlugins", - }, - -- showing keybindings { "folke/which-key.nvim", diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim index 70a74467..2f4bbf82 100644 --- a/viml_conf/plugins.vim +++ b/viml_conf/plugins.vim @@ -240,49 +240,3 @@ endif """"""""""""""""""""""""""""""nvim-gdb settings"""""""""""""""""""""""""""""" nnoremap dp :GdbStartPDB python -m pdb % - -""""""""""""""""""""""""""""""wilder.nvim settings"""""""""""""""""""""""""""""" -call timer_start(250, { -> s:wilder_init() }) - -function! s:wilder_init() abort - try - call wilder#setup({ - \ 'modes': [':', '/', '?'], - \ 'next_key': '', - \ 'previous_key': '', - \ 'accept_key': '', - \ 'reject_key': '' - \ }) - - call wilder#set_option('pipeline', [ - \ wilder#branch( - \ wilder#cmdline_pipeline({ - \ 'language': 'python', - \ 'fuzzy': 1, - \ 'sorter': wilder#python_difflib_sorter(), - \ 'debounce': 30, - \ }), - \ wilder#python_search_pipeline({ - \ 'pattern': wilder#python_fuzzy_pattern(), - \ 'sorter': wilder#python_difflib_sorter(), - \ 'engine': 're', - \ 'debounce': 30, - \ }), - \ ), - \ ]) - - let l:hl = wilder#make_hl('WilderAccent', 'Pmenu', [{}, {}, {'foreground': '#f4468f'}]) - call wilder#set_option('renderer', wilder#popupmenu_renderer({ - \ 'highlighter': wilder#basic_highlighter(), - \ 'max_height': 15, - \ 'highlights': { - \ 'accent': l:hl, - \ }, - \ 'left': [' ', wilder#popupmenu_devicons(),], - \ 'right': [' ', wilder#popupmenu_scrollbar(),], - \ 'apply_incsearch_fix': 0, - \ })) - catch /^Vim\%((\a\+)\)\=:E117/ - echohl Error |echomsg "Wilder.nvim missing"| echohl None - endtry -endfunction From 3b964c3d1f6bf9048f24da43e529c4086d975c7c Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 30 Apr 2025 19:04:44 +0200 Subject: [PATCH 127/247] remove format mapping for lsp --- lua/config/lsp.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 34fbdfdd..2d6c187f 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -35,10 +35,6 @@ vim.api.nvim_create_autocmd("LspAttach", { end, { desc = "list workspace folder" }) -- Set some key bindings conditional on server capabilities - if client.server_capabilities.documentFormattingProvider and client.name ~= "lua_ls" then - map({ "n", "x" }, "f", vim.lsp.buf.format, { desc = "format code" }) - end - -- Disable ruff hover feature in favor of Pyright if client.name == "ruff" then client.server_capabilities.hoverProvider = false From 30b3c09dda1e84f6df254796d3b058e9e0b207d8 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 30 Apr 2025 19:07:07 +0200 Subject: [PATCH 128/247] update readme --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index f46d6e41..636c58e6 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,6 @@ Neovim minimum version - - Latest release - Top languages From 082111fa4eb86a307e489a2e9e3d14c1250b1127 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 13 May 2025 18:15:08 +0200 Subject: [PATCH 129/247] update LSP config (#410) --- lua/config/lsp.lua | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 2d6c187f..41c48c99 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -20,7 +20,45 @@ vim.api.nvim_create_autocmd("LspAttach", { vim.keymap.set(mode, l, r, opts) end - map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) + map("n", "gd", function() + vim.lsp.buf.definition { + on_list = function(options) + -- custom logic to avoid showing multiple definition when you use this style of code: + -- `local M.my_fn_name = function() ... end`. + -- See also post here: https://www.reddit.com/r/neovim/comments/19cvgtp/any_way_to_remove_redundant_definition_in_lua_file/ + + -- vim.print(options.items) + local unique_defs = {} + local def_loc_hash = {} + + -- each item in options.items contain the location info for a definition provided by LSP server + for _, def_location in pairs(options.items) do + -- use filename and line number to uniquelly indentify a definition, + -- we do not expect/want multiple definition in single line! + local hash_key = def_location.filename .. def_location.lnum + + if not def_loc_hash[hash_key] then + def_loc_hash[hash_key] = true + table.insert(unique_defs, def_location) + end + end + + options.items = unique_defs + + -- set the location list + ---@diagnostic disable-next-line: param-type-mismatch + vim.fn.setloclist(0, {}, " ", options) + + -- open the location list when we have more than 1 definitions found, + -- otherwise, jump directly to the definition + if #options.items > 1 then + vim.cmd.lopen() + else + vim.cmd([[silent! lfirst]]) + end + end, + } + end, { desc = "go to definition" }) map("n", "", vim.lsp.buf.definition) map("n", "K", function() vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 } @@ -88,6 +126,7 @@ local enabled_lsp_servers = { -- clangd = "clangd", vimls = "vim-language-server", bashls = "bash-language-server", + yamlls = "yaml-language-server", } for server_name, lsp_executable in pairs(enabled_lsp_servers) do From ec557001af0d13970f33ef248db4756a18025d99 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 2 Jun 2025 23:25:06 +0200 Subject: [PATCH 130/247] bump supported nvim version to 0.11.2 (#412) --- README.md | 2 +- init.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 636c58e6..abb571bf 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows - Neovim minimum version + Neovim minimum version Top languages diff --git a/init.lua b/init.lua index 6c63a02d..f12d2c93 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.11.1" +local expected_version = "0.11.2" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") From 6c10223062be17a5cb0fc3417359b00722ba155e Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 3 Jun 2025 12:36:50 +0200 Subject: [PATCH 131/247] change kanagawa theme variant --- lua/colorschemes.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 2365e5cd..cfeb2bc3 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -59,7 +59,7 @@ M.colorscheme_conf = { vim.cmd("colorscheme arctic") end, kanagawa = function() - vim.cmd("colorscheme kanagawa-wave") + vim.cmd("colorscheme kanagawa-dragon") end, } From 448f2394fe393cc1514bf8ef3e742ce7f56f9fd1 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 3 Jun 2025 13:22:02 +0200 Subject: [PATCH 132/247] Add new bunch of colorschemes (#413) --- lua/colorschemes.lua | 28 ++++++++++++++++++++++++++++ lua/plugin_specs.lua | 9 +++++++++ 2 files changed, 37 insertions(+) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index cfeb2bc3..465047bd 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -61,6 +61,34 @@ M.colorscheme_conf = { kanagawa = function() vim.cmd("colorscheme kanagawa-dragon") end, + modus = function() + vim.cmd([[colorscheme modus]]) + end, + jellybeans = function() + vim.cmd([[colorscheme jellybeans]]) + end, + github = function() + vim.cmd([[colorscheme github_dark_default]]) + end, + e_ink = function() + require("e-ink").setup() + vim.cmd.colorscheme("e-ink") + end, + ashen = function() + vim.cmd([[colorscheme ashen]]) + end, + melange = function() + vim.cmd([[colorscheme melange]]) + end, + makurai = function() + vim.cmd.colorscheme("makurai_warrior") + end, + vague = function() + vim.cmd([[colorscheme vague]]) + end, + kanso = function() + vim.cmd([[colorscheme kanso]]) + end, } --- Use a random colorscheme from the pre-defined list of colorschemes. diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index c977f610..7a7a7fb7 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -199,6 +199,15 @@ local plugin_specs = { branch = "v2", }, { "rebelot/kanagawa.nvim", lazy = true }, + { "miikanissi/modus-themes.nvim", priority = 1000 }, + { "wtfox/jellybeans.nvim", priority = 1000 }, + { "projekt0n/github-nvim-theme", name = "github-theme" }, + { "e-ink-colorscheme/e-ink.nvim", priority = 1000 }, + { "ficcdaf/ashen.nvim", priority = 1000 }, + { "savq/melange-nvim", priority = 1000 }, + { "Skardyy/makurai-nvim", priority = 1000 }, + { "vague2k/vague.nvim", priority = 1000 }, + { "webhooked/kanso.nvim", priority = 1000 }, -- plugins to provide nerdfont icons { From 88044b252e383edb290b808d9d5faaed39bb16e0 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 5 Jun 2025 00:51:10 +0200 Subject: [PATCH 133/247] add new colorscheme citruszest (#414) --- lua/colorschemes.lua | 3 +++ lua/plugin_specs.lua | 1 + 2 files changed, 4 insertions(+) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 465047bd..06f5d3fe 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -89,6 +89,9 @@ M.colorscheme_conf = { kanso = function() vim.cmd([[colorscheme kanso]]) end, + citruszest = function() + vim.cmd([[colorscheme citruszest]]) + end, } --- Use a random colorscheme from the pre-defined list of colorschemes. diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 7a7a7fb7..0f929d8e 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -208,6 +208,7 @@ local plugin_specs = { { "Skardyy/makurai-nvim", priority = 1000 }, { "vague2k/vague.nvim", priority = 1000 }, { "webhooked/kanso.nvim", priority = 1000 }, + { "zootedb0t/citruszest.nvim", priority = 1000 }, -- plugins to provide nerdfont icons { From 6e6a09e32f9653d6754842785ffa4d9d5730bb71 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 7 Jun 2025 19:12:01 +0200 Subject: [PATCH 134/247] Add support for markdown ref-style link (#415) --- after/ftplugin/markdown.lua | 107 ++++++++++++++++++++++++++++++++++ my_snippets/markdown.snippets | 4 ++ 2 files changed, 111 insertions(+) create mode 100644 after/ftplugin/markdown.lua diff --git a/after/ftplugin/markdown.lua b/after/ftplugin/markdown.lua new file mode 100644 index 00000000..662bbeaf --- /dev/null +++ b/after/ftplugin/markdown.lua @@ -0,0 +1,107 @@ +local function add_reference_at_end(label, url, title) + vim.schedule(function() + local bufnr = vim.api.nvim_get_current_buf() + local line_count = vim.api.nvim_buf_line_count(bufnr) + + -- Prepare reference definition + local ref_def = "[" .. label .. "]: " .. url + if title and title ~= "" then + ref_def = ref_def .. ' "' .. title .. '"' + end + + -- Check if references section exists + local buffer_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) + + local has_ref_section = false + for _, line in ipairs(buffer_lines) do + if line:match("^%s*[%s]*$") then + has_ref_section = true + break + end + end + + local lines_to_add = {} + -- Add references header if it doesn't exist + if not has_ref_section then + if #lines_to_add == 0 then + table.insert(lines_to_add, "") + end + table.insert(lines_to_add, "") + end + + table.insert(lines_to_add, ref_def) + + -- Insert at buffer end + vim.api.nvim_buf_set_lines(bufnr, line_count, line_count, false, lines_to_add) + end) +end + +local function get_ref_link_labels() + local labels = {} + local seen = {} -- To avoid duplicates + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + + for _, line in ipairs(lines) do + -- Pattern explanation: + -- %[.-%] matches [link text] (non-greedy) + -- %[(.-)%] matches [label] and captures the label content + local start_pos = 1 + while start_pos <= #line do + local match_start, match_end, label = string.find(line, "%[.-%]%[(.-)%]", start_pos) + if not match_start then + break + end + + -- Only add unique labels + if label and label ~= "" and not seen[label] then + table.insert(labels, label) + seen[label] = true + end + + start_pos = match_end + 1 + end + end + + return labels +end + +local function count_consecutive_spaces(str) + -- Remove leading spaces first + local trimmed = str:match("^%s*(.*)") + local count = 0 + + -- Count each sequence of one or more consecutive spaces + for spaces in trimmed:gmatch("%s+") do + count = count + 1 + end + return count +end + +vim.api.nvim_buf_create_user_command(0, "AddRef", function(opts) + local args = vim.split(opts.args, " ", { trimempty = true }) + + if #args < 2 then + vim.print("Usage: :AddRef License + + deepwiki +

From a872921029c295672748e056f15fdaa1832dce76 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 20 Jul 2025 08:32:37 +0200 Subject: [PATCH 142/247] bump supported nvim version --- README.md | 2 +- init.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a5a9fc0e..0ef2f157 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows - Neovim minimum version + Neovim minimum version Top languages diff --git a/init.lua b/init.lua index f12d2c93..822b2b06 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.11.2" +local expected_version = "0.11.3" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") From 3dfb4d1ab14d5b5f2dd3a1af74891b45b9ff6268 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 Aug 2025 20:08:34 +0200 Subject: [PATCH 143/247] update plugin specs (#425) - pin gitsigns to stable version, to avoid https://github.com/lewis6991/gitsigns.nvim/issues/1381 - add plugin quicker.nvim --- lua/plugin_specs.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index fe1425b8..9c6209c9 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -379,6 +379,7 @@ local plugin_specs = { require("config.gitsigns") end, event = "BufRead", + version = "*", }, { @@ -600,6 +601,13 @@ local plugin_specs = { opts = { -- set to setup table }, }, + { + "stevearc/quicker.nvim", + event = "FileType qf", + ---@module "quicker" + ---@type quicker.SetupOptions + opts = {}, + }, } ---@diagnostic disable-next-line: missing-fields From 63791b1990afb8e9bf110921730169b31619188c Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 Aug 2025 20:12:22 +0200 Subject: [PATCH 144/247] fix colorscheme name for makurai --- lua/colorschemes.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 06f5d3fe..2734856a 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -81,7 +81,7 @@ M.colorscheme_conf = { vim.cmd([[colorscheme melange]]) end, makurai = function() - vim.cmd.colorscheme("makurai_warrior") + vim.cmd.colorscheme("makurai_dark") end, vague = function() vim.cmd([[colorscheme vague]]) From c1990d95096b67ebc1cfb02ef9289a4ede93fb93 Mon Sep 17 00:00:00 2001 From: Ruben De Raeve <91075917+rubenderaeve@users.noreply.github.com> Date: Mon, 18 Aug 2025 23:02:16 +0200 Subject: [PATCH 145/247] [fzf-lua] fix recently opened files (#427) refs [issue 426](https://github.com/jdhao/nvim-config/issues/426) --- lua/config/fzf-lua.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/config/fzf-lua.lua b/lua/config/fzf-lua.lua index a0cc176c..2ed01088 100644 --- a/lua/config/fzf-lua.lua +++ b/lua/config/fzf-lua.lua @@ -16,3 +16,4 @@ vim.keymap.set("n", "fg", "FzfLua live_grep", { desc = "Fuzzy g vim.keymap.set("n", "fh", "FzfLua helptags", { desc = "Fuzzy grep tags in help files" }) vim.keymap.set("n", "ft", "FzfLua btags", { desc = "Fuzzy search buffer tags" }) vim.keymap.set("n", "fb", "FzfLua buffers", { desc = "Fuzzy search opened buffers" }) +vim.keymap.set("n", "fr", "FzfLua oldfiles", { desc = "Fuzzy search opened files history" }) From 0ee09b06456b84fddc6f6010cb22ebc67ed94aa4 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 24 Aug 2025 22:26:14 +0200 Subject: [PATCH 146/247] Map the feature of q in normal mode to Q (#430) --- lua/mappings.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/mappings.lua b/lua/mappings.lua index f5fb950d..1d1ff99c 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -233,3 +233,10 @@ keymap.set("n", "cb", function() end) ) end, { desc = "show cursor" }) + +keymap.set("n", "q", function() + vim.print("q is remapped to Q in Normal mode!") +end) +keymap.set("n", "Q", "q", { + desc = "Record macro", +}) From 9d7d356ff7ee409940f513e157a75f1d2bf9ac42 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 25 Aug 2025 21:40:03 +0200 Subject: [PATCH 147/247] update diffopt to include inline diff (#432) --- viml_conf/options.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/viml_conf/options.vim b/viml_conf/options.vim index 08d984bd..a046e6be 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -178,7 +178,13 @@ set diffopt+=filler " show filler for deleted lines set diffopt+=closeoff " turn off diff when one file window is closed set diffopt+=context:3 " context for diff set diffopt+=internal,indent-heuristic,algorithm:histogram -set diffopt+=linematch:60 +" inline diff makes changes in a line more noticeable, the author suggests to +" remove linematch option if you use inline option, see also https://www.reddit.com/r/neovim/comments/1myfvla/comment/najy4s3/ +if has('nvim-0.12') + set diffopt+=inline:char +else + set diffopt+=linematch:60 +endif set nowrap " do no wrap set noruler From d41c48aa11df4de99fab6323e33c82f101062ce5 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 28 Aug 2025 21:32:47 +0200 Subject: [PATCH 148/247] feat: close float win more easily when not needed (#433) --- lua/config/lsp.lua | 7 ++++++- lua/diagnostic-conf.lua | 5 ++++- lua/mappings.lua | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 41c48c99..96d300e6 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -61,7 +61,12 @@ vim.api.nvim_create_autocmd("LspAttach", { end, { desc = "go to definition" }) map("n", "", vim.lsp.buf.definition) map("n", "K", function() - vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 } + vim.lsp.buf.hover { + border = "single", + max_height = 20, + max_width = 130, + close_events = { "CursorMoved", "BufLeave", "WinLeave", "LSPDetach" }, + } end) map("n", "", vim.lsp.buf.signature_help) map("n", "rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) diff --git a/lua/diagnostic-conf.lua b/lua/diagnostic-conf.lua index e50a4be9..f5558fcb 100644 --- a/lua/diagnostic-conf.lua +++ b/lua/diagnostic-conf.lua @@ -20,6 +20,9 @@ diagnostic.config { header = "Diagnostics:", prefix = " ", border = "single", + max_height = 10, + max_width = 130, + close_events = { "CursorMoved", "BufLeave", "WinLeave" }, }, } @@ -58,7 +61,7 @@ api.nvim_create_autocmd("CursorHold", { local cursor_pos = api.nvim_win_get_cursor(0) if not vim.deep_equal(cursor_pos, vim.b.diagnostics_pos) then - diagnostic.open_float { width = 100 } + diagnostic.open_float {} end vim.b.diagnostics_pos = cursor_pos diff --git a/lua/mappings.lua b/lua/mappings.lua index 1d1ff99c..940019d0 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -240,3 +240,9 @@ end) keymap.set("n", "Q", "q", { desc = "Record macro", }) + +keymap.set("n", "", function() + vim.cmd("fclose!") +end, { + desc = "close floating win", +}) From 2f5eb885b8a7549abe458294a2497f3f5e9326d4 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 30 Aug 2025 23:21:13 +0200 Subject: [PATCH 149/247] change mini.nvim organization (#434) --- lua/plugin_specs.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 9c6209c9..8f1c379d 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -159,7 +159,7 @@ local plugin_specs = { -- plugins to provide nerdfont icons { - "echasnovski/mini.icons", + "nvim-mini/mini.icons", version = false, config = function() -- this is the compatibility fix for plugins that only support nvim-web-devicons @@ -197,7 +197,7 @@ local plugin_specs = { }, { - "echasnovski/mini.indentscope", + "nvim-mini/mini.indentscope", version = false, config = function() local mini_indent = require("mini.indentscope") From b243644d36ceaa08c9a5cc5b351a3858227d9d7a Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 1 Sep 2025 22:15:43 +0200 Subject: [PATCH 150/247] Bump supported nvim version to 0.11.4 (#435) --- README.md | 2 +- init.lua | 2 +- lua/globals.lua | 15 --------------- 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 0ef2f157..5e6f8a45 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows - Neovim minimum version + Neovim minimum version Top languages diff --git a/init.lua b/init.lua index 822b2b06..0e44a979 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.11.3" +local expected_version = "0.11.4" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") diff --git a/lua/globals.lua b/lua/globals.lua index d1a06a76..862afac0 100644 --- a/lua/globals.lua +++ b/lua/globals.lua @@ -1,6 +1,3 @@ -local fn = vim.fn -local api = vim.api - local utils = require("utils") ------------------------------------------------------------------------ @@ -20,18 +17,6 @@ vim.g.loaded_ruby_provider = 0 -- Disable ruby provider vim.g.loaded_node_provider = 0 -- Disable node provider vim.g.did_install_default_menus = 1 -- do not load menu -if utils.executable("python3") then - if vim.g.is_win then - vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", "", "g") - else - vim.g.python3_host_prog = fn.exepath("python3") - end -else - local msg = "Python3 executable not found! You must install Python3 and set its PATH correctly!" - api.nvim_echo({ { msg } }, true, { err = true }) - return -end - -- Custom mapping (see `:h mapleader` for more info) vim.g.mapleader = "," From 6e3621ab764f2f6edd7846d492d28a9a8240bdbf Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 14 Sep 2025 20:49:54 +0200 Subject: [PATCH 151/247] use colorscheme cmd as function (#438) --- lua/colorschemes.lua | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 2734856a..8cf1a3e4 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -3,6 +3,8 @@ local utils = require("utils") local M = {} +local use_theme = vim.cmd.colorscheme + -- Colorscheme to its directory name mapping, because colorscheme repo name is not necessarily -- the same as the colorscheme name itself. M.colorscheme_conf = { @@ -18,13 +20,13 @@ M.colorscheme_conf = { vim.g.edge_enable_italic = 1 vim.g.edge_better_performance = 1 - vim.cmd([[colorscheme edge]]) + use_theme("edge") end, sonokai = function() vim.g.sonokai_enable_italic = 1 vim.g.sonokai_better_performance = 1 - vim.cmd([[colorscheme sonokai]]) + use_theme("sonokai") end, gruvbox_material = function() -- foreground option can be material, mix, or original @@ -34,63 +36,63 @@ M.colorscheme_conf = { vim.g.gruvbox_material_enable_italic = 1 vim.g.gruvbox_material_better_performance = 1 - vim.cmd([[colorscheme gruvbox-material]]) + use_theme("gruvbox-material") end, everforest = function() vim.g.everforest_background = "hard" vim.g.everforest_enable_italic = 1 vim.g.everforest_better_performance = 1 - vim.cmd([[colorscheme everforest]]) + use_theme("everforest") end, nightfox = function() - vim.cmd([[colorscheme carbonfox]]) + use_theme("carbonfox") end, onedarkpro = function() -- set colorscheme after options -- onedark_vivid does not enough contrast - vim.cmd("colorscheme onedark_dark") + use_theme("onedark_dark") end, material = function() vim.g.material_style = "darker" - vim.cmd("colorscheme material") + use_theme("material") end, arctic = function() - vim.cmd("colorscheme arctic") + use_theme("arctic") end, kanagawa = function() - vim.cmd("colorscheme kanagawa-dragon") + use_theme("kanagawa-dragon") end, modus = function() - vim.cmd([[colorscheme modus]]) + use_theme("modus") end, jellybeans = function() - vim.cmd([[colorscheme jellybeans]]) + use_theme("jellybeans") end, github = function() - vim.cmd([[colorscheme github_dark_default]]) + use_theme("github_dark_default") end, e_ink = function() require("e-ink").setup() - vim.cmd.colorscheme("e-ink") + use_theme("e-ink") end, ashen = function() - vim.cmd([[colorscheme ashen]]) + use_theme("ashen") end, melange = function() - vim.cmd([[colorscheme melange]]) + use_theme("melange") end, makurai = function() - vim.cmd.colorscheme("makurai_dark") + use_theme("makurai_dark") end, vague = function() - vim.cmd([[colorscheme vague]]) + use_theme("vague") end, kanso = function() - vim.cmd([[colorscheme kanso]]) + use_theme("kanso") end, citruszest = function() - vim.cmd([[colorscheme citruszest]]) + use_theme("citruszest") end, } From 0fd25e214d225ec090576b1bbf95e4f7fc02bd15 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 14 Sep 2025 20:51:56 +0200 Subject: [PATCH 152/247] Use new labubu icon for dashboard (#439) --- lua/config/dashboard-nvim.lua | 68 ++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/lua/config/dashboard-nvim.lua b/lua/config/dashboard-nvim.lua index fd921717..f5e55056 100644 --- a/lua/config/dashboard-nvim.lua +++ b/lua/config/dashboard-nvim.lua @@ -3,20 +3,62 @@ local keymap = vim.keymap local dashboard = require("dashboard") local conf = {} +-- conf.header = { +-- " ", +-- " ", +-- " ", +-- " ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗", +-- " ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║", +-- " ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║", +-- " ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║", +-- " ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║", +-- " ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝", +-- " ", +-- " ", +-- " ", +-- " ", +-- } + conf.header = { - " ", - " ", - " ", - " ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗", - " ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║", - " ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║", - " ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║", - " ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║", - " ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝", - " ", - " ", - " ", - " ", + " ", + " ", + " ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣿⣦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣨⣿⣿⠿⠻⣿⡀⠀⠀⠀⣠⣾⡟⢹⣶⣦⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⣿⠋⠀⢠⣿⣧⠀⠀⣴⣿⣿⣿⡟⠉⢿⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⡟⠀⣤⠉⣿⣿⠀⢠⣿⣿⣿⡟⠀⠀⢸⣿⣟⠂⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣺⣿⣿⠀⣰⣿⠀⣿⣿⠀⣾⣿⣿⡟⠀⣠⡄⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⠃⠀⣿⡏⢠⣿⣿⣤⣿⣿⣿⠁⢸⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣀⣼⣿⣷⣿⡿⣿⠿⠿⣿⣧⣠⣿⣿⢁⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⡿⣽⣿⣷⣶⡋⠂⠀⣊⠀⢉⠽⠻⢿⣿⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⢠⣞⣹⡿⣿⣿⣿⣿⣻⣿⣷⣧⣰⡀⠉⠀⢀⡠⠎⠩⣭⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⢠⠄⣰⠟⣻⣿⡿⢿⣿⣿⣿⣿⣷⣿⣿⣿⡇⠀⡙⣻⣦⠀⢸⣖⠒⠺⣷⡀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠠⠃⢸⣷⡿⠋⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣾⣿⡿⣿⣷⣏⠉⢛⣀⣼⡇⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⢠⣶⡟⢉⣴⣿⣿⣿⣿⣿⣿⣿⡿⠛⠛⠋⠉⠛⠻⢿⣿⣿⣽⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀", + "⠀⠀⠀⢰⡿⢟⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠙⠻⣿⣿⣽⣿⣷⠀⠀⠀⠀", + "⠀⠀⠀⡼⣷⣿⡟⣿⣿⣿⣿⣿⡟⠀⠀⠀⣀⠖⠰⢦⠤⠤⠀⠀⠀⠀⠀⠀⠀⢀⡸⣿⣿⣻⣿⣧⠀⠀⠀", + "⠀⠀⠀⢱⣿⣿⣿⣿⣿⣿⣿⣟⠀⠀⠀⢠⠏⠀⣾⡿⣷⡀⠀⠀⠀⠀⡾⠋⣩⡍⠁⢸⣿⣿⣻⣿⠀⠀⠀", + "⠀⠀⠀⡿⣿⣿⣿⣿⣿⣿⣿⣿⠰⡀⠀⢸⠀⢸⣿⣿⣿⠃⠀⠀⠀⢸⠃⢰⣿⣿⠀⢸⣿⣿⣿⣿⠄⠀⠀", + "⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⡇⠻⣄⠈⢧⠈⠿⠿⠋⠀⢠⣶⣤⣬⠀⢸⣿⡏⠀⢸⣿⣿⣿⠃⠀⠀⠀", + "⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣦⡈⠳⣄⡀⠀⠀⠀⠀⠀⠙⠉⠀⠁⠘⠛⢁⣰⣿⣿⣿⣿⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⣉⡳⠶⠤⣤⣀⣀⣀⣀⣀⣤⣶⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠉⠻⣿⣿⣿⣿⣍⣿⣿⣿⣿⣿⣿⣶⣶⣶⣿⣿⣿⣷⣾⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣤⣄⣀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⢰⣤⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢧⢄⠀⠀", + "⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⣿⣿⡗⢤⢤⠾⠀", + "⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣽⣿⣿⣿⣿⣿⣿⣿⣿⠟⠀⠀⠀", + "⠀⠀⠀⠀⣸⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⠻⠟⠋⠁⠀⠀⠀⠀", + "⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⢀⣴⣟⠁⢸⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀", + "⢠⡾⠟⠛⠙⠳⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠰⢆⡀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⢀⣀⡉⢓⣦⣠⣴⠾⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠰⣤⣥⣼⣿⣿⡏⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠄⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠘⠹⠛⠻⠛⠃⣾⣿⣿⡿⣿⣿⣿⣿⣿⣿⣿⣟⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⣀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠋⠋⠙⣿⠻⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⣿⣯⣥⣤⣬⣽⡿⢻⣿⡏⡂⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠏⠛⠻⠿⡿⣿⡟⢺⣿⣿⡿⠛⠛⢃⣘⠛⠛⠟⠛⠛⠻⢿⢿⠏⠙⠜⣷⢞⠂", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠆⠀⠀⠀⠁⠈⠁⢨⠭⣉⠀⠀⠀⢈⠁⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀", + " ", + " ", } conf.center = { From 360513d3b7ef268c42450081f33917f934a3de1a Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 24 Sep 2025 21:30:40 +0200 Subject: [PATCH 153/247] update url for plugin render-markdown --- lua/plugin_specs.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 8f1c379d..3e4477d0 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -124,7 +124,7 @@ local plugin_specs = { event = "VeryLazy", }, { - "MeanderingProgrammer/markdown.nvim", + "MeanderingProgrammer/render-markdown.nvim", main = "render-markdown", opts = {}, ft = { "markdown" }, From 3175b8f38a9c8d70a8388385c92e0adeee79b327 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 24 Oct 2025 23:09:54 +0200 Subject: [PATCH 154/247] feat: open jira ticket with gx :) (#444) --- lua/config/gx.lua | 17 +++++++++++++++++ lua/plugin_specs.lua | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lua/config/gx.lua diff --git a/lua/config/gx.lua b/lua/config/gx.lua new file mode 100644 index 00000000..fe943500 --- /dev/null +++ b/lua/config/gx.lua @@ -0,0 +1,17 @@ +---@diagnostic disable-next-line: missing-fields +require("gx").setup { + handlers = { + jira = { + name = "jira", -- set name of handler + handle = function(mode, line, _) + local ticket = require("gx.helper").find(line, mode, "(%a%a%a+%-%d+)") + vim.print("ticket, mode, line", ticket, mode, line) + + if ticket and #ticket < 20 then + local ticket_link = string.format("http://jira.%s/browse/%s", vim.env.COMPANY_NAME, ticket) + return ticket_link + end + end, + }, + }, +} diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 3e4477d0..46cc951a 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -257,7 +257,9 @@ local plugin_specs = { enabled = function() return vim.g.is_win or vim.g.is_mac end, - config = true, -- default settings + config = function() + require("config.gx") + end, submodules = false, -- not needed, submodules are required only for tests }, From 1bffe84cb3805a924ec0f0f27f02215840a07bc8 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 24 Oct 2025 23:19:49 +0200 Subject: [PATCH 155/247] fzf-lua: do not ignore files --- lua/config/fzf-lua.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/config/fzf-lua.lua b/lua/config/fzf-lua.lua index 2ed01088..da7b071d 100644 --- a/lua/config/fzf-lua.lua +++ b/lua/config/fzf-lua.lua @@ -8,6 +8,8 @@ require("fzf-lua").setup { }, files = { previewer = false, + git_icons = true, + no_ignore = true, }, } From 04d9079b8a3e006b604421b22cdb94ddb7c0693d Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 26 Oct 2025 17:52:35 +0100 Subject: [PATCH 156/247] feat: load env variable from .env (#445) --- .gitignore | 1 + lua/config/gx.lua | 8 ++++++-- lua/dotenv.lua | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 lua/dotenv.lua diff --git a/.gitignore b/.gitignore index 178e9446..f8e46c0a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ en.utf-8.add.spl *.log .DS_Store lazy-lock.json +.env* diff --git a/lua/config/gx.lua b/lua/config/gx.lua index fe943500..e8109adc 100644 --- a/lua/config/gx.lua +++ b/lua/config/gx.lua @@ -5,10 +5,14 @@ require("gx").setup { name = "jira", -- set name of handler handle = function(mode, line, _) local ticket = require("gx.helper").find(line, mode, "(%a%a%a+%-%d+)") - vim.print("ticket, mode, line", ticket, mode, line) + + local dotenv = require("dotenv") + local env_path = vim.fs.joinpath(vim.fn.stdpath("config"), ".env") + dotenv.load_dotenv(env_path) + local company_name = dotenv.get("COMPANY_NAME") if ticket and #ticket < 20 then - local ticket_link = string.format("http://jira.%s/browse/%s", vim.env.COMPANY_NAME, ticket) + local ticket_link = string.format("http://jira.%s/browse/%s", company_name, ticket) return ticket_link end end, diff --git a/lua/dotenv.lua b/lua/dotenv.lua new file mode 100644 index 00000000..a065dda0 --- /dev/null +++ b/lua/dotenv.lua @@ -0,0 +1,29 @@ +-- code from https://github.com/mcjkula/lua-dotenv/blob/main/env.lua +local M = {} +local env_vars = {} + +function M.get(key, default) + local value = env_vars[key] or os.getenv(key) + return value or default +end + +function M.load_dotenv(file_path) + file_path = file_path or os.getenv("HOME") .. "/.config/.env" + local file, _ = io.open(file_path, "r") + if not file then + return + end + + local content = file:read("*all") + file:close() + + for line in content:gmatch("[^\r\n]+") do + local key, value = line:match("^([%w_]+)%s*=%s*(.+)$") + if key and value then + value = value:gsub("^[\"'](.-)[\"']$", "%1") + env_vars[key] = value + end + end +end + +return M From 7a33e22440a3dd96628065d99fde9df146152d65 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 26 Oct 2025 17:54:44 +0100 Subject: [PATCH 157/247] refactor: use vim.fs for path joining (#446) --- lua/plugin_specs.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 46cc951a..18e7c448 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -1,7 +1,7 @@ local utils = require("utils") -local plugin_dir = vim.fn.stdpath("data") .. "/lazy" -local lazypath = plugin_dir .. "/lazy.nvim" +local plugin_dir = vim.fs.joinpath(vim.fn.stdpath("data"), "lazy") +local lazypath = vim.fs.joinpath(plugin_dir, "lazy.nvim") if not vim.uv.fs_stat(lazypath) then vim.fn.system { @@ -467,7 +467,7 @@ local plugin_specs = { -- it seems that we can only call the firenvim function directly. -- Using vim.fn or vim.cmd to call this function will fail. build = function() - local firenvim_path = plugin_dir .. "/firenvim" + local firenvim_path = vim.fs.joinpath(plugin_dir, "firenvim") vim.opt.runtimepath:append(firenvim_path) vim.cmd("runtime! firenvim.vim") From 3a439b2447c3e1dfa05ad776bed36eec68d70ed5 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 27 Oct 2025 00:02:53 +0100 Subject: [PATCH 158/247] feat: add mapping for JSON file format (#447) --- after/ftplugin/json.lua | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 after/ftplugin/json.lua diff --git a/after/ftplugin/json.lua b/after/ftplugin/json.lua new file mode 100644 index 00000000..dda237ea --- /dev/null +++ b/after/ftplugin/json.lua @@ -0,0 +1,4 @@ +vim.keymap.set("n", "f", "JSONFormat", { + buffer = true, + silent = true, +}) From 72849d19bab9646c76c68d9c1e7d962dabffd2db Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 27 Oct 2025 00:05:58 +0100 Subject: [PATCH 159/247] remove mappings for adding a blank line (#448) Nvim has builtin mapping for these: - `[`: add a blank line above - `]`: add a blank line below --- lua/mappings.lua | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lua/mappings.lua b/lua/mappings.lua index 940019d0..6afb76b8 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -49,18 +49,6 @@ end, { desc = "delete other buffers", }) --- Insert a blank line below or above current line (do not move the cursor), --- see https://stackoverflow.com/a/16136133/6064933 -keymap.set("n", "o", "printf('m`%so``', v:count1)", { - expr = true, - desc = "insert line below", -}) - -keymap.set("n", "O", "printf('m`%sO``', v:count1)", { - expr = true, - desc = "insert line above", -}) - -- Move the cursor based on physical lines, not the actual lines. keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true }) keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true }) From b6050a99f230106889b10cd3f6c95fd2f4f17146 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 27 Oct 2025 00:19:12 +0100 Subject: [PATCH 160/247] update diagnostic config (#449) dismiss diagnostic float win in insert mode --- lua/diagnostic-conf.lua | 2 +- lua/plugin_specs.lua | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/diagnostic-conf.lua b/lua/diagnostic-conf.lua index f5558fcb..7763a610 100644 --- a/lua/diagnostic-conf.lua +++ b/lua/diagnostic-conf.lua @@ -22,7 +22,7 @@ diagnostic.config { border = "single", max_height = 10, max_width = 130, - close_events = { "CursorMoved", "BufLeave", "WinLeave" }, + close_events = { "CursorMoved", "BufLeave", "WinLeave", "InsertEnter" }, }, } diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 18e7c448..52cbb391 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -612,7 +612,6 @@ local plugin_specs = { }, } ----@diagnostic disable-next-line: missing-fields require("lazy").setup { spec = plugin_specs, ui = { From be966db58b87667d38a457b1005ba499f1124ae6 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 29 Oct 2025 01:22:16 +0100 Subject: [PATCH 161/247] fzf-lua config update: respect ignore files (#450) --- lua/config/fzf-lua.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/config/fzf-lua.lua b/lua/config/fzf-lua.lua index da7b071d..d4b4180d 100644 --- a/lua/config/fzf-lua.lua +++ b/lua/config/fzf-lua.lua @@ -9,7 +9,11 @@ require("fzf-lua").setup { files = { previewer = false, git_icons = true, - no_ignore = true, + -- using .gitignore is usually good, but still we may want to include some files, + -- you can create a file `.rgignore` to "unignore" those files, e.g., `.env` files. + -- see also https://github.com/BurntSushi/ripgrep/discussions/2512 + -- and https://www.reddit.com/r/linuxquestions/comments/zycvud/ripgrep_respect_gitignore_but_show_env_files/ + no_ignore = false, }, } From c98531e0172d27240a2a2adb80dcb918f86cff05 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 1 Nov 2025 12:05:55 +0100 Subject: [PATCH 162/247] move vim plugin config to plugin_specs.lua (#451) - also remove some unused pluins --- init.lua | 3 +- lua/plugin_specs.lua | 257 ++++++++++++++++++++++++++++++++++-------- viml_conf/plugins.vim | 228 ------------------------------------- 3 files changed, 214 insertions(+), 274 deletions(-) delete mode 100644 viml_conf/plugins.vim diff --git a/init.lua b/init.lua index 0e44a979..8addad43 100644 --- a/init.lua +++ b/init.lua @@ -27,8 +27,9 @@ vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/options.vim")) require("custom-autocmd") -- all the user-defined mappings require("mappings") + -- all the plugins installed and their configurations -vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim")) +require("plugin_specs") -- diagnostic related config require("diagnostic-conf") diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 52cbb391..5da2ee35 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -78,19 +78,6 @@ local plugin_specs = { }, { "machakann/vim-swap", event = "VeryLazy" }, - -- IDE for Lisp - -- 'kovisoft/slimv' - { - "vlime/vlime", - enabled = function() - return utils.executable("sbcl") - end, - config = function(plugin) - vim.opt.rtp:append(plugin.dir .. "/vim") - end, - ft = { "lisp" }, - }, - -- Super fast buffer jump { "smoka7/hop.nvim", @@ -267,6 +254,19 @@ local plugin_specs = { -- show file tags in vim window { "liuchengxu/vista.vim", + init = function() + vim.cmd([[ + let g:vista#renderer#icons = { + \ 'member': '', + \ } + " Do not echo message on command line + let g:vista_echo_cursor = 0 + " Stay in current window when vista window is opened + let g:vista_stay_on_open = 0 + + nnoremap t :Vista!! + ]]) + end, enabled = function() return utils.executable("ctags") end, @@ -276,6 +276,23 @@ local plugin_specs = { -- Snippet engine and snippet template { "SirVer/ultisnips", + init = function() + vim.cmd([[ + " Trigger configuration. Do not use if you use YouCompleteMe + let g:UltiSnipsExpandTrigger='' + + " Do not look for SnipMate snippets + let g:UltiSnipsEnableSnipMate = 0 + + " Shortcut to jump forward and backward in tabstop positions + let g:UltiSnipsJumpForwardTrigger='' + let g:UltiSnipsJumpBackwardTrigger='' + + " Configuration for custom snippets directory, see + " https://jdhao.github.io/2019/04/17/neovim_snippet_s1/ for details. + let g:UltiSnipsSnippetDirectories=['UltiSnips', 'my_snippets'] + ]]) + end, dependencies = { "honza/vim-snippets", }, @@ -301,9 +318,6 @@ local plugin_specs = { -- Multiple cursor plugin like Sublime Text? -- 'mg979/vim-visual-multi' - -- Show undo history visually - { "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } }, - -- Manage your yank history { "gbprod/yanky.nvim", @@ -319,10 +333,23 @@ local plugin_specs = { -- Repeat vim motions { "tpope/vim-repeat", event = "VeryLazy" }, - { "nvim-zh/better-escape.vim", event = { "InsertEnter" } }, + { + "nvim-zh/better-escape.vim", + init = function() + vim.cmd([[ + let g:better_escape_interval = 200 + ]]) + end, + event = { "InsertEnter" }, + }, { "lyokha/vim-xkbswitch", + init = function() + vim.cmd([[ + let g:XkbSwitchEnabled = 1 + ]]) + end, enabled = function() return vim.g.is_mac and utils.executable("xkbswitch") end, @@ -403,36 +430,100 @@ local plugin_specs = { -- Vim tabular plugin for manipulate tabular, required by markdown plugins { "godlygeek/tabular", ft = { "markdown" } }, - -- Markdown previewing (only for Mac and Windows) { - "iamcco/markdown-preview.nvim", - enabled = function() - return vim.g.is_win or vim.g.is_mac - end, - build = "cd app && npm install && git restore .", - ft = { "markdown" }, - }, - - { - "rhysd/vim-grammarous", - enabled = function() - return vim.g.is_mac + "chrisbra/unicode.vim", + init = function() + vim.cmd([[ + nmap ga (UnicodeGA) + ]]) end, - ft = { "markdown" }, + event = "VeryLazy", }, - { "chrisbra/unicode.vim", keys = { "ga" }, cmd = { "UnicodeSearch" } }, - -- Additional powerful text object for vim, this plugin should be studied -- carefully to use its full power { "wellle/targets.vim", event = "VeryLazy" }, -- Plugin to manipulate character pairs quickly - { "machakann/vim-sandwich", event = "VeryLazy" }, + { + "machakann/vim-sandwich", + init = function() + vim.cmd([[ + " Map s to nop since s in used by vim-sandwich. Use cl instead of s. + nmap s + omap s + ]]) + end, + event = "VeryLazy", + }, -- Only use these plugin on Windows and Mac and when LaTeX is installed { "lervag/vimtex", + init = function() + vim.cmd([[ + if executable('latex') + " Hacks for inverse search to work semi-automatically, + " see https://jdhao.github.io/2021/02/20/inverse_search_setup_neovim_vimtex/. + function! s:write_server_name() abort + let nvim_server_file = (has('win32') ? $TEMP : '/tmp') . '/vimtexserver.txt' + call writefile([v:servername], nvim_server_file) + endfunction + + augroup vimtex_common + autocmd! + autocmd FileType tex call s:write_server_name() + autocmd FileType tex nmap (vimtex-compile) + augroup END + + let g:vimtex_compiler_latexmk = { + \ 'build_dir' : 'build', + \ } + + " TOC settings + let g:vimtex_toc_config = { + \ 'name' : 'TOC', + \ 'layers' : ['content', 'todo', 'include'], + \ 'resize' : 1, + \ 'split_width' : 30, + \ 'todo_sorted' : 0, + \ 'show_help' : 1, + \ 'show_numbers' : 1, + \ 'mode' : 2, + \ } + + " Viewer settings for different platforms + if g:is_win + let g:vimtex_view_general_viewer = 'SumatraPDF' + let g:vimtex_view_general_options = '-reuse-instance -forward-search @tex @line @pdf' + endif + + if g:is_mac + " let g:vimtex_view_method = "skim" + let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline' + let g:vimtex_view_general_options = '-r @line @pdf @tex' + + augroup vimtex_mac + autocmd! + autocmd User VimtexEventCompileSuccess call UpdateSkim() + augroup END + + " The following code is adapted from https://gist.github.com/skulumani/7ea00478c63193a832a6d3f2e661a536. + function! UpdateSkim() abort + let l:out = b:vimtex.out() + let l:src_file_path = expand('%:p') + let l:cmd = [g:vimtex_view_general_viewer, '-r'] + + if !empty(system('pgrep Skim')) + call extend(l:cmd, ['-g']) + endif + + call jobstart(l:cmd + [line('.'), l:out, l:src_file_path]) + endfunction + endif + endif + ]]) + end, enabled = function() return utils.executable("latex") end, @@ -451,16 +542,92 @@ local plugin_specs = { }, -- Modern matchit implementation - { "andymass/vim-matchup", event = "BufRead" }, + { + "andymass/vim-matchup", + init = function() + vim.cmd([[ + " Improve performance + let g:matchup_matchparen_deferred = 1 + let g:matchup_matchparen_timeout = 100 + let g:matchup_matchparen_insert_timeout = 30 + + " Enhanced matching with matchup plugin + let g:matchup_override_vimtex = 1 + + " Whether to enable matching inside comment or string + let g:matchup_delim_noskips = 0 + + " Show offscreen match pair in popup window + let g:matchup_matchparen_offscreen = {'method': 'popup'} + ]]) + end, + event = "BufRead", + }, { "tpope/vim-scriptease", cmd = { "Scriptnames", "Messages", "Verbose" } }, -- Asynchronous command execution - { "skywind3000/asyncrun.vim", lazy = true, cmd = { "AsyncRun" } }, + { + "skywind3000/asyncrun.vim", + init = function() + vim.cmd([[ + " Automatically open quickfix window of 6 line tall after asyncrun starts + let g:asyncrun_open = 6 + if g:is_win + " Command output encoding for Windows + let g:asyncrun_encs = 'gbk' + endif + ]]) + end, + cmd = { "AsyncRun" }, + }, { "cespare/vim-toml", ft = { "toml" }, branch = "main" }, -- Edit text area in browser using nvim { "glacambre/firenvim", + init = function() + vim.cmd([[ + """"""""""""""""""""""""""""""firenvim settings"""""""""""""""""""""""""""""" + if exists('g:started_by_firenvim') && g:started_by_firenvim + if g:is_mac + set guifont=Iosevka\ Nerd\ Font:h18 + else + set guifont=Consolas + endif + + " general config for firenvim + let g:firenvim_config = { + \ 'globalSettings': { + \ 'alt': 'all', + \ }, + \ 'localSettings': { + \ '.*': { + \ 'cmdline': 'neovim', + \ 'priority': 0, + \ 'selector': 'textarea', + \ 'takeover': 'never', + \ }, + \ } + \ } + + function s:setup_firenvim() abort + set signcolumn=no + set noruler + set noshowcmd + set laststatus=0 + set showtabline=0 + endfunction + + augroup firenvim + autocmd! + autocmd BufEnter * call s:setup_firenvim() + autocmd BufEnter sqlzoo*.txt set filetype=sql + autocmd BufEnter github.com_*.txt set filetype=markdown + autocmd BufEnter stackoverflow.com_*.txt set filetype=markdown + augroup END + endif + ]]) + end, enabled = function() return vim.g.is_win or vim.g.is_mac end, @@ -481,15 +648,6 @@ local plugin_specs = { vim.cmd(cmd_str) end, }, - -- Debugger plugin - { - "sakhnik/nvim-gdb", - enabled = function() - return vim.g.is_win or vim.g.is_linux - end, - build = { "bash install.sh" }, - lazy = true, - }, -- Session management plugin { "tpope/vim-obsession", cmd = "Obsession" }, @@ -624,3 +782,12 @@ require("lazy").setup { hererocks = false, }, } + +-- Use short names for common plugin manager commands to simplify typing. +-- To use these shortcuts: first activate command line with `:`, then input the +-- short alias, e.g., `pi`, then press , the alias will be expanded to +-- the full command automatically. +vim.fn["utils#Cabbrev"]("pi", "Lazy install") +vim.fn["utils#Cabbrev"]("pud", "Lazy update") +vim.fn["utils#Cabbrev"]("pc", "Lazy clean") +vim.fn["utils#Cabbrev"]("ps", "Lazy sync") diff --git a/viml_conf/plugins.vim b/viml_conf/plugins.vim deleted file mode 100644 index d07d702f..00000000 --- a/viml_conf/plugins.vim +++ /dev/null @@ -1,228 +0,0 @@ -scriptencoding utf-8 - -" Plugin specification and lua stuff -lua require('plugin_specs') - -" Use short names for common plugin manager commands to simplify typing. -" To use these shortcuts: first activate command line with `:`, then input the -" short alias, e.g., `pi`, then press , the alias will be expanded to -" the full command automatically. -call utils#Cabbrev('pi', 'Lazy install') -call utils#Cabbrev('pud', 'Lazy update') -call utils#Cabbrev('pc', 'Lazy clean') -call utils#Cabbrev('ps', 'Lazy sync') - -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" configurations for vim script plugin " -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -"""""""""""""""""""""""""UltiSnips settings""""""""""""""""""" -" Trigger configuration. Do not use if you use YouCompleteMe -let g:UltiSnipsExpandTrigger='' - -" Do not look for SnipMate snippets -let g:UltiSnipsEnableSnipMate = 0 - -" Shortcut to jump forward and backward in tabstop positions -let g:UltiSnipsJumpForwardTrigger='' -let g:UltiSnipsJumpBackwardTrigger='' - -" Configuration for custom snippets directory, see -" https://jdhao.github.io/2019/04/17/neovim_snippet_s1/ for details. -let g:UltiSnipsSnippetDirectories=['UltiSnips', 'my_snippets'] - -"""""""""""""""""""""""""" vlime settings """""""""""""""""""""""""""""""" -command! -nargs=0 StartVlime call jobstart(printf("sbcl --load %s/vlime/lisp/start-vlime.lisp", g:package_home)) - -""""""""""""""""""""""""""" vista settings """""""""""""""""""""""""""""""""" -let g:vista#renderer#icons = { - \ 'member': '', - \ } - -" Do not echo message on command line -let g:vista_echo_cursor = 0 -" Stay in current window when vista window is opened -let g:vista_stay_on_open = 0 - -nnoremap t :Vista!! - -""""""""""""""""""""""""vim-mundo settings""""""""""""""""""""""" -let g:mundo_verbose_graph = 0 -let g:mundo_width = 80 - -nnoremap u :MundoToggle - -""""""""""""""""""""""""""""better-escape.vim settings""""""""""""""""""""""""" -let g:better_escape_interval = 200 - -""""""""""""""""""""""""""""vim-xkbswitch settings""""""""""""""""""""""""" -let g:XkbSwitchEnabled = 1 - -"""""""""""""""""""""""""markdown-preview settings""""""""""""""""""" -" Only setting this for suitable platforms -if g:is_win || g:is_mac - " Do not close the preview tab when switching to other buffers - let g:mkdp_auto_close = 0 - - " Shortcuts to start and stop markdown previewing - nnoremap :MarkdownPreview - nnoremap :MarkdownPreviewStop -endif - -""""""""""""""""""""""""vim-grammarous settings"""""""""""""""""""""""""""""" -if g:is_mac - let g:grammarous#languagetool_cmd = 'languagetool' - let g:grammarous#disabled_rules = { - \ '*' : ['WHITESPACE_RULE', 'EN_QUOTES', 'ARROWS', 'SENTENCE_WHITESPACE', - \ 'WORD_CONTAINS_UNDERSCORE', 'COMMA_PARENTHESIS_WHITESPACE', - \ 'EN_UNPAIRED_BRACKETS', 'UPPERCASE_SENTENCE_START', - \ 'ENGLISH_WORD_REPEAT_BEGINNING_RULE', 'DASH_RULE', 'PLUS_MINUS', - \ 'PUNCTUATION_PARAGRAPH_END', 'MULTIPLICATION_SIGN', 'PRP_CHECKOUT', - \ 'CAN_CHECKOUT', 'SOME_OF_THE', 'DOUBLE_PUNCTUATION', 'HELL', - \ 'CURRENCY', 'POSSESSIVE_APOSTROPHE', 'ENGLISH_WORD_REPEAT_RULE', - \ 'NON_STANDARD_WORD', 'AU', 'DATE_NEW_YEAR'], - \ } - - augroup grammarous_map - autocmd! - autocmd FileType markdown nmap x (grammarous-close-info-window) - autocmd FileType markdown nmap (grammarous-move-to-next-error) - autocmd FileType markdown nmap (grammarous-move-to-previous-error) - augroup END -endif - -""""""""""""""""""""""""unicode.vim settings"""""""""""""""""""""""""""""" -nmap ga (UnicodeGA) - -""""""""""""""""""""""""""""vim-sandwich settings""""""""""""""""""""""""""""" -" Map s to nop since s in used by vim-sandwich. Use cl instead of s. -nmap s -omap s - -""""""""""""""""""""""""""""vimtex settings""""""""""""""""""""""""""""" -if executable('latex') - " Hacks for inverse search to work semi-automatically, - " see https://jdhao.github.io/2021/02/20/inverse_search_setup_neovim_vimtex/. - function! s:write_server_name() abort - let nvim_server_file = (has('win32') ? $TEMP : '/tmp') . '/vimtexserver.txt' - call writefile([v:servername], nvim_server_file) - endfunction - - augroup vimtex_common - autocmd! - autocmd FileType tex call s:write_server_name() - autocmd FileType tex nmap (vimtex-compile) - augroup END - - let g:vimtex_compiler_latexmk = { - \ 'build_dir' : 'build', - \ } - - " TOC settings - let g:vimtex_toc_config = { - \ 'name' : 'TOC', - \ 'layers' : ['content', 'todo', 'include'], - \ 'resize' : 1, - \ 'split_width' : 30, - \ 'todo_sorted' : 0, - \ 'show_help' : 1, - \ 'show_numbers' : 1, - \ 'mode' : 2, - \ } - - " Viewer settings for different platforms - if g:is_win - let g:vimtex_view_general_viewer = 'SumatraPDF' - let g:vimtex_view_general_options = '-reuse-instance -forward-search @tex @line @pdf' - endif - - if g:is_mac - " let g:vimtex_view_method = "skim" - let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline' - let g:vimtex_view_general_options = '-r @line @pdf @tex' - - augroup vimtex_mac - autocmd! - autocmd User VimtexEventCompileSuccess call UpdateSkim() - augroup END - - " The following code is adapted from https://gist.github.com/skulumani/7ea00478c63193a832a6d3f2e661a536. - function! UpdateSkim() abort - let l:out = b:vimtex.out() - let l:src_file_path = expand('%:p') - let l:cmd = [g:vimtex_view_general_viewer, '-r'] - - if !empty(system('pgrep Skim')) - call extend(l:cmd, ['-g']) - endif - - call jobstart(l:cmd + [line('.'), l:out, l:src_file_path]) - endfunction - endif -endif - -""""""""""""""""""""""""""""vim-matchup settings""""""""""""""""""""""""""""" -" Improve performance -let g:matchup_matchparen_deferred = 1 -let g:matchup_matchparen_timeout = 100 -let g:matchup_matchparen_insert_timeout = 30 - -" Enhanced matching with matchup plugin -let g:matchup_override_vimtex = 1 - -" Whether to enable matching inside comment or string -let g:matchup_delim_noskips = 0 - -" Show offscreen match pair in popup window -let g:matchup_matchparen_offscreen = {'method': 'popup'} - -"""""""""""""""""""""""""" asyncrun.vim settings """""""""""""""""""""""""" -" Automatically open quickfix window of 6 line tall after asyncrun starts -let g:asyncrun_open = 6 -if g:is_win - " Command output encoding for Windows - let g:asyncrun_encs = 'gbk' -endif - -""""""""""""""""""""""""""""""firenvim settings"""""""""""""""""""""""""""""" -if exists('g:started_by_firenvim') && g:started_by_firenvim - if g:is_mac - set guifont=Iosevka\ Nerd\ Font:h18 - else - set guifont=Consolas - endif - - " general config for firenvim - let g:firenvim_config = { - \ 'globalSettings': { - \ 'alt': 'all', - \ }, - \ 'localSettings': { - \ '.*': { - \ 'cmdline': 'neovim', - \ 'priority': 0, - \ 'selector': 'textarea', - \ 'takeover': 'never', - \ }, - \ } - \ } - - function s:setup_firenvim() abort - set signcolumn=no - set noruler - set noshowcmd - set laststatus=0 - set showtabline=0 - endfunction - - augroup firenvim - autocmd! - autocmd BufEnter * call s:setup_firenvim() - autocmd BufEnter sqlzoo*.txt set filetype=sql - autocmd BufEnter github.com_*.txt set filetype=markdown - autocmd BufEnter stackoverflow.com_*.txt set filetype=markdown - augroup END -endif - -""""""""""""""""""""""""""""""nvim-gdb settings"""""""""""""""""""""""""""""" -nnoremap dp :GdbStartPDB python -m pdb % From 279b7ce687fa36fbfaf76360c7ba4a8cd0f3d3a6 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 1 Nov 2025 12:17:44 +0100 Subject: [PATCH 163/247] update README --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e6f8a45..1c51744e 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ and how to set up on different platforms (Linux, macOS, and Windows). + Code highlighting via [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter). + Code editing using true nvim inside browser via [firenvim](https://github.com/glacambre/firenvim). + Beautiful colorscheme via [sainnhe/gruvbox-material](https://github.com/sainnhe/gruvbox-material) and other colorschemes. -+ Markdown writing and previewing via [vim-markdown](https://github.com/preservim/vim-markdown) and [markdown-preview.nvim](https://github.com/iamcco/markdown-preview.nvim). ++ Markdown previewing via [render-markdown.nvim](https://github.com/MeanderingProgrammer/render-markdown.nvim) + LaTeX editing and previewing via [vimtex](https://github.com/lervag/vimtex) + Animated GUI style notification via [nvim-notify](https://github.com/rcarriga/nvim-notify). + Tags navigation via [vista](https://github.com/liuchengxu/vista.vim). @@ -178,8 +178,6 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu | `{operator}iB` | Normal | Linux/macOS/Win | Operate in the whole buffer, `{operator}` can be `v`, `y`, `c`, `d` etc. | | `Alt-k` | Normal | Linux/macOS/Win | Move current line or selected lines up | | `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down | -| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser | -| `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser | | `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case | | `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case | | `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging | From 28839c391fd7f8055fe16a9e1f9be2e9c43f15b6 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 1 Nov 2025 12:21:55 +0100 Subject: [PATCH 164/247] update README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1c51744e..68f05dd1 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,6 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu | `v` | Normal | Linux/macOS/Win | Reselect last pasted text | | `ev` | Normal | Linux/macOS/Win | Edit Nvim config in a new tabpage | | `sv` | Normal | Linux/macOS/Win | Reload Nvim config | -| `st` | Normal | Linux/macOS/Win | Show highlight group for cursor text | | `q` | Normal | Linux/macOS/Win | Quit current window | | `Q` | Normal | Linux/macOS/Win | Quit all window and close Nvim | | `w` | Normal | Linux/macOS/Win | Save current buffer content | From 6173ae9507e3274d7dd734ca674d19c2c4ce9470 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 2 Nov 2025 21:58:38 +0100 Subject: [PATCH 165/247] support nvim 0.11.5 (#452) --- README.md | 2 +- init.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 68f05dd1..e93ca861 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows - Neovim minimum version + Neovim minimum version Top languages diff --git a/init.lua b/init.lua index 8addad43..520f8db1 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.11.4" +local expected_version = "0.11.5" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") From 6265982f50fd9a77a71ebd8df954c2270e8e4f7f Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 19 Dec 2025 18:34:01 +0100 Subject: [PATCH 166/247] Fix git branch status issue in statusline (#453) --- lua/config/lualine.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index dfd3bd50..414c5090 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -1,6 +1,11 @@ local fn = vim.fn -local git_status_cache = {} +-- cache for git states +local git_status_cache = { + fetch_success = false, + behind_count = 0, + ahead_count = 0, +} local on_exit_fetch = function(result) if result.code == 0 then @@ -12,6 +17,12 @@ local function handle_numeric_result(cache_key) return function(result) if result.code == 0 then git_status_cache[cache_key] = tonumber(result.stdout:match("(%d+)")) or 0 + else + -- when the git command fails, it usually means there are some changes in your branch. For example, you + -- on branchA, for this one, you have upstream branch. Then you changed to branchB, and there is no upstream + -- branch, the git rev-list command will error out. In this case, we should clear the cache + -- vim.print("Error running git command", result) + git_status_cache[cache_key] = 0 end end end From bc7431719cd434ed2806df81aba0fcde23750a77 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 24 Dec 2025 22:29:25 +0100 Subject: [PATCH 167/247] update stylua config (#454) --- .stylua.toml | 2 ++ lua/config/fzf-lua.lua | 21 ++++++++++++++++++--- lua/config/nvim_ufo.lua | 3 ++- lua/custom-autocmd.lua | 12 ++++++++++-- lua/mappings.lua | 35 ++++++++++++++++++++++++++++++----- 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/.stylua.toml b/.stylua.toml index 4b134160..92bda2a1 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -1,4 +1,6 @@ # config for stylua, ref: https://github.com/JohnnyMorganz/StyLua +syntax = "Lua51" +column_width = 100 line_endings = "Unix" indent_type = "Spaces" indent_width = 2 diff --git a/lua/config/fzf-lua.lua b/lua/config/fzf-lua.lua index d4b4180d..de7fe94e 100644 --- a/lua/config/fzf-lua.lua +++ b/lua/config/fzf-lua.lua @@ -19,7 +19,22 @@ require("fzf-lua").setup { vim.keymap.set("n", "ff", "FzfLua files", { desc = "Fuzzy find files" }) vim.keymap.set("n", "fg", "FzfLua live_grep", { desc = "Fuzzy grep files" }) -vim.keymap.set("n", "fh", "FzfLua helptags", { desc = "Fuzzy grep tags in help files" }) +vim.keymap.set( + "n", + "fh", + "FzfLua helptags", + { desc = "Fuzzy grep tags in help files" } +) vim.keymap.set("n", "ft", "FzfLua btags", { desc = "Fuzzy search buffer tags" }) -vim.keymap.set("n", "fb", "FzfLua buffers", { desc = "Fuzzy search opened buffers" }) -vim.keymap.set("n", "fr", "FzfLua oldfiles", { desc = "Fuzzy search opened files history" }) +vim.keymap.set( + "n", + "fb", + "FzfLua buffers", + { desc = "Fuzzy search opened buffers" } +) +vim.keymap.set( + "n", + "fr", + "FzfLua oldfiles", + { desc = "Fuzzy search opened files history" } +) diff --git a/lua/config/nvim_ufo.lua b/lua/config/nvim_ufo.lua index b8704ee7..bc1ae60d 100644 --- a/lua/config/nvim_ufo.lua +++ b/lua/config/nvim_ufo.lua @@ -24,7 +24,8 @@ local handler = function(virtText, lnum, endLnum, width, truncate) end curWidth = curWidth + chunkWidth end - local rAlignAppndx = math.max(math.min(vim.opt.textwidth["_value"], width - 1) - curWidth - sufWidth, 0) + local rAlignAppndx = + math.max(math.min(vim.opt.textwidth["_value"], width - 1) - curWidth - sufWidth, 0) suffix = (" "):rep(rAlignAppndx) .. suffix table.insert(newVirtText, { suffix, "MoreMsg" }) return newVirtText diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 62b6e7eb..1167114d 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -64,7 +64,11 @@ api.nvim_create_autocmd({ "FileChangedShellPost" }, { pattern = "*", group = "auto_read", callback = function() - vim.notify("File changed on disk. Buffer reloaded!", vim.log.levels.WARN, { title = "nvim-config" }) + vim.notify( + "File changed on disk. Buffer reloaded!", + vim.log.levels.WARN, + { title = "nvim-config" } + ) end, }) @@ -164,7 +168,11 @@ api.nvim_create_autocmd("ColorScheme", { desc = "Define or overrride some highlight groups", callback = function() -- For yank highlight - vim.api.nvim_set_hl(0, "YankColor", { fg = "#34495E", bg = "#2ECC71", ctermfg = 59, ctermbg = 41 }) + vim.api.nvim_set_hl( + 0, + "YankColor", + { fg = "#34495E", bg = "#2ECC71", ctermfg = 59, ctermbg = 41 } + ) -- For cursor colors vim.api.nvim_set_hl(0, "Cursor", { fg = "black", bg = "#00c918", bold = true }) diff --git a/lua/mappings.lua b/lua/mappings.lua index 6afb76b8..b5cca830 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -116,22 +116,47 @@ keymap.set("n", "cc", '"_cc') keymap.set("x", "c", '"_c') -- Remove trailing whitespace characters -keymap.set("n", "", "StripTrailingWhitespace", { desc = "remove trailing space" }) +keymap.set( + "n", + "", + "StripTrailingWhitespace", + { desc = "remove trailing space" } +) -- Copy entire buffer. keymap.set("n", "y", "%yank", { desc = "yank entire buffer" }) -- Toggle cursor column -keymap.set("n", "cl", "call utils#ToggleCursorCol()", { desc = "toggle cursor column" }) +keymap.set( + "n", + "cl", + "call utils#ToggleCursorCol()", + { desc = "toggle cursor column" } +) -- Move current line up and down -keymap.set("n", "", 'call utils#SwitchLine(line("."), "up")', { desc = "move line up" }) -keymap.set("n", "", 'call utils#SwitchLine(line("."), "down")', { desc = "move line down" }) +keymap.set( + "n", + "", + 'call utils#SwitchLine(line("."), "up")', + { desc = "move line up" } +) +keymap.set( + "n", + "", + 'call utils#SwitchLine(line("."), "down")', + { desc = "move line down" } +) -- Move current visual-line selection up and down keymap.set("x", "", 'call utils#MoveSelection("up")', { desc = "move selection up" }) -keymap.set("x", "", 'call utils#MoveSelection("down")', { desc = "move selection down" }) +keymap.set( + "x", + "", + 'call utils#MoveSelection("down")', + { desc = "move selection down" } +) -- Replace visual selection with text in register, but not contaminate the register, -- see also https://stackoverflow.com/q/10723700/6064933. From bc2c11e11a737868791a40a41a3d72b137409067 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 24 Jan 2026 14:08:55 +0100 Subject: [PATCH 168/247] check if file is formatted (#456) --- lua/custom-autocmd.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 1167114d..24933325 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -250,3 +250,27 @@ api.nvim_create_autocmd("BufReadPre", { end end, }) + +-- check if current file is formatted +local ft_to_command = { + python = { "black", "--check" }, + lua = { "stylua", "--check" }, +} + +api.nvim_create_autocmd("BufWritePost", { + group = api.nvim_create_augroup("format check", { clear = true }), + pattern = { "*.py", "*.lua" }, + desc = "Check if file needs reformat", + callback = function(ev) + local fpath = ev.file + local ft = vim.api.nvim_get_option_value("filetype", { buf = ev.buf }) + local cmd = vim.deepcopy(ft_to_command[ft]) + table.insert(cmd, fpath) + + local result = vim.system(cmd, { text = true }):wait() + + if result.code ~= 0 then + vim.notify("This file is not formatted!") + end + end, +}) From 3353922d51c9fd7720238c9f73c904942a7cd2e6 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 24 Jan 2026 14:52:46 +0100 Subject: [PATCH 169/247] ci: add github action to check lua code format (#457) --- .github/workflows/format-check.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/format-check.yml diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml new file mode 100644 index 00000000..1f4733de --- /dev/null +++ b/.github/workflows/format-check.yml @@ -0,0 +1,17 @@ +name: Format Check + +on: + pull_request: + +jobs: + format-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install stylua + run: | + wget https://github.com/JohnnyMorganz/StyLua/releases/download/v2.3.1/stylua-linux-x86_64.zip + unzip stylua-linux-x86_64.zip + sudo mv stylua /usr/local/bin/ + - name: Run stylua + run: stylua --check . From 30c305ca937ae6e0a574127d9b67c9081fefa5d2 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 24 Jan 2026 15:10:40 +0100 Subject: [PATCH 170/247] Update format check ci (#458) --- .github/workflows/format-check.yml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml index 1f4733de..5cd723bc 100644 --- a/.github/workflows/format-check.yml +++ b/.github/workflows/format-check.yml @@ -1,17 +1,25 @@ name: Format Check - on: pull_request: + paths: + - '**.lua' + push: + branches: + - main + paths: + - '**.lua' jobs: format-check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Install stylua - run: | - wget https://github.com/JohnnyMorganz/StyLua/releases/download/v2.3.1/stylua-linux-x86_64.zip - unzip stylua-linux-x86_64.zip - sudo mv stylua /usr/local/bin/ + - name: Install StyLua + uses: JohnnyMorganz/stylua-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: false - name: Run stylua - run: stylua --check . + run: | + stylua --check . From 53c34c25d3333a12a14d82de30ae65f9ad457ed6 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 28 Jan 2026 17:47:45 +0100 Subject: [PATCH 171/247] bump supported nvim version --- README.md | 2 +- init.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e93ca861..c87c13d0 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows - Neovim minimum version + Neovim minimum version Top languages diff --git a/init.lua b/init.lua index 520f8db1..4f475ce5 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ vim.loader.enable() local utils = require("utils") -local expected_version = "0.11.5" +local expected_version = "0.11.6" utils.is_compatible_version(expected_version) local config_dir = vim.fn.stdpath("config") From 95c13f57f3c38c500e8b9b081d3d1f7d4796da5e Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 30 Jan 2026 20:20:57 +0100 Subject: [PATCH 172/247] Support visual mode for json format (#459) --- after/ftplugin/json.lua | 2 +- plugin/command.lua | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/after/ftplugin/json.lua b/after/ftplugin/json.lua index dda237ea..3bcf7051 100644 --- a/after/ftplugin/json.lua +++ b/after/ftplugin/json.lua @@ -1,4 +1,4 @@ -vim.keymap.set("n", "f", "JSONFormat", { +vim.keymap.set({ "n", "v" }, "f", ":JSONFormat", { buffer = true, silent = true, }) diff --git a/plugin/command.lua b/plugin/command.lua index 006e3724..0b5cc5de 100644 --- a/plugin/command.lua +++ b/plugin/command.lua @@ -1,3 +1,5 @@ +local utils = require("utils") + -- Copy file path to clipboard vim.api.nvim_create_user_command("CopyPath", function(context) local full_path = vim.fn.glob("%:p") @@ -41,13 +43,26 @@ vim.api.nvim_create_user_command("JSONFormat", function(context) local line1 = context["line1"] local line2 = context["line2"] + local python_name = nil + if utils.executable("python3") then + python_name = "python3" + elseif utils.executable("python") then + python_name = "python" + else + vim.print("No python command found") + return + end + if range == 0 then -- the command is invoked without range, then we assume whole buffer - local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2) + local cmd_str = string.format("%s,%s!%s -m json.tool", line1, line2, python_name) vim.fn.execute(cmd_str) elseif range == 2 then -- the command is invoked with some range - local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2) + -- for this to work, the mapping has to call this command with `:JSONFormat`, + -- JSONFormat won't work, the range can not be passed with ``. + -- See also: https://www.reddit.com/r/neovim/comments/17xxehz/how_to_correctly_get_line_ranges_from_command/ + local cmd_str = string.format("%s,%s!%s -m json.tool", line1, line2, python_name) vim.fn.execute(cmd_str) else local msg = string.format("unsupported range: %s", range) From 94bb7b76bc0c806650eadf1fe6685eb3d2b488f2 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 31 Jan 2026 21:37:02 +0100 Subject: [PATCH 173/247] check if executable is available --- lua/custom-autocmd.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 24933325..94a84a0c 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -267,6 +267,11 @@ api.nvim_create_autocmd("BufWritePost", { local cmd = vim.deepcopy(ft_to_command[ft]) table.insert(cmd, fpath) + local exe_path = cmd[1] + if not utils.executable(exe_path) then + return + end + local result = vim.system(cmd, { text = true }):wait() if result.code ~= 0 then From dff6b5e37ad1e36ea05fe121cb14fd9931570b1f Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 1 Feb 2026 22:52:47 +0100 Subject: [PATCH 174/247] feat: switch to main branch of nvim-treesitter (#461) Note: - tree-sitter-cli needs to be installed (in macOS, run `brew install tree-sitter-cli`) - if nvim-treesitter and nvim-treesitter-textobjects are using the old master branch, we need to delete the old plugin and then re-install them to have the main branch --- lua/config/treesitter-textobjects.lua | 88 ++++++++++++++------------- lua/config/treesitter.lua | 58 +++++++++++++++--- lua/plugin_specs.lua | 16 ++++- 3 files changed, 112 insertions(+), 50 deletions(-) diff --git a/lua/config/treesitter-textobjects.lua b/lua/config/treesitter-textobjects.lua index 32e9e5f6..051e8289 100644 --- a/lua/config/treesitter-textobjects.lua +++ b/lua/config/treesitter-textobjects.lua @@ -1,44 +1,50 @@ -require("nvim-treesitter.configs").setup { - textobjects = { - select = { - enable = true, - - -- Automatically jump forward to textobj, similar to targets.vim - lookahead = true, - - keymaps = { - -- You can use the capture groups defined in textobjects.scm - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ac"] = "@class.outer", - -- You can optionally set descriptions to the mappings (used in the desc parameter of - -- nvim_buf_set_keymap) which plugins like which-key display - ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" }, - }, - -- You can choose the select mode (default is charwise 'v') - -- - -- Can also be a function which gets passed a table with the keys - -- * query_string: eg '@function.inner' - -- * method: eg 'v' or 'o' - -- and should return the mode ('v', 'V', or '') or a table - -- mapping query_strings to modes. - selection_modes = { - ["@function.inner"] = "V", -- linewise - ["@function.outer"] = "V", -- linewise - ["@class.outer"] = "V", -- linewise - ["@class.inner"] = "V", -- linewise - ["@parameter.outer"] = "v", -- charwise - }, - -- If you set this to `true` (default is `false`) then any textobject is - -- extended to include preceding or succeeding whitespace. Succeeding - -- whitespace has priority in order to act similarly to eg the built-in - -- `ap`. - -- - -- Can also be a function which gets passed a table with the keys - -- * query_string: eg '@function.inner' - -- * selection_mode: eg 'v' - -- and should return true or false - include_surrounding_whitespace = false, +-- configuration +require("nvim-treesitter-textobjects").setup { + select = { + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + -- You can choose the select mode (default is charwise 'v') + -- + -- Can also be a function which gets passed a table with the keys + -- * query_string: eg '@function.inner' + -- * method: eg 'v' or 'o' + -- and should return the mode ('v', 'V', or '') or a table + -- mapping query_strings to modes. + selection_modes = { + ["@function.inner"] = "V", -- linewise + ["@function.outer"] = "V", -- linewise + ["@class.outer"] = "V", -- linewise + ["@class.inner"] = "V", -- linewise + ["@parameter.outer"] = "v", -- charwise }, + -- If you set this to `true` (default is `false`) then any textobject is + -- extended to include preceding or succeeding whitespace. Succeeding + -- whitespace has priority in order to act similarly to eg the built-in + -- `ap`. + -- + -- Can also be a function which gets passed a table with the keys + -- * query_string: eg '@function.inner' + -- * selection_mode: eg 'v' + -- and should return true of false + include_surrounding_whitespace = false, }, } + +-- keymaps +-- You can use the capture groups defined in `textobjects.scm` +vim.keymap.set({ "x", "o" }, "af", function() + require("nvim-treesitter-textobjects.select").select_textobject("@function.outer", "textobjects") +end) +vim.keymap.set({ "x", "o" }, "if", function() + require("nvim-treesitter-textobjects.select").select_textobject("@function.inner", "textobjects") +end) +vim.keymap.set({ "x", "o" }, "ac", function() + require("nvim-treesitter-textobjects.select").select_textobject("@class.outer", "textobjects") +end) +vim.keymap.set({ "x", "o" }, "ic", function() + require("nvim-treesitter-textobjects.select").select_textobject("@class.inner", "textobjects") +end) +-- You can also use captures from other query groups like `locals.scm` +vim.keymap.set({ "x", "o" }, "as", function() + require("nvim-treesitter-textobjects.select").select_textobject("@local.scope", "locals") +end) diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 2b455531..fe31b12f 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -1,8 +1,52 @@ -require("nvim-treesitter.configs").setup { - ensure_installed = { "python", "cpp", "lua", "vim", "json", "toml" }, - ignore_install = {}, -- List of parsers to ignore installing - highlight = { - enable = true, -- false will disable the whole extension - disable = { "help" }, -- list of language that will be disabled - }, +-- a list of filetypes to install treesitter parsers and queries +local ensure_installed = { + "python", + "cpp", + "lua", + "vim", + "json", + "toml", + "yaml", + "javascript", + "go", + "typescript", + "markdown", + "sh", + "zsh", } + +vim.api.nvim_create_autocmd("FileType", { + pattern = ensure_installed, + + callback = function(args) + local ft = vim.bo[args.buf].filetype + local lang = vim.treesitter.language.get_lang(ft) + + -- check if parser is available + if not vim.treesitter.language.add(lang) then + local available = vim.g.ts_available or require("nvim-treesitter").get_available() + if not vim.g.ts_available then + vim.g.ts_available = available + end + + if vim.tbl_contains(available, lang) then + -- install treesitter parsers and queries + local install_msg = string.format("Installing parsers and queries for %s", lang) + vim.print(install_msg) + require("nvim-treesitter").install(lang) + end + end + + if vim.treesitter.language.add(lang) then + -- start treesitter highlighting + vim.treesitter.start(args.buf, lang) + + -- the following two statements will enable treesitter folding + -- vim.wo[0][0].foldexpr = "v:lua.vim.treesitter.foldexpr()" + -- vim.wo[0][0].foldmethod = "expr" + + -- enable treesitter-based indentation + -- vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end + end, +}) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 5da2ee35..0ff0d13f 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -62,8 +62,9 @@ local plugin_specs = { }, { "nvim-treesitter/nvim-treesitter", - lazy = true, + lazy = false, build = ":TSUpdate", + branch = "main", config = function() require("config.treesitter") end, @@ -71,7 +72,18 @@ local plugin_specs = { { "nvim-treesitter/nvim-treesitter-textobjects", event = "VeryLazy", - branch = "master", + branch = "main", + init = function() + -- Disable entire built-in ftplugin mappings to avoid conflicts. + -- See https://github.com/neovim/neovim/tree/master/runtime/ftplugin for built-in ftplugins. + vim.g.no_plugin_maps = true + + -- Or, disable per filetype (add as you like) + -- vim.g.no_python_maps = true + -- vim.g.no_ruby_maps = true + -- vim.g.no_rust_maps = true + -- vim.g.no_go_maps = true + end, config = function() require("config.treesitter-textobjects") end, From b167ac18367b7c3f7e91641a334913664d5a39d7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 4 Feb 2026 23:27:48 +0100 Subject: [PATCH 175/247] remove copilot plugins (#462) --- lua/plugin_specs.lua | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 0ff0d13f..fcbbfa1a 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -727,24 +727,6 @@ local plugin_specs = { }, }, }, - { - "CopilotC-Nvim/CopilotChat.nvim", - dependencies = { - { "zbirenbaum/copilot.lua" }, -- or github/copilot.vim - }, - opts = { - debug = true, -- Enable debugging - -- See Configuration section for rest - }, - cmd = { "CopilotChat" }, - }, - { - "zbirenbaum/copilot.lua", - cmd = "Copilot", - config = function() - require("copilot").setup {} - end, - }, { "smjonas/live-command.nvim", -- live-command supports semantic versioning via Git tags From 835d8821b619567624dfc602bff6783454cbfdbf Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 6 Feb 2026 20:23:09 +0100 Subject: [PATCH 176/247] remove e-ink-colorscheme --- lua/plugin_specs.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index fcbbfa1a..f3256fba 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -148,7 +148,6 @@ local plugin_specs = { { "miikanissi/modus-themes.nvim", priority = 1000 }, { "wtfox/jellybeans.nvim", priority = 1000 }, { "projekt0n/github-nvim-theme", name = "github-theme" }, - { "e-ink-colorscheme/e-ink.nvim", priority = 1000 }, { "ficcdaf/ashen.nvim", priority = 1000 }, { "savq/melange-nvim", priority = 1000 }, { "Skardyy/makurai-nvim", priority = 1000 }, From eb3e61b6ad0dff393ec65a2521903d8b353933f3 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 6 Feb 2026 20:25:13 +0100 Subject: [PATCH 177/247] remove e-ink from colorscheme module --- lua/colorschemes.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 8cf1a3e4..2a0644fc 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -72,10 +72,6 @@ M.colorscheme_conf = { github = function() use_theme("github_dark_default") end, - e_ink = function() - require("e-ink").setup() - use_theme("e-ink") - end, ashen = function() use_theme("ashen") end, From e25c8cef522b9e2700ec2e40f6e4fb71491ef343 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 6 Feb 2026 20:48:41 +0100 Subject: [PATCH 178/247] use dashboard from snacks.nvim (#463) --- lua/config/dashboard-nvim.lua | 117 ---------------------------------- lua/config/snacks.lua | 55 ++++++++++++++++ lua/plugin_specs.lua | 25 ++------ 3 files changed, 59 insertions(+), 138 deletions(-) delete mode 100644 lua/config/dashboard-nvim.lua create mode 100644 lua/config/snacks.lua diff --git a/lua/config/dashboard-nvim.lua b/lua/config/dashboard-nvim.lua deleted file mode 100644 index f5e55056..00000000 --- a/lua/config/dashboard-nvim.lua +++ /dev/null @@ -1,117 +0,0 @@ -local api = vim.api -local keymap = vim.keymap -local dashboard = require("dashboard") - -local conf = {} --- conf.header = { --- " ", --- " ", --- " ", --- " ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗", --- " ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║", --- " ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║", --- " ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║", --- " ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║", --- " ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝", --- " ", --- " ", --- " ", --- " ", --- } - -conf.header = { - " ", - " ", - " ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣿⣦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣨⣿⣿⠿⠻⣿⡀⠀⠀⠀⣠⣾⡟⢹⣶⣦⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⣿⠋⠀⢠⣿⣧⠀⠀⣴⣿⣿⣿⡟⠉⢿⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⡟⠀⣤⠉⣿⣿⠀⢠⣿⣿⣿⡟⠀⠀⢸⣿⣟⠂⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣺⣿⣿⠀⣰⣿⠀⣿⣿⠀⣾⣿⣿⡟⠀⣠⡄⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⠃⠀⣿⡏⢠⣿⣿⣤⣿⣿⣿⠁⢸⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣀⣼⣿⣷⣿⡿⣿⠿⠿⣿⣧⣠⣿⣿⢁⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⡿⣽⣿⣷⣶⡋⠂⠀⣊⠀⢉⠽⠻⢿⣿⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⢠⣞⣹⡿⣿⣿⣿⣿⣻⣿⣷⣧⣰⡀⠉⠀⢀⡠⠎⠩⣭⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⢠⠄⣰⠟⣻⣿⡿⢿⣿⣿⣿⣿⣷⣿⣿⣿⡇⠀⡙⣻⣦⠀⢸⣖⠒⠺⣷⡀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠠⠃⢸⣷⡿⠋⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣾⣿⡿⣿⣷⣏⠉⢛⣀⣼⡇⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⢠⣶⡟⢉⣴⣿⣿⣿⣿⣿⣿⣿⡿⠛⠛⠋⠉⠛⠻⢿⣿⣿⣽⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀", - "⠀⠀⠀⢰⡿⢟⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠙⠻⣿⣿⣽⣿⣷⠀⠀⠀⠀", - "⠀⠀⠀⡼⣷⣿⡟⣿⣿⣿⣿⣿⡟⠀⠀⠀⣀⠖⠰⢦⠤⠤⠀⠀⠀⠀⠀⠀⠀⢀⡸⣿⣿⣻⣿⣧⠀⠀⠀", - "⠀⠀⠀⢱⣿⣿⣿⣿⣿⣿⣿⣟⠀⠀⠀⢠⠏⠀⣾⡿⣷⡀⠀⠀⠀⠀⡾⠋⣩⡍⠁⢸⣿⣿⣻⣿⠀⠀⠀", - "⠀⠀⠀⡿⣿⣿⣿⣿⣿⣿⣿⣿⠰⡀⠀⢸⠀⢸⣿⣿⣿⠃⠀⠀⠀⢸⠃⢰⣿⣿⠀⢸⣿⣿⣿⣿⠄⠀⠀", - "⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⡇⠻⣄⠈⢧⠈⠿⠿⠋⠀⢠⣶⣤⣬⠀⢸⣿⡏⠀⢸⣿⣿⣿⠃⠀⠀⠀", - "⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣦⡈⠳⣄⡀⠀⠀⠀⠀⠀⠙⠉⠀⠁⠘⠛⢁⣰⣿⣿⣿⣿⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⣉⡳⠶⠤⣤⣀⣀⣀⣀⣀⣤⣶⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠉⠻⣿⣿⣿⣿⣍⣿⣿⣿⣿⣿⣿⣶⣶⣶⣿⣿⣿⣷⣾⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣤⣄⣀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⢰⣤⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢧⢄⠀⠀", - "⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⣿⣿⡗⢤⢤⠾⠀", - "⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣽⣿⣿⣿⣿⣿⣿⣿⣿⠟⠀⠀⠀", - "⠀⠀⠀⠀⣸⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⠻⠟⠋⠁⠀⠀⠀⠀", - "⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⢀⣴⣟⠁⢸⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀", - "⢠⡾⠟⠛⠙⠳⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠰⢆⡀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⢀⣀⡉⢓⣦⣠⣴⠾⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀", - "⠀⠰⣤⣥⣼⣿⣿⡏⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠄⠀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠘⠹⠛⠻⠛⠃⣾⣿⣿⡿⣿⣿⣿⣿⣿⣿⣿⣟⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⣀⠀⠀⠀⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠋⠋⠙⣿⠻⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⣿⣯⣥⣤⣬⣽⡿⢻⣿⡏⡂⠀⠀⠀", - "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠏⠛⠻⠿⡿⣿⡟⢺⣿⣿⡿⠛⠛⢃⣘⠛⠛⠟⠛⠛⠻⢿⢿⠏⠙⠜⣷⢞⠂", - "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠆⠀⠀⠀⠁⠈⠁⢨⠭⣉⠀⠀⠀⢈⠁⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀", - " ", - " ", -} - -conf.center = { - { - icon = "󰈞 ", - desc = "Find File ", - action = "FzfLua files", - key = " f f", - }, - { - icon = "󰈢 ", - desc = "Recently opened files ", - action = "FzfLua oldfiles", - key = " f r", - }, - { - icon = "󰈬 ", - desc = "Project grep ", - action = "FzfLua live_grep", - key = " f g", - }, - { - icon = " ", - desc = "Open Nvim config ", - action = "tabnew $MYVIMRC | tcd %:p:h", - key = " e v", - }, - { - icon = " ", - desc = "New file ", - action = "enew", - key = "e", - }, - { - icon = "󰗼 ", - desc = "Quit Nvim ", - -- desc = "Quit Nvim ", - action = "qa", - key = "q", - }, -} - -dashboard.setup { - theme = "doom", - shortcut_type = "number", - config = conf, -} - -api.nvim_create_autocmd("FileType", { - pattern = "dashboard", - group = api.nvim_create_augroup("dashboard_enter", { clear = true }), - callback = function() - keymap.set("n", "q", ":qa", { buffer = true, silent = true }) - keymap.set("n", "e", ":enew", { buffer = true, silent = true }) - end, -}) diff --git a/lua/config/snacks.lua b/lua/config/snacks.lua new file mode 100644 index 00000000..78a57c8a --- /dev/null +++ b/lua/config/snacks.lua @@ -0,0 +1,55 @@ +require("snacks").setup { + -- more beautiful vim.ui.input + input = { + enabled = true, + win = { + relative = "cursor", + backdrop = true, + }, + }, + -- more beautiful vim.ui.select + picker = { enabled = true }, + -- startup dashboard + dashboard = { + enabled = true, + preset = { + header = [[ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣿⣦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣨⣿⣿⠿⠻⣿⡀⠀⠀⠀⣠⣾⡟⢹⣶⣦⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⣿⠋⠀⢠⣿⣧⠀⠀⣴⣿⣿⣿⡟⠉⢿⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⡟⠀⣤⠉⣿⣿⠀⢠⣿⣿⣿⡟⠀⠀⢸⣿⣟⠂⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣺⣿⣿⠀⣰⣿⠀⣿⣿⠀⣾⣿⣿⡟⠀⣠⡄⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⠃⠀⣿⡏⢠⣿⣿⣤⣿⣿⣿⠁⢸⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣀⣼⣿⣷⣿⡿⣿⠿⠿⣿⣧⣠⣿⣿⢁⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⡿⣽⣿⣷⣶⡋⠂⠀⣊⠀⢉⠽⠻⢿⣿⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⢠⣞⣹⡿⣿⣿⣿⣿⣻⣿⣷⣧⣰⡀⠉⠀⢀⡠⠎⠩⣭⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⢠⠄⣰⠟⣻⣿⡿⢿⣿⣿⣿⣿⣷⣿⣿⣿⡇⠀⡙⣻⣦⠀⢸⣖⠒⠺⣷⡀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠠⠃⢸⣷⡿⠋⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣾⣿⡿⣿⣷⣏⠉⢛⣀⣼⡇⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⢠⣶⡟⢉⣴⣿⣿⣿⣿⣿⣿⣿⡿⠛⠛⠋⠉⠛⠻⢿⣿⣿⣽⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀ +⠀⠀⠀⢰⡿⢟⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠙⠻⣿⣿⣽⣿⣷⠀⠀⠀⠀ +⠀⠀⠀⡼⣷⣿⡟⣿⣿⣿⣿⣿⡟⠀⠀⠀⣀⠖⠰⢦⠤⠤⠀⠀⠀⠀⠀⠀⠀⢀⡸⣿⣿⣻⣿⣧⠀⠀⠀ +⠀⠀⠀⢱⣿⣿⣿⣿⣿⣿⣿⣟⠀⠀⠀⢠⠏⠀⣾⡿⣷⡀⠀⠀⠀⠀⡾⠋⣩⡍⠁⢸⣿⣿⣻⣿⠀⠀⠀ +⠀⠀⠀⡿⣿⣿⣿⣿⣿⣿⣿⣿⠰⡀⠀⢸⠀⢸⣿⣿⣿⠃⠀⠀⠀⢸⠃⢰⣿⣿⠀⢸⣿⣿⣿⣿⠄⠀⠀ +⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⡇⠻⣄⠈⢧⠈⠿⠿⠋⠀⢠⣶⣤⣬⠀⢸⣿⡏⠀⢸⣿⣿⣿⠃⠀⠀⠀ +⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣦⡈⠳⣄⡀⠀⠀⠀⠀⠀⠙⠉⠀⠁⠘⠛⢁⣰⣿⣿⣿⣿⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⣉⡳⠶⠤⣤⣀⣀⣀⣀⣀⣤⣶⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠉⠻⣿⣿⣿⣿⣍⣿⣿⣿⣿⣿⣿⣶⣶⣶⣿⣿⣿⣷⣾⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣤⣄⣀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⢰⣤⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢧⢄⠀⠀ +⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⣿⣿⡗⢤⢤⠾⠀ +⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣽⣿⣿⣿⣿⣿⣿⣿⣿⠟⠀⠀⠀ +⠀⠀⠀⠀⣸⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⠻⠟⠋⠁⠀⠀⠀⠀ +⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⢀⣴⣟⠁⢸⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀ +⢠⡾⠟⠛⠙⠳⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠰⢆⡀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⢀⣀⡉⢓⣦⣠⣴⠾⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠰⣤⣥⣼⣿⣿⡏⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠄⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠘⠹⠛⠻⠛⠃⣾⣿⣿⡿⣿⣿⣿⣿⣿⣿⣿⣟⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⣀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠋⠋⠙⣿⠻⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⣿⣯⣥⣤⣬⣽⡿⢻⣿⡏⡂⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠏⠛⠻⠿⡿⣿⡟⢺⣿⣿⡿⠛⠛⢃⣘⠛⠛⠟⠛⠛⠻⢿⢿⠏⠙⠜⣷⢞⠂ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠆⠀⠀⠀⠁⠈⠁⢨⠭⣉⠀⠀⠀⢈⠁⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀ + ]], + }, + }, +} diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index f3256fba..620e3b5d 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -185,15 +185,6 @@ local plugin_specs = { end, }, - -- fancy start screen - { - "nvimdev/dashboard-nvim", - cond = firenvim_not_active, - config = function() - require("config.dashboard-nvim") - end, - }, - { "nvim-mini/mini.indentscope", version = false, @@ -683,18 +674,10 @@ local plugin_specs = { "folke/snacks.nvim", priority = 1000, lazy = false, - opts = { - -- more beautiful vim.ui.input - input = { - enabled = true, - win = { - relative = "cursor", - backdrop = true, - }, - }, - -- more beautiful vim.ui.select - picker = { enabled = true }, - }, + opts = {}, + config = function() + require("config.snacks") + end, }, -- show and trim trailing whitespaces { "jdhao/whitespace.nvim", event = "VeryLazy" }, From 8e4bf54eff4dec802344963409fea885d007b8a9 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 6 Feb 2026 21:12:44 +0100 Subject: [PATCH 179/247] always check if the partial cmd is valid --- lua/custom-autocmd.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 94a84a0c..29b43506 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -259,21 +259,28 @@ local ft_to_command = { api.nvim_create_autocmd("BufWritePost", { group = api.nvim_create_augroup("format check", { clear = true }), - pattern = { "*.py", "*.lua" }, + pattern = { "*" }, desc = "Check if file needs reformat", callback = function(ev) local fpath = ev.file local ft = vim.api.nvim_get_option_value("filetype", { buf = ev.buf }) - local cmd = vim.deepcopy(ft_to_command[ft]) - table.insert(cmd, fpath) + + local cmd_partial = ft_to_command[ft] + local cmd = nil + if cmd_partial ~= nil then + cmd = vim.deepcopy(cmd_partial) + table.insert(cmd, fpath) + else + return + end local exe_path = cmd[1] if not utils.executable(exe_path) then + vim.print(string.format("%s not found!", exe_path)) return end local result = vim.system(cmd, { text = true }):wait() - if result.code ~= 0 then vim.notify("This file is not formatted!") end From 310e922b246a15faa3884a1ffcdca247fd0745a1 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 8 Feb 2026 17:42:26 +0100 Subject: [PATCH 180/247] update dict --- spell/en.utf-8.add | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spell/en.utf-8.add b/spell/en.utf-8.add index da182b78..6da520ea 100644 --- a/spell/en.utf-8.add +++ b/spell/en.utf-8.add @@ -476,3 +476,22 @@ Kubernetes pubsub Luarocks luarocks +pytest +conftest +pytest +rootdir +pythonpath +py +#armin +Garmin/! +Garmin +garmin +MTP +openMTP +MacBook +Komoot +JVM +Lucene +replia +#hitespaces +whitespaces/! From 148bee99c8482d63932ab98bf3b74b2a275572a4 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 8 Feb 2026 17:42:53 +0100 Subject: [PATCH 181/247] enable autoread by default --- viml_conf/options.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/viml_conf/options.vim b/viml_conf/options.vim index a046e6be..1fc0289d 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -93,6 +93,9 @@ set list listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:␣ " Auto-write the file based on some condition set autowrite +" Auto reload file if changed outside nvim +set autoread + " Show hostname, full path of file and last-mod time on the window title. The " meaning of the format str for strftime can be found in " http://man7.org/linux/man-pages/man3/strftime.3.html. The function to get From c077baaa9bcc7bc5085a17c8c6389da0a21b759d Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 8 Feb 2026 18:31:48 +0100 Subject: [PATCH 182/247] migrate options.vim to lua module (#464) --- autoload/utils.vim | 15 --- init.lua | 5 +- lua/options.lua | 250 ++++++++++++++++++++++++++++++++++++++++++ lua/utils.lua | 19 ++++ viml_conf/options.vim | 195 -------------------------------- 5 files changed, 270 insertions(+), 214 deletions(-) create mode 100644 lua/options.lua delete mode 100644 viml_conf/options.vim diff --git a/autoload/utils.vim b/autoload/utils.vim index 14fb651e..a157d25e 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -94,21 +94,6 @@ function! utils#MoveSelection(direction) abort endfunction -function! utils#Get_titlestr() abort - let l:title_str = '' - if g:is_linux - let l:title_str = hostname() . ' ' - endif - - let l:buf_path = expand('%:p:~') - let l:title_str = l:title_str . l:buf_path . ' ' - if &buflisted && l:buf_path != "" - let l:title_str = l:title_str . strftime('%Y-%m-%d %H:%M:%S%z', getftime(expand('%'))) - endif - - return l:title_str -endfunction - " Output current time or unix timestamp in human-readable format. function! utils#iso_time(timestamp) abort " Get current datetime diff --git a/init.lua b/init.lua index 4f475ce5..41d9b849 100644 --- a/init.lua +++ b/init.lua @@ -16,13 +16,10 @@ local utils = require("utils") local expected_version = "0.11.6" utils.is_compatible_version(expected_version) -local config_dir = vim.fn.stdpath("config") ----@cast config_dir string - -- some global settings require("globals") -- setting options in nvim -vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/options.vim")) +require("options") -- various autocommands require("custom-autocmd") -- all the user-defined mappings diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 00000000..60cd8450 --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,250 @@ +local utils = require("utils") + +local fn = vim.fn +local opt = vim.opt +local o = vim.o + +-- Change fillchars for folding, vertical split, end of buffer, and message separator +opt.fillchars = { + fold = " ", + foldsep = " ", + foldopen = "", + foldclose = "", + vert = "│", + eob = " ", + msgsep = "‾", + diff = "╱", +} + +-- Split window below/right when creating horizontal/vertical windows +opt.splitbelow = true +opt.splitright = true + +-- Avoid the flickering when splitting window horizontal +opt.splitkeep = "screen" + +-- Time in milliseconds to wait for a mapped sequence to complete, +-- see https://unix.stackexchange.com/q/36882/221410 for more info +opt.timeoutlen = 500 + +opt.updatetime = 500 -- For CursorHold events + +-- Clipboard settings, always use clipboard for all delete, yank, change, put +-- operation, see https://stackoverflow.com/q/30691466/6064933 +if fn["provider#clipboard#Executable"]() ~= "" then + opt.clipboard:append("unnamedplus") +end + +-- Disable creating swapfiles, see https://stackoverflow.com/q/821902/6064933 +opt.swapfile = false + +-- Ignore certain files and folders when globbing +opt.wildignore:append { + "*.o", + "*.obj", + "*.dylib", + "*.bin", + "*.dll", + "*.exe", + "*/.git/*", + "*/.svn/*", + "*/__pycache__/*", + "*/build/**", + "*.jpg", + "*.png", + "*.jpeg", + "*.bmp", + "*.gif", + "*.tiff", + "*.svg", + "*.ico", + "*.pyc", + "*.pkl", + "*.DS_Store", + "*.aux", + "*.bbl", + "*.blg", + "*.brf", + "*.fls", + "*.fdb_latexmk", + "*.synctex.gz", + "*.xdv", +} +opt.wildignorecase = true -- Ignore file and dir name cases in cmd-completion + +-- Set up backup directory +vim.g.backupdir = fn.stdpath("data") .. "/backup//" +opt.backupdir = vim.g.backupdir + +-- Skip backup for patterns in option wildignore +opt.backupskip = o.wildignore +opt.backup = true -- Create backup for files +opt.backupcopy = "yes" -- Copy the original file to backupdir and overwrite it + +-- General tab settings +opt.tabstop = 2 -- Number of visual spaces per TAB +opt.softtabstop = 2 -- Number of spaces in tab when editing +opt.shiftwidth = 2 -- Number of spaces to use for autoindent +opt.expandtab = true -- Expand tab to spaces so that tabs are spaces + +-- Set matching pairs of characters and highlight matching brackets +opt.matchpairs:append { + "<:>", + "「:」", + "『:』", + "【:】", + '":"', + "':'", + "《:》", +} + +-- Show line number and relative line number +opt.number = true +opt.relativenumber = true + +-- Ignore case in general, but become case-sensitive when uppercase is present +opt.ignorecase = true +opt.smartcase = true + +-- File and script encoding settings for vim +opt.fileencoding = "utf-8" +opt.fileencodings = { "ucs-bom", "utf-8", "cp936", "gb18030", "big5", "euc-jp", "euc-kr", "latin1" } + +-- Break line at predefined characters +opt.linebreak = true +-- Character to show before the lines that have been soft-wrapped +opt.showbreak = "↪" + +-- List all matches and complete till longest common string +opt.wildmode = "list:longest" + +-- Minimum lines to keep above and below cursor when scrolling +opt.scrolloff = 3 + +-- Use mouse to select and resize windows, etc. +opt.mouse = "n" +opt.mousemodel = "popup" -- Set the behaviour of mouse +opt.mousescroll = { "ver:1", "hor:0" } + +-- Disable showing current mode on command line since statusline plugins can show it. +opt.showmode = false + +opt.fileformats = { "unix", "dos" } -- Fileformats to use for new files + +-- Ask for confirmation when handling unsaved or read-only files +opt.confirm = true + +opt.visualbell = true +opt.errorbells = false -- Do not use visual and errorbells +opt.history = 500 -- The number of command and search history to keep + +-- Use list mode and customized listchars +opt.list = true +opt.listchars = { + tab = "▸ ", + extends = "❯", + precedes = "❮", + nbsp = "␣", +} + +-- Auto-write the file based on some condition +opt.autowrite = true + +-- Auto reload file if changed outside nvim +opt.autoread = true + +-- Show hostname, full path of file and last-mod time on the window title. +-- The meaning of the format str for strftime can be found in +-- http://man7.org/linux/man-pages/man3/strftime.3.html. The function to get +-- lastmod time is drawn from https://stackoverflow.com/q/8426736/6064933 +opt.title = true +o.titlestring = "%{v:lua.require('utils').get_titlestr()}" + +-- Persistent undo even after you close a file and re-open it +opt.undofile = true + +-- Do not show "match xx of xx" and other messages during auto-completion +-- Do not show search match count on bottom right (seriously, I would strain my +-- neck looking at it). Using plugins like vim-anzu or nvim-hlslens is a better +-- choice, IMHO. +-- Disable showing intro message (:intro) +opt.shortmess:append("cSI") + +opt.messagesopt = "hit-enter,history:500" + +-- Completion behaviour +opt.completeopt:append("menuone") -- Show menu even if there is only one item +opt.completeopt:remove("preview") -- Disable the preview window + +opt.pumheight = 10 -- Maximum number of items to show in popup menu +opt.pumblend = 5 -- Pseudo transparency for completion menu + +opt.winblend = 0 -- Pseudo transparency for floating window +opt.winborder = "none" + +-- Insert mode key word completion setting +opt.complete:append("kspell") +opt.complete:remove { "w", "b", "u", "t" } + +opt.spelllang = { "en", "cjk" } -- Spell languages +opt.spellsuggest:append("9") -- Show 9 spell suggestions at most + +-- Align indent to next multiple value of shiftwidth. For its meaning, +-- see http://vim.1045645.n5.nabble.com/shiftround-option-td5712100.html +opt.shiftround = true + +opt.virtualedit = "block" -- Virtual edit is useful for visual block edit + +-- Correctly break multi-byte characters such as CJK, +-- see https://stackoverflow.com/q/32669814/6064933 +opt.formatoptions:append("mM") + +-- Tilde (~) is an operator, thus must be followed by motions like `e` or `w`. +opt.tildeop = true + +opt.synmaxcol = 250 -- Text after this column number is not highlighted +opt.startofline = false + +-- External program to use for grep command +if utils.executable("rg") then + opt.grepprg = "rg --vimgrep --no-heading --smart-case" + opt.grepformat = "%f:%l:%c:%m" +end + +-- Enable true color support. Do not set this option if your terminal does not +-- support true colors! For a comprehensive list of terminals supporting true +-- colors, see https://github.com/termstandard/colors and https://gist.github.com/XVilka/8346728. +opt.termguicolors = true + +-- Set up cursor color and shape in various mode, ref: +-- https://github.com/neovim/neovim/wiki/FAQ#how-to-change-cursor-color-in-the-terminal +opt.guicursor = "n-v-c:block-Cursor/lCursor,i-ci-ve:ver25-Cursor2/lCursor2,r-cr:hor20,o:hor20" + +opt.signcolumn = "yes:1" + +-- Remove certain character from file name pattern matching +opt.isfname:remove { "=", "," } + +-- diff options +opt.diffopt = { + "vertical", -- Show diff in vertical position + "filler", -- Show filler for deleted lines + "closeoff", -- Turn off diff when one file window is closed + "context:3", -- Context for diff + "internal", + "indent-heuristic", + "algorithm:histogram", +} +-- inline diff makes changes in a line more noticeable, the author suggests to +-- remove linematch option if you use inline option, see also +-- https://www.reddit.com/r/neovim/comments/1myfvla/comment/najy4s3/ +if fn.has("nvim-0.12") == 1 then + opt.diffopt:append("inline:char") +else + opt.diffopt:append("linematch:60") +end + +opt.wrap = false -- Do not wrap +opt.ruler = false + +opt.showcmdloc = "statusline" diff --git a/lua/utils.lua b/lua/utils.lua index f9963e71..fe42f075 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -92,4 +92,23 @@ function M.inside_git_repo() return true end +--- Get custom title string for the window title. +--- Shows hostname (on Linux), buffer path, and last modified time. +--- @return string +function M.get_titlestr() + local title_str = "" + if vim.g.is_linux then + title_str = vim.fn.hostname() .. " " + end + + local buf_path = vim.fn.expand("%:p:~") + title_str = title_str .. buf_path .. " " + if vim.bo.buflisted and buf_path ~= "" then + local mod_time = vim.fn.strftime("%Y-%m-%d %H:%M:%S%z", vim.fn.getftime(vim.fn.expand("%"))) + title_str = title_str .. mod_time + end + + return title_str +end + return M diff --git a/viml_conf/options.vim b/viml_conf/options.vim deleted file mode 100644 index 1fc0289d..00000000 --- a/viml_conf/options.vim +++ /dev/null @@ -1,195 +0,0 @@ -scriptencoding utf-8 - -" change fillchars for folding, vertical split, end of buffer, and message separator -set fillchars=fold:\ ,foldsep:\ ,foldopen:,foldclose:,vert:\│,eob:\ ,msgsep:‾,diff:╱ - -" Split window below/right when creating horizontal/vertical windows -set splitbelow splitright - -" avoid the flickering when splitting window horizontal -set splitkeep=screen - -" Time in milliseconds to wait for a mapped sequence to complete, -" see https://unix.stackexchange.com/q/36882/221410 for more info -set timeoutlen=500 - -set updatetime=500 " For CursorHold events - -" Clipboard settings, always use clipboard for all delete, yank, change, put -" operation, see https://stackoverflow.com/q/30691466/6064933 -if !empty(provider#clipboard#Executable()) - set clipboard+=unnamedplus -endif - -" Disable creating swapfiles, see https://stackoverflow.com/q/821902/6064933 -set noswapfile - -" Ignore certain files and folders when globing -set wildignore+=*.o,*.obj,*.dylib,*.bin,*.dll,*.exe -set wildignore+=*/.git/*,*/.svn/*,*/__pycache__/*,*/build/** -set wildignore+=*.jpg,*.png,*.jpeg,*.bmp,*.gif,*.tiff,*.svg,*.ico -set wildignore+=*.pyc,*.pkl -set wildignore+=*.DS_Store -set wildignore+=*.aux,*.bbl,*.blg,*.brf,*.fls,*.fdb_latexmk,*.synctex.gz,*.xdv -set wildignorecase " ignore file and dir name cases in cmd-completion - -" Set up backup directory -let g:backupdir=expand(stdpath('data') . '/backup//') -let &backupdir=g:backupdir - -" Skip backup for patterns in option wildignore -let &backupskip=&wildignore -set backup " create backup for files -set backupcopy=yes " copy the original file to backupdir and overwrite it - -" General tab settings -set tabstop=2 " number of visual spaces per TAB -set softtabstop=2 " number of spaces in tab when editing -set shiftwidth=2 " number of spaces to use for autoindent -set expandtab " expand tab to spaces so that tabs are spaces - -" Set matching pairs of characters and highlight matching brackets -set matchpairs+=<:>,「:」,『:』,【:】,“:”,‘:’,《:》 - -set number relativenumber " Show line number and relative line number - -" Ignore case in general, but become case-sensitive when uppercase is present -set ignorecase smartcase - -" File and script encoding settings for vim -set fileencoding=utf-8 -set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1 - -" Break line at predefined characters -set linebreak -" Character to show before the lines that have been soft-wrapped -set showbreak=↪ - -" List all matches and complete till longest common string -set wildmode=list:longest - -" Minimum lines to keep above and below cursor when scrolling -set scrolloff=3 - -" Use mouse to select and resize windows, etc. -set mouse=n -set mousemodel=popup " Set the behaviour of mouse -set mousescroll=ver:1,hor:0 - -" Disable showing current mode on command line since statusline plugins can show it. -set noshowmode - -set fileformats=unix,dos " Fileformats to use for new files - -" Ask for confirmation when handling unsaved or read-only files -set confirm - -set visualbell noerrorbells " Do not use visual and errorbells -set history=500 " The number of command and search history to keep - -" Use list mode and customized listchars -set list listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:␣ - -" Auto-write the file based on some condition -set autowrite - -" Auto reload file if changed outside nvim -set autoread - -" Show hostname, full path of file and last-mod time on the window title. The -" meaning of the format str for strftime can be found in -" http://man7.org/linux/man-pages/man3/strftime.3.html. The function to get -" lastmod time is drawn from https://stackoverflow.com/q/8426736/6064933 -set title -set titlestring= -set titlestring=%{utils#Get_titlestr()} - -" Persistent undo even after you close a file and re-open it -set undofile - -" Do not show "match xx of xx" and other messages during auto-completion -set shortmess+=c - -" Do not show search match count on bottom right (seriously, I would strain my -" neck looking at it). Using plugins like vim-anzu or nvim-hlslens is a better -" choice, IMHO. -set shortmess+=S - -" Disable showing intro message (:intro) -set shortmess+=I - -set messagesopt=hit-enter,history:500 - -" Completion behaviour -" set completeopt+=noinsert " Auto select the first completion entry -set completeopt+=menuone " Show menu even if there is only one item -set completeopt-=preview " Disable the preview window - -set pumheight=10 " Maximum number of items to show in popup menu -set pumblend=5 " pseudo transparency for completion menu - -set winblend=0 " pseudo transparency for floating window -set winborder=none - -" Insert mode key word completion setting -set complete+=kspell complete-=w complete-=b complete-=u complete-=t - -set spelllang=en,cjk " Spell languages -set spellsuggest+=9 " show 9 spell suggestions at most - -" Align indent to next multiple value of shiftwidth. For its meaning, -" see http://vim.1045645.n5.nabble.com/shiftround-option-td5712100.html -set shiftround - -set virtualedit=block " Virtual edit is useful for visual block edit - -" Correctly break multi-byte characters such as CJK, -" see https://stackoverflow.com/q/32669814/6064933 -set formatoptions+=mM - -" Tilde (~) is an operator, thus must be followed by motions like `e` or `w`. -set tildeop - -set synmaxcol=250 " Text after this column number is not highlighted -set nostartofline - -" External program to use for grep command -if executable('rg') - set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case - set grepformat=%f:%l:%c:%m -endif - -" Enable true color support. Do not set this option if your terminal does not -" support true colors! For a comprehensive list of terminals supporting true -" colors, see https://github.com/termstandard/colors and https://gist.github.com/XVilka/8346728. -set termguicolors - -" Set up cursor color and shape in various mode, ref: -" https://github.com/neovim/neovim/wiki/FAQ#how-to-change-cursor-color-in-the-terminal -set guicursor=n-v-c:block-Cursor/lCursor,i-ci-ve:ver25-Cursor2/lCursor2,r-cr:hor20,o:hor20 - -set signcolumn=yes:1 - -" Remove certain character from file name pattern matching -set isfname-== -set isfname-=, - -" diff options -set diffopt= -set diffopt+=vertical " show diff in vertical position -set diffopt+=filler " show filler for deleted lines -set diffopt+=closeoff " turn off diff when one file window is closed -set diffopt+=context:3 " context for diff -set diffopt+=internal,indent-heuristic,algorithm:histogram -" inline diff makes changes in a line more noticeable, the author suggests to -" remove linematch option if you use inline option, see also https://www.reddit.com/r/neovim/comments/1myfvla/comment/najy4s3/ -if has('nvim-0.12') - set diffopt+=inline:char -else - set diffopt+=linematch:60 -endif - -set nowrap " do no wrap -set noruler - -set showcmdloc=statusline From d88eb433ba91b62b75ff38b29452ed95cd99de1c Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 14 Feb 2026 12:05:29 +0100 Subject: [PATCH 183/247] update conf for blink-cmp (#465) --- lua/config/blink-cmp.lua | 51 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/lua/config/blink-cmp.lua b/lua/config/blink-cmp.lua index ae50aadc..ac83c630 100644 --- a/lua/config/blink-cmp.lua +++ b/lua/config/blink-cmp.lua @@ -29,7 +29,56 @@ require("blink.cmp").setup { -- Default list of enabled providers defined so that you can extend it -- elsewhere in your config, without redefining it, due to `opts_extend` sources = { - default = { "lsp", "path", "buffer" }, + default = { "lsp", "path", "buffer", "omni" }, + providers = { + -- Use the thesaurus source + thesaurus = { + name = "blink-cmp-words", + module = "blink-cmp-words.thesaurus", + -- All available options + opts = { + -- A score offset applied to returned items. + -- By default the highest score is 0 (item 1 has a score of -1, item 2 of -2 etc..). + score_offset = 0, + + -- Default pointers define the lexical relations listed under each definition, + -- see Pointer Symbols below. + -- Default is as below ("antonyms", "similar to" and "also see"). + definition_pointers = { "!", "&", "^" }, + + -- The pointers that are considered similar words when using the thesaurus, + -- see Pointer Symbols below. + -- Default is as below ("similar to", "also see" } + similarity_pointers = { "&", "^" }, + + -- The depth of similar words to recurse when collecting synonyms. 1 is similar words, + -- 2 is similar words of similar words, etc. Increasing this may slow results. + similarity_depth = 2, + }, + }, + + -- Use the dictionary source + dictionary = { + name = "blink-cmp-words", + module = "blink-cmp-words.dictionary", + -- All available options + opts = { + -- The number of characters required to trigger completion. + -- Set this higher if completion is slow, 3 is default. + dictionary_search_threshold = 3, + + -- See above + score_offset = 0, + + -- See above + definition_pointers = { "!", "&", "^" }, + }, + }, + }, + per_filetype = { + text = { "dictionary" }, + markdown = { "dictionary" }, + }, }, -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance From 6cced23b2a189837c2f6c58d510dbbf16fd8870f Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 14 Feb 2026 12:06:10 +0100 Subject: [PATCH 184/247] fix function style --- lua/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/utils.lua b/lua/utils.lua index fe42f075..9a70ab0d 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -13,7 +13,7 @@ end --- check whether a feature exists in Nvim --- @param feat string the feature name, like `nvim-0.7` or `unix`. --- @return boolean -M.has = function(feat) +function M.has(feat) if fn.has(feat) == 1 then return true end From e8f955293d2ab3efa5c9c0c17250bd04a1dbff5b Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 14 Feb 2026 12:23:41 +0100 Subject: [PATCH 185/247] Add opencode.nvim --- lua/plugin_specs.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 620e3b5d..82b30d47 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -39,7 +39,10 @@ local plugin_specs = { -- { -- "saghen/blink.cmp", -- -- optional: provides snippets for the snippet source - -- dependencies = { "rafamadriz/friendly-snippets" }, + -- dependencies = { + -- "rafamadriz/friendly-snippets", + -- "archie-judd/blink-cmp-words", + -- }, -- -- use a release tag to download pre-built binaries -- version = "1.*", -- config = function() @@ -744,6 +747,18 @@ local plugin_specs = { ---@type quicker.SetupOptions opts = {}, }, + { + "nickjvandyke/opencode.nvim", + config = function() + ---@type opencode.Opts + vim.g.opencode_opts = { + -- Your configuration, if any — see `lua/opencode/config.lua`, or "goto definition" on the type or field. + } + + -- Required for `opts.events.reload`. + vim.o.autoread = true + end, + }, } require("lazy").setup { From d6387f9bd7df61337658ccad7eec673d141e2341 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 14 Feb 2026 12:58:55 +0100 Subject: [PATCH 186/247] Add vim-illuminate to highlight cursor word (#466) --- lua/config/lsp.lua | 20 -------------------- lua/custom-autocmd.lua | 4 ++++ lua/plugin_specs.lua | 4 ++++ 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 96d300e6..8a683793 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -86,26 +86,6 @@ vim.api.nvim_create_autocmd("LspAttach", { -- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint, -- but disable this feature by default, so you may need to enable inlay hint in the LSP server config. -- vim.lsp.inlay_hint.enable(true, {buffer=bufnr}) - - -- The blow command will highlight the current variable and its usages in the buffer. - if client.server_capabilities.documentHighlightProvider then - local gid = vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true }) - vim.api.nvim_create_autocmd("CursorHold", { - group = gid, - buffer = bufnr, - callback = function() - vim.lsp.buf.document_highlight() - end, - }) - - vim.api.nvim_create_autocmd("CursorMoved", { - group = gid, - buffer = bufnr, - callback = function() - vim.lsp.buf.clear_references() - end, - }) - end end, nested = true, desc = "Configure buffer keymap and behavior based on LSP", diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 29b43506..5bc01d5d 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -187,6 +187,10 @@ api.nvim_create_autocmd("ColorScheme", { -- highlight for matching parentheses vim.api.nvim_set_hl(0, "MatchParen", { bold = true, underline = true }) + + vim.api.nvim_set_hl(0, "IlluminatedWordWrite", { underline = true, reverse = true }) + vim.api.nvim_set_hl(0, "IlluminatedWordRead", { underline = true, reverse = true }) + vim.api.nvim_set_hl(0, "IlluminatedWordText", { underline = true, reverse = true }) end, }) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 82b30d47..1c866e86 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -759,6 +759,10 @@ local plugin_specs = { vim.o.autoread = true end, }, + { + "RRethy/vim-illuminate", + event = "VeryLazy", + }, } require("lazy").setup { From aa9ce613ead160c3e8c073b86ff7900412bde35f Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 14 Feb 2026 13:13:56 +0100 Subject: [PATCH 187/247] update conf for vim-illuminate (#467) --- lua/plugin_specs.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 1c866e86..3618b358 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -750,6 +750,7 @@ local plugin_specs = { { "nickjvandyke/opencode.nvim", config = function() + ---@module "opencode" ---@type opencode.Opts vim.g.opencode_opts = { -- Your configuration, if any — see `lua/opencode/config.lua`, or "goto definition" on the type or field. @@ -762,6 +763,19 @@ local plugin_specs = { { "RRethy/vim-illuminate", event = "VeryLazy", + config = function() + require("illuminate").configure { + filetypes_denylist = {}, + filetypes_allowlist = { + "lua", + "python", + "sh", + "yaml", + "json", + "toml", + }, + } + end, }, } From 6d589efc008b3edc7abd86ea4529a3424cebe89f Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 14 Feb 2026 13:18:39 +0100 Subject: [PATCH 188/247] Update conf for vim-illuminate --- lua/plugin_specs.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 3618b358..07ba6dc2 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -774,6 +774,7 @@ local plugin_specs = { "json", "toml", }, + min_count_to_highlight = 2, } end, }, From 75bb903a5fd205ef700c568417c3041ff6a2d2de Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 28 Feb 2026 15:31:41 +0100 Subject: [PATCH 189/247] refactor: move python env extraction to a function (#469) --- lua/config/lualine.lua | 20 +++++--------------- lua/utils.lua | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index 414c5090..c1f18dd4 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -1,3 +1,4 @@ +local utils = require("utils") local fn = vim.fn -- cache for git states @@ -174,23 +175,12 @@ local diff = function() end local virtual_env = function() - -- only show virtual env for Python - if vim.bo.filetype ~= "python" then - return "" - end - - local conda_env = os.getenv("CONDA_DEFAULT_ENV") - local venv_path = os.getenv("VIRTUAL_ENV") + local venv_name = utils.get_virtual_env() - if venv_path == nil then - if conda_env == nil then - return "" - else - return string.format(" %s (conda)", conda_env) - end + if venv_name ~= "" then + return string.format(" (%s)", venv_name) else - local venv_name = vim.fn.fnamemodify(venv_path, ":t") - return string.format(" %s (venv)", venv_name) + return "" end end diff --git a/lua/utils.lua b/lua/utils.lua index 9a70ab0d..c9697e12 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -111,4 +111,24 @@ function M.get_titlestr() return title_str end +--- Get the current virtual env +--- @return string +function M.get_virtual_env() + local conda_env = os.getenv("CONDA_DEFAULT_ENV") + -- venv_path is the complete path to the virtual env + local venv_path = os.getenv("VIRTUAL_ENV") + + local venv_name = "" + + if venv_path == nil then + if conda_env ~= nil then + venv_name = conda_env + end + else + venv_name = vim.fn.fnamemodify(venv_path, ":t") + end + + return venv_name +end + return M From 9fcf680a57f840a41ea09ab8fd1722f5a3552734 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 28 Feb 2026 15:35:36 +0100 Subject: [PATCH 190/247] migrate python filetype conf to lua (#470) --- after/ftplugin/python.lua | 67 +++++++++++++++++++++++++++++++++++++++ after/ftplugin/python.vim | 16 ---------- 2 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 after/ftplugin/python.lua delete mode 100644 after/ftplugin/python.vim diff --git a/after/ftplugin/python.lua b/after/ftplugin/python.lua new file mode 100644 index 00000000..abc420ac --- /dev/null +++ b/after/ftplugin/python.lua @@ -0,0 +1,67 @@ +local utils = require("utils") +local opt = vim.opt + +opt.wrap = false +opt.sidescroll = 5 +opt.sidescrolloff = 2 +opt.colorcolumn = "100" + +opt.tabstop = 4 -- Number of visual spaces per TAB +opt.softtabstop = 4 -- Number of spaces in tab when editing +opt.shiftwidth = 4 -- Number of spaces to use for autoindent +opt.expandtab = true -- Expand tab to spaces so that tabs are spaces + +local get_proj_root = function() + local project_marker = { ".git", "pyproject.toml" } + local project_root = vim.fs.root(0, project_marker) + + return project_root +end + +local get_py_env = function() + local project_root = get_proj_root() + + local venv_name = utils.get_virtual_env() + + if venv_name ~= "" then + return "plain_venv" + end + + -- check if this is uv-managed project + local uv_lock_path = vim.fs.joinpath(project_root, "uv.lock") + if vim.fn.filereadable(uv_lock_path) == 1 then + return "uv" + end + + return "" +end + +local py_env = get_py_env() + +if vim.fn.exists(":AsyncRun") == 2 then + local py_cmd = "python" + + if py_env == "uv" then + py_cmd = "uv run python" + end + + local rhs = string.format(":AsyncRun %s -u %%", py_cmd) + + vim.keymap.set("n", "", rhs, { + buffer = true, + silent = true, + }) +end + +-- format current file + +local py_fmt_cmd = "!black" +if py_env == "uv" then + py_fmt_cmd = "!uv run black" +end + +local rhs = string.format("silent %s %%", py_fmt_cmd) +vim.keymap.set("n", "f", rhs, { + buffer = true, + silent = true, +}) diff --git a/after/ftplugin/python.vim b/after/ftplugin/python.vim deleted file mode 100644 index 49563df5..00000000 --- a/after/ftplugin/python.vim +++ /dev/null @@ -1,16 +0,0 @@ -if exists(':AsyncRun') - nnoremap :AsyncRun python -u "%" -endif - -" Do not wrap Python source code. -set nowrap -set sidescroll=5 -set sidescrolloff=2 -set colorcolumn=100 - -set tabstop=4 " number of visual spaces per TAB -set softtabstop=4 " number of spaces in tab when editing -set shiftwidth=4 " number of spaces to use for autoindent -set expandtab " expand tab to spaces so that tabs are spaces - -nnoremap f silent !black % From 9c256e7747bd055e7f6486f84c9db8bf8c0a4e9e Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 1 Mar 2026 23:36:08 +0100 Subject: [PATCH 191/247] migrate filetype conf for lua to lua script --- after/ftplugin/lua.lua | 11 +++++++++++ after/ftplugin/lua.vim | 7 ------- 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 after/ftplugin/lua.lua delete mode 100644 after/ftplugin/lua.vim diff --git a/after/ftplugin/lua.lua b/after/ftplugin/lua.lua new file mode 100644 index 00000000..ce4f1806 --- /dev/null +++ b/after/ftplugin/lua.lua @@ -0,0 +1,11 @@ +-- Disable inserting comment leader after hitting o/O/ +vim.opt_local.formatoptions:remove { "o", "r" } + +vim.keymap.set("n", "", "luafile %", { + buffer = true, + silent = true, +}) +vim.keymap.set("n", "f", "silent !stylua %", { + buffer = true, + silent = true, +}) diff --git a/after/ftplugin/lua.vim b/after/ftplugin/lua.vim deleted file mode 100644 index 1c60d66a..00000000 --- a/after/ftplugin/lua.vim +++ /dev/null @@ -1,7 +0,0 @@ -" Disable inserting comment leader after hitting o or O or -set formatoptions-=o -set formatoptions-=r - -nnoremap :luafile % - -nnoremap f silent !stylua % From d0fc0983f757aabc542d9107fbfc7b57361d1df3 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 12 Mar 2026 22:59:48 +0100 Subject: [PATCH 192/247] Remove plugin git-conflict.nvim (#471) --- lua/config/git-conflict.lua | 12 ------------ lua/plugin_specs.lua | 8 -------- 2 files changed, 20 deletions(-) delete mode 100644 lua/config/git-conflict.lua diff --git a/lua/config/git-conflict.lua b/lua/config/git-conflict.lua deleted file mode 100644 index 50688506..00000000 --- a/lua/config/git-conflict.lua +++ /dev/null @@ -1,12 +0,0 @@ -require("git-conflict").setup {} - -vim.api.nvim_create_autocmd("User", { - pattern = "GitConflictResolved", - callback = function() - -- clear qf list - vim.fn.setqflist({}, "r") - - -- reopen it? - vim.cmd([[silent! GitConflictListQf]]) - end, -}) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 07ba6dc2..859b9060 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -390,14 +390,6 @@ local plugin_specs = { -- Better git log display { "rbong/vim-flog", cmd = { "Flog" } }, - { - "akinsho/git-conflict.nvim", - version = "*", - event = "VeryLazy", - config = function() - require("config.git-conflict") - end, - }, { "ruifm/gitlinker.nvim", event = "User InGitRepo", From a14e86df037e4e2bfcd88d2eb416584aecfd52b0 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 12 Mar 2026 23:26:43 +0100 Subject: [PATCH 193/247] Remove plugin vim-snippets --- lua/plugin_specs.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 859b9060..ad3a2813 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -298,9 +298,6 @@ local plugin_specs = { let g:UltiSnipsSnippetDirectories=['UltiSnips', 'my_snippets'] ]]) end, - dependencies = { - "honza/vim-snippets", - }, event = "InsertEnter", }, From 72fbdef0b5facd24fc214ee9ca0815be21370c53 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 13 Mar 2026 23:20:22 +0100 Subject: [PATCH 194/247] update config for plugins (#472) --- lua/config/diffview.lua | 23 +++++++++++++++++++++++ lua/plugin_specs.lua | 9 ++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 lua/config/diffview.lua diff --git a/lua/config/diffview.lua b/lua/config/diffview.lua new file mode 100644 index 00000000..5c63469a --- /dev/null +++ b/lua/config/diffview.lua @@ -0,0 +1,23 @@ +local ok, diffview = pcall(require, "diffview") +if not ok then + return +end + +diffview.setup { + enhanced_diff_hl = true, + view = { + default = { + disable_diagnostics = true, + }, + merge_tool = { + layout = "diff3_mixed", + }, + }, + file_history_panel = { + win_config = { + type = "split", + position = "bottom", + height = 10, + }, + }, +} diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index ad3a2813..9e06fda7 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -408,6 +408,9 @@ local plugin_specs = { { "sindrets/diffview.nvim", cmd = { "DiffviewOpen" }, + config = function() + require("config.diffview") + end, }, { @@ -734,7 +737,11 @@ local plugin_specs = { event = "FileType qf", ---@module "quicker" ---@type quicker.SetupOptions - opts = {}, + opts = { + max_filename_width = function() + return math.floor(math.min(40, vim.o.columns / 2)) + end, + }, }, { "nickjvandyke/opencode.nvim", From 6894ecabd933cde6c09c4181a60198d40507fb5f Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 13 Mar 2026 23:35:47 +0100 Subject: [PATCH 195/247] update python filetype conf --- after/ftplugin/python.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/after/ftplugin/python.lua b/after/ftplugin/python.lua index abc420ac..9314539a 100644 --- a/after/ftplugin/python.lua +++ b/after/ftplugin/python.lua @@ -11,6 +11,11 @@ opt.softtabstop = 4 -- Number of spaces in tab when editing opt.shiftwidth = 4 -- Number of spaces to use for autoindent opt.expandtab = true -- Expand tab to spaces so that tabs are spaces +-- when we run `:compiler ruff`, then followed by `:make`, +-- Nvim will run ruff in the current directory. By default, `--preview` option is used. +-- The following option is used to customize the option passed to ruff. +vim.g.ruff_makeprg_params = "" + local get_proj_root = function() local project_marker = { ".git", "pyproject.toml" } local project_root = vim.fs.root(0, project_marker) @@ -20,6 +25,9 @@ end local get_py_env = function() local project_root = get_proj_root() + if project_root == nil then + return + end local venv_name = utils.get_virtual_env() From 081c79e947f0fd58aade87b723da76a3c8d53999 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 13 Mar 2026 23:36:13 +0100 Subject: [PATCH 196/247] disable normal mode map for backslash This will conflict with other normal mappings starting with backslash. It is better not to define normal mode map with just one character. --- after/ftplugin/markdown.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim index efea5e5a..9e4f2920 100644 --- a/after/ftplugin/markdown.vim +++ b/after/ftplugin/markdown.vim @@ -47,7 +47,7 @@ function! AddListSymbol(type, ...) abort endfunction " Add hard line breaks for Markdown -nnoremap \ :set operatorfunc=AddLineBreakg@ +" nnoremap \ :set operatorfunc=AddLineBreakg@ xnoremap \ : call AddLineBreak(visualmode(), 1) function! AddLineBreak(type, ...) abort From 4b0a929405ec4d4f45c121dfa3d160122b0036a2 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 14 Mar 2026 23:36:37 +0100 Subject: [PATCH 197/247] refactor: change lsp config location --- init.lua | 3 +++ lua/{config/lsp.lua => lsp_conf.lua} | 1 + lua/plugin_specs.lua | 3 --- 3 files changed, 4 insertions(+), 3 deletions(-) rename lua/{config/lsp.lua => lsp_conf.lua} (99%) diff --git a/init.lua b/init.lua index 41d9b849..ecd05247 100644 --- a/init.lua +++ b/init.lua @@ -28,6 +28,9 @@ require("mappings") -- all the plugins installed and their configurations require("plugin_specs") +-- This is done after plugin_specs, since lsp-config is loaded in that step +require("lsp_conf") + -- diagnostic related config require("diagnostic-conf") diff --git a/lua/config/lsp.lua b/lua/lsp_conf.lua similarity index 99% rename from lua/config/lsp.lua rename to lua/lsp_conf.lua index 8a683793..22c53a9b 100644 --- a/lua/config/lsp.lua +++ b/lua/lsp_conf.lua @@ -95,6 +95,7 @@ vim.api.nvim_create_autocmd("LspAttach", { local capabilities = require("lsp_utils").get_default_capabilities() +-- `*` will set default config for all lsp vim.lsp.config("*", { capabilities = capabilities, flags = { diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 9e06fda7..ae4e6770 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -52,9 +52,6 @@ local plugin_specs = { -- }, { "neovim/nvim-lspconfig", - config = function() - require("config.lsp") - end, }, { "dnlhc/glance.nvim", From 94d1ec5b41db032d8e79e299da302e1ff1af6bdb Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 15 Mar 2026 00:14:13 +0100 Subject: [PATCH 198/247] Add neovim runtime path to lua_ls library This will help lua_ls to index the runtime path, and autocompletion will also work. --- .luarc.jsonc | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .luarc.jsonc diff --git a/.luarc.jsonc b/.luarc.jsonc new file mode 100644 index 00000000..86e49684 --- /dev/null +++ b/.luarc.jsonc @@ -0,0 +1,4 @@ +{ + "runtime.version": "LuaJIT", + "workspace.library": ["$VIMRUNTIME/lua"] +} From d5718f1bce7e792a528ebc57417eea5761b516a7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 15 Mar 2026 00:15:44 +0100 Subject: [PATCH 199/247] Add treesitter support for diff --- lua/config/treesitter.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index fe31b12f..667c8f30 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -1,17 +1,18 @@ -- a list of filetypes to install treesitter parsers and queries local ensure_installed = { - "python", "cpp", - "lua", - "vim", - "json", - "toml", - "yaml", - "javascript", + "diff", "go", - "typescript", + "javascript", + "json", + "lua", "markdown", + "python", "sh", + "toml", + "typescript", + "vim", + "yaml", "zsh", } From 00793e710414e3ce9e017ddd56ba300cbd27b844 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 15 Mar 2026 00:18:35 +0100 Subject: [PATCH 200/247] fix treesitter config --- lua/config/treesitter.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 667c8f30..9558e4cf 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -22,6 +22,9 @@ vim.api.nvim_create_autocmd("FileType", { callback = function(args) local ft = vim.bo[args.buf].filetype local lang = vim.treesitter.language.get_lang(ft) + if lang == nil then + return + end -- check if parser is available if not vim.treesitter.language.add(lang) then From 111aadbd09fbec73a69ea4915b88b00c0ac134c7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 15 Mar 2026 00:41:40 +0100 Subject: [PATCH 201/247] Remove .luarc.jsonc Lazydev seems can not work with .luarc.json correctly --- .luarc.jsonc | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .luarc.jsonc diff --git a/.luarc.jsonc b/.luarc.jsonc deleted file mode 100644 index 86e49684..00000000 --- a/.luarc.jsonc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "runtime.version": "LuaJIT", - "workspace.library": ["$VIMRUNTIME/lua"] -} From 2c2354d9a27773f9991791618f5fcd89b5bc11a3 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 15 Mar 2026 19:46:23 +0100 Subject: [PATCH 202/247] Add completion support for lsp settings (#473) For more details, see https://www.reddit.com/r/neovim/comments/1rssfs9/a_new_use_for_lspconfig_providing_types_for_your/ --- after/lsp/clangd.lua | 1 + after/lsp/ltex.lua | 2 ++ after/lsp/lua_ls.lua | 7 +++++++ after/lsp/pyright.lua | 2 ++ after/lsp/ruff.lua | 1 + lua/plugin_specs.lua | 1 + 6 files changed, 14 insertions(+) diff --git a/after/lsp/clangd.lua b/after/lsp/clangd.lua index 96016e7f..3edff2b3 100644 --- a/after/lsp/clangd.lua +++ b/after/lsp/clangd.lua @@ -1,3 +1,4 @@ +---@type vim.lsp.Config return { filetypes = { "c", "cpp", "cc" }, } diff --git a/after/lsp/ltex.lua b/after/lsp/ltex.lua index 65da2859..f4be5f48 100644 --- a/after/lsp/ltex.lua +++ b/after/lsp/ltex.lua @@ -1,5 +1,7 @@ +---@type vim.lsp.Config return { filetypes = { "text", "plaintex", "tex", "markdown" }, + ---@type lspconfig.settings.ltex settings = { ltex = { language = "en", diff --git a/after/lsp/lua_ls.lua b/after/lsp/lua_ls.lua index 382ac7b1..ad7512a0 100644 --- a/after/lsp/lua_ls.lua +++ b/after/lsp/lua_ls.lua @@ -1,5 +1,7 @@ -- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/ +---@type vim.lsp.Config return { + ---@type lspconfig.settings.lua_ls settings = { Lua = { runtime = { @@ -9,6 +11,11 @@ return { hint = { enable = true, }, + workspace = { + library = { + vim.env.VIMRUNTIME .. "/lua", + }, + }, }, }, } diff --git a/after/lsp/pyright.lua b/after/lsp/pyright.lua index cd69e82a..4b2632ae 100644 --- a/after/lsp/pyright.lua +++ b/after/lsp/pyright.lua @@ -19,8 +19,10 @@ local new_capability = { }, } +---@type vim.lsp.Config return { cmd = { "delance-langserver", "--stdio" }, + ---@type lspconfig.settings.pyright settings = { pyright = { -- disable import sorting and use Ruff for this diff --git a/after/lsp/ruff.lua b/after/lsp/ruff.lua index 49120a9e..523c7361 100644 --- a/after/lsp/ruff.lua +++ b/after/lsp/ruff.lua @@ -1,3 +1,4 @@ +---@type vim.lsp.Config return { init_options = { -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/ diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index ae4e6770..76266d5e 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -698,6 +698,7 @@ local plugin_specs = { -- See the configuration section for more details -- Load luvit types when the `vim.uv` word is found { path = "${3rd}/luv/library", words = { "vim%.uv" } }, + { path = "nvim-lspconfig", words = { "lspconfig" } }, }, }, }, From 45495c486408e8b3b144c19dc7948a846e86fe85 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 17 Mar 2026 20:40:34 +0100 Subject: [PATCH 203/247] Add colorscheme oxocarbon (#474) --- lua/colorschemes.lua | 3 +++ lua/plugin_specs.lua | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 2a0644fc..e1d8121e 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -90,6 +90,9 @@ M.colorscheme_conf = { citruszest = function() use_theme("citruszest") end, + oxocarbon = function() + use_theme("oxocarbon") + end, } --- Use a random colorscheme from the pre-defined list of colorschemes. diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 76266d5e..3193343c 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -154,6 +154,10 @@ local plugin_specs = { { "vague2k/vague.nvim", priority = 1000 }, { "webhooked/kanso.nvim", priority = 1000 }, { "zootedb0t/citruszest.nvim", priority = 1000 }, + { + "nyoom-engineering/oxocarbon.nvim", + priority = 1000, + }, -- plugins to provide nerdfont icons { From 6b936df0c2e27f3f78672cc9466216bdc51a9bf9 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 21 Mar 2026 00:20:19 +0100 Subject: [PATCH 204/247] Add mapping for conflict resolution (#475) --- lua/config/diffview.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lua/config/diffview.lua b/lua/config/diffview.lua index 5c63469a..97d2c573 100644 --- a/lua/config/diffview.lua +++ b/lua/config/diffview.lua @@ -3,6 +3,9 @@ if not ok then return end +local actions = require("diffview.actions") +local prefix_conflicts = "gC" + diffview.setup { enhanced_diff_hl = true, view = { @@ -20,4 +23,29 @@ diffview.setup { height = 10, }, }, + keymaps = { + view = { + { + "n", + prefix_conflicts .. "t", + actions.conflict_choose("theirs"), + { desc = "Conflict choose theirs" }, + }, + { + "n", + prefix_conflicts .. "o", + actions.conflict_choose("ours"), + { desc = "Conflict choose ours" }, + }, + { + "n", + prefix_conflicts .. "a", + actions.conflict_choose("all"), + { desc = "Conflict choose both" }, + }, + + { "n", "]C", actions.next_conflict, { desc = "Next conflict" } }, + { "n", "[C", actions.prev_conflict, { desc = "Previous conflict" } }, + }, + }, } From afe30a5e7ccfef9d9b75b7ad6d62e0c8ac494a0d Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 21 Mar 2026 00:44:19 +0100 Subject: [PATCH 205/247] improve colorscheme loading (#476) --- init.lua | 12 ++++++------ lua/colorschemes.lua | 25 ++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/init.lua b/init.lua index ecd05247..b9ad813b 100644 --- a/init.lua +++ b/init.lua @@ -9,19 +9,22 @@ -- Blog: https://jdhao.github.io/ -- GitHub: https://github.com/jdhao -- StackOverflow: https://stackoverflow.com/users/6064933/jdhao -vim.loader.enable() - local utils = require("utils") +vim.loader.enable() + local expected_version = "0.11.6" utils.is_compatible_version(expected_version) -- some global settings require("globals") + -- setting options in nvim require("options") + -- various autocommands require("custom-autocmd") + -- all the user-defined mappings require("mappings") @@ -35,7 +38,4 @@ require("lsp_conf") require("diagnostic-conf") -- colorscheme settings -local color_scheme = require("colorschemes") - --- Load a random colorscheme -color_scheme.rand_colorscheme() +require("colorschemes") diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index e1d8121e..ae37776a 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -3,7 +3,18 @@ local utils = require("utils") local M = {} -local use_theme = vim.cmd.colorscheme +local use_theme = function(name) + local ok, err = pcall(vim.cmd.colorscheme, name) + + if not ok then + vim.notify( + string.format("Failed to load colorscheme %s, err: %s", name, err), + vim.log.levels.WARN + ) + + vim.cmd.colorscheme("default") + end +end -- Colorscheme to its directory name mapping, because colorscheme repo name is not necessarily -- the same as the colorscheme name itself. @@ -97,10 +108,18 @@ M.colorscheme_conf = { --- Use a random colorscheme from the pre-defined list of colorschemes. M.rand_colorscheme = function() - local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf)) + local colorscheme_names = vim.tbl_keys(M.colorscheme_conf) + local colorscheme = utils.rand_element(colorscheme_names) -- Load the colorscheme and its settings - M.colorscheme_conf[colorscheme]() + + local color_scheme_loader = M.colorscheme_conf[colorscheme] + + color_scheme_loader() + + return colorscheme end +M.rand_colorscheme() + return M From bc9fbcdbe06d5d3418427ec461201d7836286355 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 21 Mar 2026 11:26:03 +0100 Subject: [PATCH 206/247] Add two diff-related plugins (#477) --- lua/plugin_specs.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 3193343c..5a1bf13e 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -414,6 +414,24 @@ local plugin_specs = { end, }, + { + "barrettruth/diffs.nvim", + init = function() + vim.g.diffs = { + integrations = { + fugitive = true, + neogit = true, + gitsigns = true, + }, + } + end, + }, + + { + "esmuellert/codediff.nvim", + cmd = "CodeDiff", + }, + { "kevinhwang91/nvim-bqf", ft = "qf", From 09f947b854a4e0fbd9cdbf737980b6527d0c0949 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 21 Mar 2026 11:35:00 +0100 Subject: [PATCH 207/247] Add mapping to manage tabs (#478) --- lua/mappings.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lua/mappings.lua b/lua/mappings.lua index b5cca830..b9bea8e6 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -30,12 +30,12 @@ keymap.set("n", [[\x]], "windo lclose cclose ", { }) -- Delete a buffer, without closing the window, see https://stackoverflow.com/q/4465095/6064933 -keymap.set("n", [[\d]], "bprevious bdelete #", { +keymap.set("n", [[\db]], "bprevious bdelete #", { silent = true, - desc = "delete current buffer", + desc = "Delete current buffer", }) -keymap.set("n", [[\D]], function() +keymap.set("n", [[\dB]], function() local buf_ids = vim.api.nvim_list_bufs() local cur_buf = vim.api.nvim_win_get_buf(0) @@ -46,7 +46,17 @@ keymap.set("n", [[\D]], function() end end end, { - desc = "delete other buffers", + desc = "Delete other buffers", +}) + +keymap.set("n", [[\dt]], "tabclose", { + silent = true, + desc = "Delete current tab", +}) + +keymap.set("n", [[\dT]], "tabonly", { + silent = true, + desc = "Delete other tabs", }) -- Move the cursor based on physical lines, not the actual lines. From cfb0710d1b639deca2e9f58ddbe05d2a0122adda Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 26 Mar 2026 15:46:34 +0100 Subject: [PATCH 208/247] change default float win border style --- lua/options.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/options.lua b/lua/options.lua index 60cd8450..24a26da0 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -180,7 +180,7 @@ opt.pumheight = 10 -- Maximum number of items to show in popup menu opt.pumblend = 5 -- Pseudo transparency for completion menu opt.winblend = 0 -- Pseudo transparency for floating window -opt.winborder = "none" +opt.winborder = "single" -- Insert mode key word completion setting opt.complete:append("kspell") From e56acc8abf1b646d84c418778fe3fa327f329acd Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 2 Apr 2026 23:08:21 +0200 Subject: [PATCH 209/247] Upgrade to nvim 0.12 (#479) --- README.md | 2 +- after/lsp/pyright.lua | 2 +- init.lua | 4 ++-- lua/config/iswap.lua | 5 +++++ lua/custom-autocmd.lua | 22 +++++++++++---------- lua/lsp_conf.lua | 34 ++++++++++++++++++++++++++++++++ lua/options.lua | 13 ++++++------ lua/plugin_specs.lua | 8 +++++++- lua/{colorschemes.lua => ui.lua} | 25 +++++++++++++++++++++++ 9 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 lua/config/iswap.lua rename lua/{colorschemes.lua => ui.lua} (75%) diff --git a/README.md b/README.md index c87c13d0..4c375d68 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows - Neovim minimum version + Neovim minimum version Top languages diff --git a/after/lsp/pyright.lua b/after/lsp/pyright.lua index 4b2632ae..c6ba1d3d 100644 --- a/after/lsp/pyright.lua +++ b/after/lsp/pyright.lua @@ -21,7 +21,7 @@ local new_capability = { ---@type vim.lsp.Config return { - cmd = { "delance-langserver", "--stdio" }, + -- cmd = { "delance-langserver", "--stdio" }, ---@type lspconfig.settings.pyright settings = { pyright = { diff --git a/init.lua b/init.lua index b9ad813b..bf2d5103 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ local utils = require("utils") vim.loader.enable() -local expected_version = "0.11.6" +local expected_version = "0.12.0" utils.is_compatible_version(expected_version) -- some global settings @@ -38,4 +38,4 @@ require("lsp_conf") require("diagnostic-conf") -- colorscheme settings -require("colorschemes") +require("ui") diff --git a/lua/config/iswap.lua b/lua/config/iswap.lua new file mode 100644 index 00000000..cf29e1d7 --- /dev/null +++ b/lua/config/iswap.lua @@ -0,0 +1,5 @@ +require("iswap").setup { + move_cursor = true, +} +vim.keymap.set("n", "gs<", "ISwapWithLeft") +vim.keymap.set("n", "gs>", "ISwapWithRight") diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 5bc01d5d..1f2842ca 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -174,23 +174,25 @@ api.nvim_create_autocmd("ColorScheme", { { fg = "#34495E", bg = "#2ECC71", ctermfg = 59, ctermbg = 41 } ) - -- For cursor colors - vim.api.nvim_set_hl(0, "Cursor", { fg = "black", bg = "#00c918", bold = true }) - vim.api.nvim_set_hl(0, "Cursor2", { fg = "red", bg = "red" }) + -- For cursor colors, see option guicursor for more info + vim.api.nvim_set_hl(0, "Cursor", { fg = "black", bg = "#00c918", update = true }) + vim.api.nvim_set_hl(0, "Cursor2", { fg = "None", bg = "yellow", update = true }) -- For floating windows border highlight - vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen", bg = "None", bold = true }) + vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen", update = true }) - local hl = vim.api.nvim_get_hl(0, { name = "NormalFloat" }) -- change the background color of floating window to None, so it blenders better - vim.api.nvim_set_hl(0, "NormalFloat", { fg = hl.fg, bg = "None" }) + vim.api.nvim_set_hl(0, "NormalFloat", { bg = "None", update = true }) + + -- this is the highlight used by nvim-cmp for cmdline completion window border + vim.api.nvim_set_hl(0, "Pmenu", { bg = "None", update = true }) -- highlight for matching parentheses - vim.api.nvim_set_hl(0, "MatchParen", { bold = true, underline = true }) + vim.api.nvim_set_hl(0, "MatchParen", { bold = true, underline = true, update = true }) - vim.api.nvim_set_hl(0, "IlluminatedWordWrite", { underline = true, reverse = true }) - vim.api.nvim_set_hl(0, "IlluminatedWordRead", { underline = true, reverse = true }) - vim.api.nvim_set_hl(0, "IlluminatedWordText", { underline = true, reverse = true }) + vim.api.nvim_set_hl(0, "IlluminatedWordWrite", { reverse = true, update = true }) + vim.api.nvim_set_hl(0, "IlluminatedWordRead", { reverse = true, update = true }) + vim.api.nvim_set_hl(0, "IlluminatedWordText", { reverse = true, update = true }) end, }) diff --git a/lua/lsp_conf.lua b/lua/lsp_conf.lua index 22c53a9b..3aa35ee5 100644 --- a/lua/lsp_conf.lua +++ b/lua/lsp_conf.lua @@ -127,3 +127,37 @@ for server_name, lsp_executable in pairs(enabled_lsp_servers) do vim.notify(msg, vim.log.levels.WARN, { title = "Nvim-config" }) end end + +-- LSP related command + +vim.api.nvim_create_user_command("LspInfo", "checkhealth vim.lsp", { + desc = "Show LSP Info", +}) + +vim.api.nvim_create_user_command("LspLog", function(_) + local state_path = vim.fn.stdpath("state") + local log_path = vim.fs.joinpath(state_path, "lsp.log") + + vim.cmd(string.format("edit %s", log_path)) +end, { + desc = "Show LSP log", +}) + +vim.api.nvim_create_user_command("LspRestart", "lsp restart", { + desc = "Restart LSP", +}) + +--- show LSP progress (works on Ghostty) +vim.api.nvim_create_autocmd("LspProgress", { + callback = function(ev) + local value = ev.data.params.value + vim.api.nvim_echo({ { value.message or "done" } }, false, { + id = "lsp." .. ev.data.client_id, + kind = "progress", + source = "vim.lsp", + title = value.title, + status = value.kind ~= "end" and "running" or "success", + percent = value.percentage, + }) + end, +}) diff --git a/lua/options.lua b/lua/options.lua index 24a26da0..0f961a5c 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -149,6 +149,7 @@ opt.listchars = { -- Auto-write the file based on some condition opt.autowrite = true +opt.autowriteall = true -- Auto reload file if changed outside nvim opt.autoread = true @@ -178,6 +179,7 @@ opt.completeopt:remove("preview") -- Disable the preview window opt.pumheight = 10 -- Maximum number of items to show in popup menu opt.pumblend = 5 -- Pseudo transparency for completion menu +opt.pumborder = "single" opt.winblend = 0 -- Pseudo transparency for floating window opt.winborder = "single" @@ -217,8 +219,9 @@ end opt.termguicolors = true -- Set up cursor color and shape in various mode, ref: --- https://github.com/neovim/neovim/wiki/FAQ#how-to-change-cursor-color-in-the-terminal -opt.guicursor = "n-v-c:block-Cursor/lCursor,i-ci-ve:ver25-Cursor2/lCursor2,r-cr:hor20,o:hor20" +-- https://neovim.io/doc/user/faq/#_how-to-change-cursor-color-in-the-terminal%3f +opt.guicursor = + "n-v:block-Cursor/lCursor,i-c-ci-ve:ver50-blinkwait50-blinkoff100-blinkon175-Cursor2/lCursor2,r-cr:hor20,o:hor20" opt.signcolumn = "yes:1" @@ -238,11 +241,7 @@ opt.diffopt = { -- inline diff makes changes in a line more noticeable, the author suggests to -- remove linematch option if you use inline option, see also -- https://www.reddit.com/r/neovim/comments/1myfvla/comment/najy4s3/ -if fn.has("nvim-0.12") == 1 then - opt.diffopt:append("inline:char") -else - opt.diffopt:append("linematch:60") -end +opt.diffopt:append("inline:char") opt.wrap = false -- Do not wrap opt.ruler = false diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 5a1bf13e..fb3e82b3 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -88,7 +88,13 @@ local plugin_specs = { require("config.treesitter-textobjects") end, }, - { "machakann/vim-swap", event = "VeryLazy" }, + { + "mizlan/iswap.nvim", + event = "VeryLazy", + config = function() + require("config.iswap") + end, + }, -- Super fast buffer jump { diff --git a/lua/colorschemes.lua b/lua/ui.lua similarity index 75% rename from lua/colorschemes.lua rename to lua/ui.lua index ae37776a..447d5be9 100644 --- a/lua/colorschemes.lua +++ b/lua/ui.lua @@ -122,4 +122,29 @@ end M.rand_colorscheme() +-- enable the experiment UI +require("vim._core.ui2").enable { + enable = true, + msg = { -- Options related to the message module. + ---@type 'cmd'|'msg' Default message target, either in the + ---cmdline or in a separate ephemeral message window. + ---@type string|table Default message target + ---or table mapping |ui-messages| kinds and triggers to a target. + targets = "cmd", + cmd = { -- Options related to messages in the cmdline window. + height = 0.5, -- Maximum height while expanded for messages beyond 'cmdheight'. + }, + dialog = { -- Options related to dialog window. + height = 0.5, -- Maximum height. + }, + msg = { -- Options related to msg window. + height = 0.5, -- Maximum height. + timeout = 4000, -- Time a message is visible in the message window. + }, + pager = { -- Options related to message window. + height = 0.5, -- Maximum height. + }, + }, +} + return M From 0ce16c60964321b9f8ff0c1b5997c2ecc14fdf0e Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 3 Apr 2026 15:07:48 +0200 Subject: [PATCH 210/247] use native lsp method to get lsp log path --- lua/lsp_conf.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/lsp_conf.lua b/lua/lsp_conf.lua index 3aa35ee5..25dadad4 100644 --- a/lua/lsp_conf.lua +++ b/lua/lsp_conf.lua @@ -135,8 +135,7 @@ vim.api.nvim_create_user_command("LspInfo", "checkhealth vim.lsp", { }) vim.api.nvim_create_user_command("LspLog", function(_) - local state_path = vim.fn.stdpath("state") - local log_path = vim.fs.joinpath(state_path, "lsp.log") + local log_path = vim.lsp.log.get_filename() vim.cmd(string.format("edit %s", log_path)) end, { From 7a851486a859ba110a967e9f11c06ad442d87005 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 3 Apr 2026 15:22:01 +0200 Subject: [PATCH 211/247] Use nvim native intro page (#480) --- lua/config/snacks.lua | 43 ------------------------------------------- lua/options.lua | 4 ++-- 2 files changed, 2 insertions(+), 45 deletions(-) diff --git a/lua/config/snacks.lua b/lua/config/snacks.lua index 78a57c8a..81c7dffb 100644 --- a/lua/config/snacks.lua +++ b/lua/config/snacks.lua @@ -9,47 +9,4 @@ require("snacks").setup { }, -- more beautiful vim.ui.select picker = { enabled = true }, - -- startup dashboard - dashboard = { - enabled = true, - preset = { - header = [[ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣿⣦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣨⣿⣿⠿⠻⣿⡀⠀⠀⠀⣠⣾⡟⢹⣶⣦⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⣿⠋⠀⢠⣿⣧⠀⠀⣴⣿⣿⣿⡟⠉⢿⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⡟⠀⣤⠉⣿⣿⠀⢠⣿⣿⣿⡟⠀⠀⢸⣿⣟⠂⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣺⣿⣿⠀⣰⣿⠀⣿⣿⠀⣾⣿⣿⡟⠀⣠⡄⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⠃⠀⣿⡏⢠⣿⣿⣤⣿⣿⣿⠁⢸⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣀⣼⣿⣷⣿⡿⣿⠿⠿⣿⣧⣠⣿⣿⢁⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⡿⣽⣿⣷⣶⡋⠂⠀⣊⠀⢉⠽⠻⢿⣿⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⢠⣞⣹⡿⣿⣿⣿⣿⣻⣿⣷⣧⣰⡀⠉⠀⢀⡠⠎⠩⣭⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⢠⠄⣰⠟⣻⣿⡿⢿⣿⣿⣿⣿⣷⣿⣿⣿⡇⠀⡙⣻⣦⠀⢸⣖⠒⠺⣷⡀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠠⠃⢸⣷⡿⠋⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣾⣿⡿⣿⣷⣏⠉⢛⣀⣼⡇⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⢠⣶⡟⢉⣴⣿⣿⣿⣿⣿⣿⣿⡿⠛⠛⠋⠉⠛⠻⢿⣿⣿⣽⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀ -⠀⠀⠀⢰⡿⢟⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠙⠻⣿⣿⣽⣿⣷⠀⠀⠀⠀ -⠀⠀⠀⡼⣷⣿⡟⣿⣿⣿⣿⣿⡟⠀⠀⠀⣀⠖⠰⢦⠤⠤⠀⠀⠀⠀⠀⠀⠀⢀⡸⣿⣿⣻⣿⣧⠀⠀⠀ -⠀⠀⠀⢱⣿⣿⣿⣿⣿⣿⣿⣟⠀⠀⠀⢠⠏⠀⣾⡿⣷⡀⠀⠀⠀⠀⡾⠋⣩⡍⠁⢸⣿⣿⣻⣿⠀⠀⠀ -⠀⠀⠀⡿⣿⣿⣿⣿⣿⣿⣿⣿⠰⡀⠀⢸⠀⢸⣿⣿⣿⠃⠀⠀⠀⢸⠃⢰⣿⣿⠀⢸⣿⣿⣿⣿⠄⠀⠀ -⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⡇⠻⣄⠈⢧⠈⠿⠿⠋⠀⢠⣶⣤⣬⠀⢸⣿⡏⠀⢸⣿⣿⣿⠃⠀⠀⠀ -⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣦⡈⠳⣄⡀⠀⠀⠀⠀⠀⠙⠉⠀⠁⠘⠛⢁⣰⣿⣿⣿⣿⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⣉⡳⠶⠤⣤⣀⣀⣀⣀⣀⣤⣶⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠉⠻⣿⣿⣿⣿⣍⣿⣿⣿⣿⣿⣿⣶⣶⣶⣿⣿⣿⣷⣾⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣤⣄⣀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⢰⣤⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢧⢄⠀⠀ -⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⣿⣿⡗⢤⢤⠾⠀ -⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣽⣿⣿⣿⣿⣿⣿⣿⣿⠟⠀⠀⠀ -⠀⠀⠀⠀⣸⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⠻⠟⠋⠁⠀⠀⠀⠀ -⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⢀⣴⣟⠁⢸⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀ -⢠⡾⠟⠛⠙⠳⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠰⢆⡀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⢀⣀⡉⢓⣦⣠⣴⠾⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠰⣤⣥⣼⣿⣿⡏⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠄⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠘⠹⠛⠻⠛⠃⣾⣿⣿⡿⣿⣿⣿⣿⣿⣿⣿⣟⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⣀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠋⠋⠙⣿⠻⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⣿⣯⣥⣤⣬⣽⡿⢻⣿⡏⡂⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠏⠛⠻⠿⡿⣿⡟⢺⣿⣿⡿⠛⠛⢃⣘⠛⠛⠟⠛⠛⠻⢿⢿⠏⠙⠜⣷⢞⠂ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠆⠀⠀⠀⠁⠈⠁⢨⠭⣉⠀⠀⠀⢈⠁⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀ - ]], - }, - }, } diff --git a/lua/options.lua b/lua/options.lua index 0f961a5c..2378d7ba 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -168,8 +168,7 @@ opt.undofile = true -- Do not show search match count on bottom right (seriously, I would strain my -- neck looking at it). Using plugins like vim-anzu or nvim-hlslens is a better -- choice, IMHO. --- Disable showing intro message (:intro) -opt.shortmess:append("cSI") +opt.shortmess:append("cS") opt.messagesopt = "hit-enter,history:500" @@ -224,6 +223,7 @@ opt.guicursor = "n-v:block-Cursor/lCursor,i-c-ci-ve:ver50-blinkwait50-blinkoff100-blinkon175-Cursor2/lCursor2,r-cr:hor20,o:hor20" opt.signcolumn = "yes:1" +opt.colorcolumn = "100" -- Remove certain character from file name pattern matching opt.isfname:remove { "=", "," } From dbbedb3422beff0fbaf7d98df1ce03a129dd96d4 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 3 Apr 2026 15:36:10 +0200 Subject: [PATCH 212/247] redefine reload using command restart --- lua/mappings.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/mappings.lua b/lua/mappings.lua index b9bea8e6..7238c275 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -85,14 +85,14 @@ keymap.set("n", "ev", "tabnew $MYVIMRC tcd %:h", { }) keymap.set("n", "sv", function() - vim.cmd([[ - update $MYVIMRC - source $MYVIMRC - ]]) - vim.notify("Nvim config successfully reloaded!", vim.log.levels.INFO, { title = "nvim-config" }) + local current_buf_path = vim.fn.expand("%") + local restart_cmd = string.format("restart edit %s", current_buf_path) + + vim.cmd(restart_cmd) + vim.notify("Nvim restarted!", vim.log.levels.INFO, { title = "nvim-config" }) end, { silent = true, - desc = "reload init.lua", + desc = "Restart nvim", }) -- Reselect the text that has just been pasted, see also https://stackoverflow.com/a/4317090/6064933. From e76f25ba8f7a35d8e6ceddc329cce8c94219af89 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 3 Apr 2026 15:39:26 +0200 Subject: [PATCH 213/247] update spell --- spell/en.utf-8.add | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spell/en.utf-8.add b/spell/en.utf-8.add index 6da520ea..2b832543 100644 --- a/spell/en.utf-8.add +++ b/spell/en.utf-8.add @@ -495,3 +495,7 @@ Lucene replia #hitespaces whitespaces/! +venv +lockfile +uv +ref From e89e9f05fb8513278a60926e2fd02cb3d60df0f3 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 7 Apr 2026 21:35:33 +0200 Subject: [PATCH 214/247] update lualine section separator --- lua/config/lualine.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index c1f18dd4..8aed3c76 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -206,7 +206,7 @@ require("lualine").setup { options = { icons_enabled = true, theme = "auto", - component_separators = { left = "⏐", right = "⏐" }, + component_separators = { left = "|", right = "|" }, section_separators = "", disabled_filetypes = {}, always_divide_middle = true, From 4ba3af19756e22508aef036f1e7ccbe1f47a84a7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 8 Apr 2026 00:35:56 +0200 Subject: [PATCH 215/247] bump supported nvim version --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index bf2d5103..88b8e361 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ local utils = require("utils") vim.loader.enable() -local expected_version = "0.12.0" +local expected_version = "0.12.1" utils.is_compatible_version(expected_version) -- some global settings From c028d1bf7c94ffee12b32044b5c0e4593f016c91 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 8 Apr 2026 00:36:30 +0200 Subject: [PATCH 216/247] set up gopls and basic go formatting --- after/ftplugin/go.lua | 5 +++++ after/lsp/gopls.lua | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 after/ftplugin/go.lua create mode 100644 after/lsp/gopls.lua diff --git a/after/ftplugin/go.lua b/after/ftplugin/go.lua new file mode 100644 index 00000000..07593903 --- /dev/null +++ b/after/ftplugin/go.lua @@ -0,0 +1,5 @@ +-- gofumpt adds more rule to gofmt, and is compatible with gofmt, +-- so also https://github.com/mvdan/gofumpt +vim.keymap.set("n", "f", function() + vim.cmd([[silent !gofumpt -w %]]) +end, { buffer = true, silent = true }) diff --git a/after/lsp/gopls.lua b/after/lsp/gopls.lua new file mode 100644 index 00000000..45af9e36 --- /dev/null +++ b/after/lsp/gopls.lua @@ -0,0 +1,14 @@ +-- settings for gopls can be found in https://go.dev/gopls/settings +---@type vim.lsp.Config +return { + settings = { + gopls = { + usePlaceholders = true, + analyses = { + unusedparams = true, + }, + staticcheck = true, + gofumpt = true, + }, + }, +} From db61060c2548fa2f1ec14b66613e95618fb543c6 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 8 Apr 2026 00:37:16 +0200 Subject: [PATCH 217/247] enable gopls and golangci-lint --- lua/lsp_conf.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/lsp_conf.lua b/lua/lsp_conf.lua index 25dadad4..b5e2c8ee 100644 --- a/lua/lsp_conf.lua +++ b/lua/lsp_conf.lua @@ -113,6 +113,10 @@ local enabled_lsp_servers = { vimls = "vim-language-server", bashls = "bash-language-server", yamlls = "yaml-language-server", + gopls = "gopls", + -- the server can be install via homebrew: brew install golangci-lint-langserver + -- golangci-lint also needs to be installed: https://github.com/golangci/golangci-lint + golangci_lint_ls = "golangci-lint-langserver", } for server_name, lsp_executable in pairs(enabled_lsp_servers) do From 71f4f49f82fa6c58dacf43c7a27f7cd8bce49996 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 8 Apr 2026 00:37:41 +0200 Subject: [PATCH 218/247] update treesitter config --- lua/config/treesitter.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 9558e4cf..52f2f2e8 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -1,8 +1,12 @@ -- a list of filetypes to install treesitter parsers and queries +local nvim_treesitter = require("nvim-treesitter") + local ensure_installed = { "cpp", "diff", "go", + "gomod", + "gosum", "javascript", "json", "lua", @@ -27,13 +31,14 @@ vim.api.nvim_create_autocmd("FileType", { end -- check if parser is available - if not vim.treesitter.language.add(lang) then - local available = vim.g.ts_available or require("nvim-treesitter").get_available() + local is_parser_available = vim.treesitter.language.add(lang) + if not is_parser_available then + local available_langs = vim.g.ts_available or nvim_treesitter.get_available() if not vim.g.ts_available then - vim.g.ts_available = available + vim.g.ts_available = available_langs end - if vim.tbl_contains(available, lang) then + if vim.tbl_contains(available_langs, lang) then -- install treesitter parsers and queries local install_msg = string.format("Installing parsers and queries for %s", lang) vim.print(install_msg) From 84a991c754e9e56d86bffe0282df2d5dfdccb367 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 9 Apr 2026 01:01:23 +0200 Subject: [PATCH 219/247] update nvim-tree conf --- lua/config/nvim-tree.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/config/nvim-tree.lua b/lua/config/nvim-tree.lua index 6bf653d5..c9196b03 100644 --- a/lua/config/nvim-tree.lua +++ b/lua/config/nvim-tree.lua @@ -40,10 +40,6 @@ nvim_tree.setup { update_cwd = false, ignore_list = {}, }, - system_open = { - cmd = "", - args = {}, - }, diagnostics = { enable = false, show_on_dirs = false, From 2797c1ef6ab2bc57e6bb2df71040817574117c18 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 10 Apr 2026 00:01:41 +0200 Subject: [PATCH 220/247] update tab settings for golang --- after/ftplugin/go.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/after/ftplugin/go.lua b/after/ftplugin/go.lua index 07593903..433c81cb 100644 --- a/after/ftplugin/go.lua +++ b/after/ftplugin/go.lua @@ -1,3 +1,11 @@ +local opt = vim.opt + +-- General tab settings +opt.tabstop = 4 -- Number of visual spaces per TAB +opt.softtabstop = 4 -- Number of spaces in tab when editing +opt.shiftwidth = 4 -- Number of spaces to use for autoindent +opt.expandtab = false -- Expand tab to spaces so that tabs are spaces + -- gofumpt adds more rule to gofmt, and is compatible with gofmt, -- so also https://github.com/mvdan/gofumpt vim.keymap.set("n", "f", function() From 5a8a85d2a3d8b3c5ff4dc4720f9e7ff749f51872 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 10 Apr 2026 00:02:19 +0200 Subject: [PATCH 221/247] update fzf-lua conf --- lua/config/fzf-lua.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/config/fzf-lua.lua b/lua/config/fzf-lua.lua index de7fe94e..9d142678 100644 --- a/lua/config/fzf-lua.lua +++ b/lua/config/fzf-lua.lua @@ -18,7 +18,7 @@ require("fzf-lua").setup { } vim.keymap.set("n", "ff", "FzfLua files", { desc = "Fuzzy find files" }) -vim.keymap.set("n", "fg", "FzfLua live_grep", { desc = "Fuzzy grep files" }) +vim.keymap.set("n", "fg", "FzfLua live_grep_native", { desc = "Fuzzy grep files" }) vim.keymap.set( "n", "fh", From 4b77f683878e883c5add8bdcbf164e8aa7a0ed50 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 11 Apr 2026 17:06:56 +0200 Subject: [PATCH 222/247] change lazy load for UltiSnips We need UltiSnips to correctly highlight the *.snippets files. It is better to make sure that UltiSnips are always loaded. --- lua/plugin_specs.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index fb3e82b3..272eef2e 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -305,7 +305,7 @@ local plugin_specs = { let g:UltiSnipsSnippetDirectories=['UltiSnips', 'my_snippets'] ]]) end, - event = "InsertEnter", + event = "VeryLazy", }, -- Automatic insertion and deletion of a pair of characters From bae3370bbab718d35c92eabd968dde7552bf6801 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 11 Apr 2026 23:30:19 +0200 Subject: [PATCH 223/247] use ZR to restart nvim --- lua/mappings.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lua/mappings.lua b/lua/mappings.lua index 7238c275..60539674 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -78,18 +78,15 @@ keymap.set({ "n", "x" }, "L", "g_") keymap.set("x", "<", "", ">gv") --- Edit and reload nvim config file quickly -keymap.set("n", "ev", "tabnew $MYVIMRC tcd %:h", { - silent = true, - desc = "open init.lua", -}) - +-- Restart nvim keymap.set("n", "sv", function() + vim.print("Use ZR to restart nvim instead!") +end) + +keymap.set("n", "ZR", function() local current_buf_path = vim.fn.expand("%") local restart_cmd = string.format("restart edit %s", current_buf_path) - vim.cmd(restart_cmd) - vim.notify("Nvim restarted!", vim.log.levels.INFO, { title = "nvim-config" }) end, { silent = true, desc = "Restart nvim", From a892a19dc5243be0b0f1854bf460eb1e5bc29426 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 12 Apr 2026 00:10:29 +0200 Subject: [PATCH 224/247] Add map to run single golang source --- after/ftplugin/go.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/after/ftplugin/go.lua b/after/ftplugin/go.lua index 433c81cb..6a84a6ae 100644 --- a/after/ftplugin/go.lua +++ b/after/ftplugin/go.lua @@ -11,3 +11,10 @@ opt.expandtab = false -- Expand tab to spaces so that tabs are spaces vim.keymap.set("n", "f", function() vim.cmd([[silent !gofumpt -w %]]) end, { buffer = true, silent = true }) + +vim.keymap.set("n", "", function() + vim.cmd[[!go run %]] +end, { + buffer = true, + silent = true, +}) From f182ee4c792a836e0c1c0ee844e062b00dd159ee Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 12 Apr 2026 12:46:54 +0200 Subject: [PATCH 225/247] Add theme ember --- lua/plugin_specs.lua | 6 ++---- lua/ui.lua | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 272eef2e..128a641c 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -160,10 +160,8 @@ local plugin_specs = { { "vague2k/vague.nvim", priority = 1000 }, { "webhooked/kanso.nvim", priority = 1000 }, { "zootedb0t/citruszest.nvim", priority = 1000 }, - { - "nyoom-engineering/oxocarbon.nvim", - priority = 1000, - }, + { "nyoom-engineering/oxocarbon.nvim", priority = 1000 }, + { "ember-theme/nvim", name = "ember", priority = 1000 }, -- plugins to provide nerdfont icons { diff --git a/lua/ui.lua b/lua/ui.lua index 447d5be9..7834aabe 100644 --- a/lua/ui.lua +++ b/lua/ui.lua @@ -104,6 +104,9 @@ M.colorscheme_conf = { oxocarbon = function() use_theme("oxocarbon") end, + ember = function() + use_theme("ember") + end, } --- Use a random colorscheme from the pre-defined list of colorschemes. From e986b4bf55aa7c52318e8483a7b780767dfc28e4 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 12 Apr 2026 12:47:27 +0200 Subject: [PATCH 226/247] Add snippets for golang --- my_snippets/go.snippets | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 my_snippets/go.snippets diff --git a/my_snippets/go.snippets b/my_snippets/go.snippets new file mode 100644 index 00000000..aef1cd41 --- /dev/null +++ b/my_snippets/go.snippets @@ -0,0 +1,11 @@ +snippet main "func main" b +func main() { + $1 +} +endsnippet + +snippet func "create a function" b +func $1($2) $3 { + $4 +} +endsnippet From c56cc549f760c825150b94163c7741dbffbdf777 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 12 Apr 2026 12:58:51 +0200 Subject: [PATCH 227/247] fix format --- after/ftplugin/go.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/after/ftplugin/go.lua b/after/ftplugin/go.lua index 6a84a6ae..d28b7db3 100644 --- a/after/ftplugin/go.lua +++ b/after/ftplugin/go.lua @@ -13,7 +13,7 @@ vim.keymap.set("n", "f", function() end, { buffer = true, silent = true }) vim.keymap.set("n", "", function() - vim.cmd[[!go run %]] + vim.cmd([[!go run %]]) end, { buffer = true, silent = true, From 994d4d0004669514064a3d28b085aff7ff4fd263 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 14 Apr 2026 09:26:36 +0200 Subject: [PATCH 228/247] feat: auto-save file --- lua/custom-autocmd.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 1f2842ca..58ef01fd 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -292,3 +292,17 @@ api.nvim_create_autocmd("BufWritePost", { end end, }) + +api.nvim_create_autocmd({ "InsertLeave", "TextChanged" }, { + group = api.nvim_create_augroup("auto_save", { clear = true }), + pattern = { "*" }, + desc = "Auto save current file", + callback = function(ev) + local is_readonly = vim.api.nvim_get_option_value("readonly", { buf = ev.buf }) + local is_modifiable = vim.api.nvim_get_option_value("modifiable", { buf = ev.buf }) + + if not is_readonly and is_modifiable then + vim.cmd([[silent! update]]) + end + end, +}) From f5140170ec484eeed000ef00349dd3e99a956a2c Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 14 Apr 2026 19:08:02 +0200 Subject: [PATCH 229/247] Add config for nvim-lint --- lua/config/nvim-lint.lua | 16 ++++++++++++++++ lua/plugin_specs.lua | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100644 lua/config/nvim-lint.lua diff --git a/lua/config/nvim-lint.lua b/lua/config/nvim-lint.lua new file mode 100644 index 00000000..6b416dd7 --- /dev/null +++ b/lua/config/nvim-lint.lua @@ -0,0 +1,16 @@ +local nvim_lint = require("lint") + +nvim_lint.linters_by_ft = { + -- to use vale, install it: `brew install vale` + -- configure it via: https://vale.sh/generator, put config in `.vale.ini` in project root. + -- to install cspell and typos: `brew install cspell typos-cli` + -- markdown = { "vale", "cspell", "typos" }, +} + +vim.api.nvim_create_autocmd({ "InsertLeave" }, { + callback = function() + -- try_lint without arguments runs the linters defined in `linters_by_ft` + -- for the current filetype + nvim_lint.try_lint() + end, +}) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 128a641c..baf1a8e5 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -798,6 +798,12 @@ local plugin_specs = { } end, }, + { + "mfussenegger/nvim-lint", + config = function() + require("config.nvim-lint") + end, + }, } require("lazy").setup { From df541ad75ec03acb3861e526a07e296b54ff9495 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 14 Apr 2026 19:19:23 +0200 Subject: [PATCH 230/247] Add conf for codebook --- lua/lsp_conf.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/lsp_conf.lua b/lua/lsp_conf.lua index b5e2c8ee..687a01c6 100644 --- a/lua/lsp_conf.lua +++ b/lua/lsp_conf.lua @@ -117,6 +117,9 @@ local enabled_lsp_servers = { -- the server can be install via homebrew: brew install golangci-lint-langserver -- golangci-lint also needs to be installed: https://github.com/golangci/golangci-lint golangci_lint_ls = "golangci-lint-langserver", + + -- to install codebook, run `brew install codebook-lsp` + -- codebook = "codebook-lsp" } for server_name, lsp_executable in pairs(enabled_lsp_servers) do From 556b93b303856f4e9550aa83205dfeebac386ba8 Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 14 Apr 2026 23:02:12 +0200 Subject: [PATCH 231/247] fix plugin organization --- lua/plugin_specs.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index baf1a8e5..e5ecac05 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -698,7 +698,7 @@ local plugin_specs = { end, }, -- show and trim trailing whitespaces - { "jdhao/whitespace.nvim", event = "VeryLazy" }, + { "nvim-zh/whitespace.nvim", event = "VeryLazy" }, -- file explorer { From cf547a0284163cf010b86b5df7d61bfab983ff3c Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 14 Apr 2026 23:05:08 +0200 Subject: [PATCH 232/247] update config for neovide --- ginit.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ginit.vim b/ginit.vim index 5c3d0ff3..484510d9 100644 --- a/ginit.vim +++ b/ginit.vim @@ -64,7 +64,7 @@ endif " config for neovide " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if exists("g:neovide") - set guifont=Hack\ NF:h10 + set background=dark let g:neovide_transparency = 1.0 let g:neovide_cursor_animation_length = 0.1 let g:neovide_cursor_trail_size=0.3 From 53e2428ead723672a7858eefbcdfc43c7b9578ff Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 14 Apr 2026 23:10:32 +0200 Subject: [PATCH 233/247] update ui2 config --- lua/ui.lua | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lua/ui.lua b/lua/ui.lua index 7834aabe..fc069d39 100644 --- a/lua/ui.lua +++ b/lua/ui.lua @@ -129,23 +129,22 @@ M.rand_colorscheme() require("vim._core.ui2").enable { enable = true, msg = { -- Options related to the message module. - ---@type 'cmd'|'msg' Default message target, either in the - ---cmdline or in a separate ephemeral message window. - ---@type string|table Default message target - ---or table mapping |ui-messages| kinds and triggers to a target. - targets = "cmd", + targets = { + [""] = "cmd", + empty = "msg", + }, cmd = { -- Options related to messages in the cmdline window. - height = 0.5, -- Maximum height while expanded for messages beyond 'cmdheight'. + height = 0.2, -- Maximum height while expanded for messages beyond 'cmdheight'. }, dialog = { -- Options related to dialog window. - height = 0.5, -- Maximum height. + height = 0.2, -- Maximum height. }, msg = { -- Options related to msg window. - height = 0.5, -- Maximum height. - timeout = 4000, -- Time a message is visible in the message window. + height = 0.2, -- Maximum height. + timeout = 1000, -- Time a message is visible in the message window. }, pager = { -- Options related to message window. - height = 0.5, -- Maximum height. + height = 0.3, -- Maximum height. }, }, } From 2b29bebc922ad178dc74993057c9ddf903b1a072 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 15 Apr 2026 17:17:43 +0200 Subject: [PATCH 234/247] Show vertical help window --- lua/custom-autocmd.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 58ef01fd..96b1a080 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -306,3 +306,13 @@ api.nvim_create_autocmd({ "InsertLeave", "TextChanged" }, { end end, }) + +api.nvim_create_autocmd("FileType", { + group = api.nvim_create_augroup("vertical_help", { clear = true }), + pattern = "help", + desc = "Show help in vertical window", + callback = function(_) + -- L means to put window to leftmost + vim.cmd.wincmd([[L]]) + end, +}) From e300e96a10a6d7efcc0be36f0e773bef4cb81e15 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 15 Apr 2026 17:24:33 +0200 Subject: [PATCH 235/247] Update readme --- README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4c375d68..60512f18 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ and how to set up on different platforms (Linux, macOS, and Windows). + Faster code commenting via [vim-commentary](https://github.com/tpope/vim-commentary). + Faster matching pair insertion and jump via [nvim-autopairs](https://github.com/windwp/nvim-autopairs). + Smarter and faster matching pair management (add, replace or delete) via [vim-sandwich](https://github.com/machakann/vim-sandwich). -+ Fast buffer jump via [hop.nvim](https://github.com/phaazon/hop.nvim). ++ Fast buffer jump via [hop.nvim](https://github.com/smoka7/hop.nvim). + Powerful snippet insertion via [Ultisnips](https://github.com/SirVer/ultisnips). + Beautiful statusline via [lualine.nvim](https://github.com/nvim-lualine/lualine.nvim). + File tree explorer via [nvim-tree.lua](https://github.com/nvim-tree/nvim-tree.lua). @@ -78,7 +78,6 @@ and how to set up on different platforms (Linux, macOS, and Windows). + LaTeX editing and previewing via [vimtex](https://github.com/lervag/vimtex) + Animated GUI style notification via [nvim-notify](https://github.com/rcarriga/nvim-notify). + Tags navigation via [vista](https://github.com/liuchengxu/vista.vim). -+ Undo management via [vim-mundo](https://github.com/simnalamburt/vim-mundo) + Code folding with [nvim-ufo](https://github.com/kevinhwang91/nvim-ufo) and [statuscol.nvim](https://github.com/luukvbaal/statuscol.nvim) + ...... @@ -180,6 +179,8 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu | `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case | | `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case | | `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging | +| `ZR` | Normal | Linux/macOS/Win | Restart nvim without quitting | + # Custom commands @@ -205,10 +206,4 @@ If you still have an issue, [open a new issue](https://github.com/jdhao/nvim-con # Further readings Some of the resources that I find helpful in mastering Nvim is documented [here](docs/nvim_resources.md). -You may also be interested in my posts on configuring Nvim: - -+ My nvim notes can be found [here](https://jdhao.github.io/categories/Nvim/) -+ [Using Neovim for Three years](https://jdhao.github.io/2021/12/31/using_nvim_after_three_years/) -+ [Config nvim on Linux for Python development](https://jdhao.github.io/2018/12/24/centos_nvim_install_use_guide_en/) -+ [Nvim config on Windows 10](https://jdhao.github.io/2018/11/15/neovim_configuration_windows/) -+ [Nvim-qt config on Windows 10](https://jdhao.github.io/2019/01/17/nvim_qt_settings_on_windows/) +You may also be interested in my posts on configuring Nvim [here](https://jdhao.github.io/categories/Nvim/). From ce1e0fb7d52b2a84753b878dcf3e0efb82d8a50a Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 16 Apr 2026 00:31:33 +0200 Subject: [PATCH 236/247] Move config for help file to help.lua --- after/ftplugin/help.lua | 9 +++++++++ lua/custom-autocmd.lua | 10 ---------- 2 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 after/ftplugin/help.lua diff --git a/after/ftplugin/help.lua b/after/ftplugin/help.lua new file mode 100644 index 00000000..2422dc65 --- /dev/null +++ b/after/ftplugin/help.lua @@ -0,0 +1,9 @@ +local win_width = vim.api.nvim_win_get_width(0) + +-- do not change layout if the screen is not wide enough +if win_width < 200 then + return +end + +-- L means to put window to leftmost +vim.cmd.wincmd([[L]]) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 96b1a080..58ef01fd 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -306,13 +306,3 @@ api.nvim_create_autocmd({ "InsertLeave", "TextChanged" }, { end end, }) - -api.nvim_create_autocmd("FileType", { - group = api.nvim_create_augroup("vertical_help", { clear = true }), - pattern = "help", - desc = "Show help in vertical window", - callback = function(_) - -- L means to put window to leftmost - vim.cmd.wincmd([[L]]) - end, -}) From ac613ca1e150231770c79ec0889e04553a6f0e7b Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 16 Apr 2026 13:44:19 +0200 Subject: [PATCH 237/247] feat: q to quit man file --- after/ftplugin/man.lua | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 after/ftplugin/man.lua diff --git a/after/ftplugin/man.lua b/after/ftplugin/man.lua new file mode 100644 index 00000000..b4806d17 --- /dev/null +++ b/after/ftplugin/man.lua @@ -0,0 +1,4 @@ +-- q to quit quickly +vim.keymap.set("n", "q", "q", { + desc = "quit nvim", +}) From 607afd3b98378ca7ebeada6f7186d0400d1b4aa9 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 16 Apr 2026 22:14:21 +0200 Subject: [PATCH 238/247] fzf-lua: read rg config from env --- lua/config/fzf-lua.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/config/fzf-lua.lua b/lua/config/fzf-lua.lua index 9d142678..50cdcb7e 100644 --- a/lua/config/fzf-lua.lua +++ b/lua/config/fzf-lua.lua @@ -15,6 +15,9 @@ require("fzf-lua").setup { -- and https://www.reddit.com/r/linuxquestions/comments/zycvud/ripgrep_respect_gitignore_but_show_env_files/ no_ignore = false, }, + grep = { + RIPGREP_CONFIG_PATH = vim.env.RIPGREP_CONFIG_PATH, + }, } vim.keymap.set("n", "ff", "FzfLua files", { desc = "Fuzzy find files" }) From 3ec9f77cfc874ee73bc9a690dc5abbaa434d3a09 Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 17 Apr 2026 11:47:40 +0200 Subject: [PATCH 239/247] Addref: disable logging --- after/ftplugin/markdown.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/after/ftplugin/markdown.lua b/after/ftplugin/markdown.lua index 662bbeaf..6fb7463c 100644 --- a/after/ftplugin/markdown.lua +++ b/after/ftplugin/markdown.lua @@ -93,7 +93,7 @@ end, { desc = "Add reference link at buffer end", nargs = "+", complete = function(arg_lead, cmdline, curpos) - vim.print(string.format("arg_lead: '%s', cmdline: '%s', curpos: %d", arg_lead, cmdline, curpos)) + -- vim.print(string.format("arg_lead: '%s', cmdline: '%s', curpos: %d", arg_lead, cmdline, curpos)) -- only complete the first argument if count_consecutive_spaces(cmdline) > 1 then From 8bcd7fbc5e7085fdafeac7b2c6157a0fa943ed1e Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 17 Apr 2026 23:54:49 +0200 Subject: [PATCH 240/247] Add colorscheme lake-dweller and alabaster --- lua/plugin_specs.lua | 2 ++ lua/ui.lua | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index e5ecac05..082cd57a 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -162,6 +162,8 @@ local plugin_specs = { { "zootedb0t/citruszest.nvim", priority = 1000 }, { "nyoom-engineering/oxocarbon.nvim", priority = 1000 }, { "ember-theme/nvim", name = "ember", priority = 1000 }, + { "yonatanperel/lake-dweller.nvim", priority = 1000 }, + { "dchinmay2/alabaster.nvim", priority = 1000 }, -- plugins to provide nerdfont icons { diff --git a/lua/ui.lua b/lua/ui.lua index fc069d39..a89058f8 100644 --- a/lua/ui.lua +++ b/lua/ui.lua @@ -107,6 +107,16 @@ M.colorscheme_conf = { ember = function() use_theme("ember") end, + lake_dweller = function() + require("lake-dweller").setup { + -- "lake-dweller", "pond-dweller", or "ocean-dweller" + variant = "lake-dweller", + } + use_theme("lake-dweller") + end, + alabaster = function() + use_theme("alabaster") + end, } --- Use a random colorscheme from the pre-defined list of colorschemes. From d5aa4730d1e539ffbae95bf6839c9a890528a92a Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 23 Apr 2026 22:05:32 +0200 Subject: [PATCH 241/247] bump supported nvim version --- README.md | 2 +- init.lua | 2 +- lua/options.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 60512f18..c836712f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Windows - Neovim minimum version + Neovim minimum version Top languages diff --git a/init.lua b/init.lua index 88b8e361..2a99d778 100644 --- a/init.lua +++ b/init.lua @@ -13,7 +13,7 @@ local utils = require("utils") vim.loader.enable() -local expected_version = "0.12.1" +local expected_version = "0.12.2" utils.is_compatible_version(expected_version) -- some global settings diff --git a/lua/options.lua b/lua/options.lua index 2378d7ba..17ad6e6a 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -119,7 +119,7 @@ opt.showbreak = "↪" opt.wildmode = "list:longest" -- Minimum lines to keep above and below cursor when scrolling -opt.scrolloff = 3 +opt.scrolloff = 999 -- Use mouse to select and resize windows, etc. opt.mouse = "n" From 253bc1bb201e323bb3a841f84a263116a54a5df7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 30 Apr 2026 22:03:13 +0200 Subject: [PATCH 242/247] Remove ltex I don't really use this. --- after/lsp/ltex.lua | 10 ---------- lua/lsp_conf.lua | 1 - 2 files changed, 11 deletions(-) delete mode 100644 after/lsp/ltex.lua diff --git a/after/lsp/ltex.lua b/after/lsp/ltex.lua deleted file mode 100644 index f4be5f48..00000000 --- a/after/lsp/ltex.lua +++ /dev/null @@ -1,10 +0,0 @@ ----@type vim.lsp.Config -return { - filetypes = { "text", "plaintex", "tex", "markdown" }, - ---@type lspconfig.settings.ltex - settings = { - ltex = { - language = "en", - }, - }, -} diff --git a/lua/lsp_conf.lua b/lua/lsp_conf.lua index 687a01c6..dcb06683 100644 --- a/lua/lsp_conf.lua +++ b/lua/lsp_conf.lua @@ -108,7 +108,6 @@ local enabled_lsp_servers = { pyright = "delance-langserver", ruff = "ruff", lua_ls = "lua-language-server", - -- ltex = "ltex-ls", -- clangd = "clangd", vimls = "vim-language-server", bashls = "bash-language-server", From 79c4f9f94ad804a9b340ae5865de4606ca38c433 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 30 Apr 2026 22:09:50 +0200 Subject: [PATCH 243/247] Disable background color for floating win border --- lua/custom-autocmd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index 58ef01fd..57d31a1d 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -179,7 +179,7 @@ api.nvim_create_autocmd("ColorScheme", { vim.api.nvim_set_hl(0, "Cursor2", { fg = "None", bg = "yellow", update = true }) -- For floating windows border highlight - vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen", update = true }) + vim.api.nvim_set_hl(0, "FloatBorder", { bg = "None", fg = "LightGreen", update = true }) -- change the background color of floating window to None, so it blenders better vim.api.nvim_set_hl(0, "NormalFloat", { bg = "None", update = true }) From 8f28ed54e424fef1a55094996c6c4fe221d99701 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 30 Apr 2026 22:16:45 +0200 Subject: [PATCH 244/247] Add theme thorn.nvim --- lua/plugin_specs.lua | 1 + lua/ui.lua | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lua/plugin_specs.lua b/lua/plugin_specs.lua index 082cd57a..e1532a1d 100644 --- a/lua/plugin_specs.lua +++ b/lua/plugin_specs.lua @@ -164,6 +164,7 @@ local plugin_specs = { { "ember-theme/nvim", name = "ember", priority = 1000 }, { "yonatanperel/lake-dweller.nvim", priority = 1000 }, { "dchinmay2/alabaster.nvim", priority = 1000 }, + { "jpwol/thorn.nvim", priority = 1000 }, -- plugins to provide nerdfont icons { diff --git a/lua/ui.lua b/lua/ui.lua index a89058f8..dffaa6d8 100644 --- a/lua/ui.lua +++ b/lua/ui.lua @@ -117,6 +117,9 @@ M.colorscheme_conf = { alabaster = function() use_theme("alabaster") end, + thorn = function() + use_theme("thorn") + end, } --- Use a random colorscheme from the pre-defined list of colorschemes. From 1d00bfaf442e5ae70829e6dde436182e996eb4f9 Mon Sep 17 00:00:00 2001 From: jdhao Date: Sun, 3 May 2026 17:22:00 +0200 Subject: [PATCH 245/247] Configure inlayHints for gopls --- after/lsp/gopls.lua | 5 +++++ lua/lsp_conf.lua | 1 + 2 files changed, 6 insertions(+) diff --git a/after/lsp/gopls.lua b/after/lsp/gopls.lua index 45af9e36..3a2cb7de 100644 --- a/after/lsp/gopls.lua +++ b/after/lsp/gopls.lua @@ -9,6 +9,11 @@ return { }, staticcheck = true, gofumpt = true, + -- inlayHints settings, see https://go.dev/gopls/inlayHints + hints = { + compositeLiteralFields = true, + parameterNames = true, + }, }, }, } diff --git a/lua/lsp_conf.lua b/lua/lsp_conf.lua index dcb06683..dba9727b 100644 --- a/lua/lsp_conf.lua +++ b/lua/lsp_conf.lua @@ -83,6 +83,7 @@ vim.api.nvim_create_autocmd("LspAttach", { client.server_capabilities.hoverProvider = false end + -- TODO: turn this into a command to toggle dynamically -- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint, -- but disable this feature by default, so you may need to enable inlay hint in the LSP server config. -- vim.lsp.inlay_hint.enable(true, {buffer=bufnr}) From 652e95b4c17c4737ef6a214fbe4473e29342da9a Mon Sep 17 00:00:00 2001 From: jdhao Date: Tue, 5 May 2026 18:17:16 +0200 Subject: [PATCH 246/247] feat: use command to control LSP inlayHints --- lua/lsp_conf.lua | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/lua/lsp_conf.lua b/lua/lsp_conf.lua index dba9727b..0474aab3 100644 --- a/lua/lsp_conf.lua +++ b/lua/lsp_conf.lua @@ -82,11 +82,6 @@ vim.api.nvim_create_autocmd("LspAttach", { if client.name == "ruff" then client.server_capabilities.hoverProvider = false end - - -- TODO: turn this into a command to toggle dynamically - -- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint, - -- but disable this feature by default, so you may need to enable inlay hint in the LSP server config. - -- vim.lsp.inlay_hint.enable(true, {buffer=bufnr}) end, nested = true, desc = "Configure buffer keymap and behavior based on LSP", @@ -167,3 +162,33 @@ vim.api.nvim_create_autocmd("LspProgress", { }) end, }) + +-- this controls the LSP inlayHints behavior +vim.g.lsp_inlay_hint_enabled = false + +local update_inlayhint = function(enable) + -- Some LSP server supports inlay hint, but disable this feature by default, so you may need to + -- enable inlay hint in the LSP server config. + vim.lsp.inlay_hint.enable(enable) +end + +vim.api.nvim_create_user_command("LspInlayHints", function(context) + -- vim.print("context", context) + if context["args"] == "enable" then + vim.g.lsp_inlay_hint_enabled = true + end + + if context["args"] == "disable" then + vim.g.lsp_inlay_hint_enabled = false + end + + update_inlayhint(vim.g.lsp_inlay_hint_enabled) +end, { + bang = false, + nargs = 1, + force = true, + desc = "Toggle LSP inlayHints", + complete = function() + return { "enable", "disable" } + end, +}) From ad997f99064a90a52ff56a737d2b31ffaad57213 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 11 May 2026 21:39:01 +0200 Subject: [PATCH 247/247] set up python provider --- lua/globals.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/globals.lua b/lua/globals.lua index 862afac0..e76a6a63 100644 --- a/lua/globals.lua +++ b/lua/globals.lua @@ -1,5 +1,16 @@ local utils = require("utils") +local config_path = vim.fn.stdpath("config") +local python3_path = vim.fs.joinpath(config_path, ".venv/bin/python3") +if not vim.uv.fs_stat(python3_path) then + local msg = string.format( + "Python provider missing:\n create a virtual env under nvim config and install pynvim!" + ) + vim.api.nvim_echo({ { msg } }, true, { err = true }) +else + vim.g.python3_host_prog = python3_path +end + ------------------------------------------------------------------------ -- custom variables -- ------------------------------------------------------------------------