diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml new file mode 100644 index 00000000..5cd723bc --- /dev/null +++ b/.github/workflows/format-check.yml @@ -0,0 +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 + uses: JohnnyMorganz/stylua-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: false + - name: Run stylua + run: | + stylua --check . diff --git a/.gitignore b/.gitignore index 75dbbbba..f8e46c0a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ en.utf-8.add.spl .netrwhist *.log .DS_Store +lazy-lock.json +.env* 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/README.md b/README.md index 7116a590..c836712f 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,8 @@ Windows - - Latest release - - Neovim minimum version + Neovim minimum version Top languages @@ -21,9 +18,6 @@ - - - @@ -33,6 +27,9 @@ License + + deepwiki +

@@ -62,28 +59,26 @@ 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). -+ 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). + 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). + 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). -+ 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 @@ -96,10 +91,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 @@ -114,12 +109,6 @@ For more UI demos, check [here](https://github.com/jdhao/nvim-config/issues/15).

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

- -

- ## Tags

@@ -140,6 +129,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 `,`. @@ -155,7 +150,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 | @@ -165,12 +159,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 | -| `gl` | Normal/Visual | Linux/macOS/Win | Get perm link for current/visually-select lines -| `gb` | Normal | macOS | Browse current git repo in browser +| `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 | +| `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 | @@ -180,22 +176,23 @@ 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 | -| `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 | +| `ZR` | Normal | Linux/macOS/Win | Restart nvim without quitting | + # Custom commands 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` | +| `CopyPath` | copy current file path to clipboard | `CopyPath relative` | # Contributing @@ -209,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/). diff --git a/after/ftplugin/go.lua b/after/ftplugin/go.lua new file mode 100644 index 00000000..d28b7db3 --- /dev/null +++ b/after/ftplugin/go.lua @@ -0,0 +1,20 @@ +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() + vim.cmd([[silent !gofumpt -w %]]) +end, { buffer = true, silent = true }) + +vim.keymap.set("n", "", function() + vim.cmd([[!go run %]]) +end, { + buffer = true, + silent = true, +}) 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/after/ftplugin/json.lua b/after/ftplugin/json.lua new file mode 100644 index 00000000..3bcf7051 --- /dev/null +++ b/after/ftplugin/json.lua @@ -0,0 +1,4 @@ +vim.keymap.set({ "n", "v" }, "f", ":JSONFormat", { + buffer = true, + silent = true, +}) 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() 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 910c31da..00000000 --- a/after/ftplugin/lua.vim +++ /dev/null @@ -1,9 +0,0 @@ -" Disable inserting comment leader after hitting o or O or -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/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", +}) diff --git a/after/ftplugin/markdown.lua b/after/ftplugin/markdown.lua new file mode 100644 index 00000000..6fb7463c --- /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