Xinqi Bao's Git

refactor(nvim): refresh editing and project workflows
authorXinqi Bao <[email protected]>
Thu, 1 Oct 2026 13:40:07 +0000 (21:40 +0800)
committerXinqi Bao <[email protected]>
Thu, 1 Oct 2026 13:40:07 +0000 (21:40 +0800)
.config/nvim/init.vim
.config/nvim/lua/plugin-config/gitsigns.lua [new file with mode: 0644]
.config/nvim/lua/plugin-config/nvim-treesitter.lua

index d38c9ff..ed35c32 100644 (file)
@@ -3,16 +3,14 @@ let mapleader=" "
 
 set background=dark
 set termguicolors
 
 set background=dark
 set termguicolors
-set t_Co=256 "terminal color
-set t_ut=""
-"set term=xterm-256color
 
 "In order to display chinese in GBK
 
 "In order to display chinese in GBK
-"let &termencoding=&encoding
 set fileencodings=utf-8,gbk
 set fileformat=unix
 set foldmethod=indent
 set fileencodings=utf-8,gbk
 set fileformat=unix
 set foldmethod=indent
-set encoding=utf-8 "required for ycm
+set foldlevelstart=99
+set foldlevel=99
+set encoding=utf-8
 
 set tabstop=4
 set softtabstop=4
 
 set tabstop=4
 set softtabstop=4
@@ -71,7 +69,7 @@ endif
 
 call plug#begin()
     Plug 'morhetz/gruvbox'
 
 call plug#begin()
     Plug 'morhetz/gruvbox'
-    Plug 'Yggdroot/indentLine'
+    Plug 'lukas-reineke/indent-blankline.nvim'
     Plug 'christoomey/vim-tmux-navigator'
     Plug 'vim-airline/vim-airline'
 
     Plug 'christoomey/vim-tmux-navigator'
     Plug 'vim-airline/vim-airline'
 
@@ -84,11 +82,10 @@ call plug#begin()
     Plug 'majutsushi/tagbar'
 
     Plug 'MeanderingProgrammer/render-markdown.nvim'
     Plug 'majutsushi/tagbar'
 
     Plug 'MeanderingProgrammer/render-markdown.nvim'
-    Plug 'plasticboy/vim-markdown'
     Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
 
     Plug 'tpope/vim-fugitive'
     Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
 
     Plug 'tpope/vim-fugitive'
-    Plug 'airblade/vim-gitgutter'
+    Plug 'lewis6991/gitsigns.nvim'
     Plug 'kdheepak/lazygit.nvim'
 
     Plug 'neoclide/coc.nvim', {'branch': 'release'}
     Plug 'kdheepak/lazygit.nvim'
 
     Plug 'neoclide/coc.nvim', {'branch': 'release'}
@@ -126,10 +123,22 @@ endif
 " fzf.vim setting
 "----------------------
 if has_key(plugs, 'fzf.vim')
 " fzf.vim setting
 "----------------------
 if has_key(plugs, 'fzf.vim')
-    "mapping for fzf.vim
+    function! s:ProjectRg(query) abort
+        let dir = expand('%:p:h')
+        let dir = isdirectory(dir) ? dir : getcwd()
+        let root = systemlist('git -C ' . shellescape(dir) . ' rev-parse --show-toplevel 2>/dev/null')
+        if v:shell_error || empty(root)
+            echoerr 'Not in a Git repository'
+            return
+        endif
+        call fzf#vim#grep2(
+                    \ 'rg --hidden --glob "!.git" --column --line-number --no-heading --color=always --smart-case -- ',
+                    \ a:query, fzf#vim#with_preview({'dir': root[0]}))
+    endfunction
+
+    command! -nargs=* ProjectRg call <SID>ProjectRg(<q-args>)
     nnoremap <C-p> :GFiles<CR>
     nnoremap <C-p> :GFiles<CR>
-    "as default <C-f>/<C-b> pair used to page down/up entire page
-    nnoremap <C-f> :Tags<CR>
+    nnoremap <C-f> :ProjectRg<CR>
 endif
 
 "----------------------
 endif
 
 "----------------------
@@ -219,11 +228,18 @@ endif
 "----------------------
 if has_key(plugs, 'nvim-treesitter')
     lua require('plugin-config/nvim-treesitter')
 "----------------------
 if has_key(plugs, 'nvim-treesitter')
     lua require('plugin-config/nvim-treesitter')
+endif
+
+if has_key(plugs, 'indent-blankline.nvim')
+    lua require('ibl').setup({ scope = { enabled = false } })
+endif
+
+if has_key(plugs, 'gitsigns.nvim')
+    lua require('plugin-config/gitsigns')
+endif
 
 
-    "set foldmethod=expr
-    set foldmethod=indent
-    set foldexpr=nvim_treesitter#foldexpr()
-    set foldlevel=99
+if has_key(plugs, 'lazygit.nvim')
+    nnoremap <silent> <leader>lg :LazyGit<CR>
 endif
 
 "----------------------
 endif
 
 "----------------------
@@ -251,10 +267,6 @@ nnoremap J :tabprevious<CR>
 nnoremap K :tabnext<CR>
 nnoremap <leader>J :tabmove -1<CR>
 nnoremap <leader>K :tabmove +1<CR>
 nnoremap K :tabnext<CR>
 nnoremap <leader>J :tabmove -1<CR>
 nnoremap <leader>K :tabmove +1<CR>
-nnoremap <C-h> <C-w>h
-nnoremap <C-j> <C-w>j
-nnoremap <C-k> <C-w>k
-nnoremap <C-l> <C-w>l
 nnoremap <leader>" viw<esc>a"<esc>bi"<esc>lel
 nnoremap <leader>' viw<esc>a'<esc>bi'<esc>lel
 nnoremap <silent> <Leader>+ :resize +5<CR>
 nnoremap <leader>" viw<esc>a"<esc>bi"<esc>lel
 nnoremap <leader>' viw<esc>a'<esc>bi'<esc>lel
 nnoremap <silent> <Leader>+ :resize +5<CR>
@@ -273,10 +285,3 @@ xnoremap <C-a> <Nop>
 "HighLight trailing whitespace"
 highlight ExtraWhitespace ctermbg=red guibg=red
 match ExtraWhitespace /\s\+$/
 "HighLight trailing whitespace"
 highlight ExtraWhitespace ctermbg=red guibg=red
 match ExtraWhitespace /\s\+$/
-
-"use powerline-vim for normal use
-"instead of installing for both user and root
-"run to install lib: pip3 install --user powerline-status
-"python3 from powerline.vim import setup as powerline_setup
-"python3 powerline_setup()
-"python3 del powerline_setup
diff --git a/.config/nvim/lua/plugin-config/gitsigns.lua b/.config/nvim/lua/plugin-config/gitsigns.lua
new file mode 100644 (file)
index 0000000..a2526ca
--- /dev/null
@@ -0,0 +1,34 @@
+require('gitsigns').setup({
+  on_attach = function(bufnr)
+    local gs = require('gitsigns')
+    local function map(mode, lhs, rhs)
+      vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, silent = true })
+    end
+
+    map('n', ']c', function()
+      if vim.wo.diff then
+        vim.cmd.normal({ ']c', bang = true })
+      else
+        gs.nav_hunk('next')
+      end
+    end)
+    map('n', '[c', function()
+      if vim.wo.diff then
+        vim.cmd.normal({ '[c', bang = true })
+      else
+        gs.nav_hunk('prev')
+      end
+    end)
+
+    map('n', '<leader>hp', gs.preview_hunk)
+    map('n', '<leader>hs', gs.stage_hunk)
+    map('n', '<leader>hr', gs.reset_hunk)
+    map('n', '<leader>hb', function() gs.blame_line({ full = true }) end)
+    map('x', '<leader>hs', function()
+      gs.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') })
+    end)
+    map('x', '<leader>hr', function()
+      gs.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') })
+    end)
+  end,
+})
index ab75996..9f160e3 100644 (file)
@@ -1,22 +1,21 @@
-require'nvim-treesitter'.setup {
-  -- A list of parser names, or "all"
-  ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
+require('nvim-treesitter').setup {
+  install_dir = vim.fn.stdpath('data') .. '/site',
+}
 
 
-  -- Automatically install missing parsers when entering buffer
-  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
-  auto_install = true,
+local function enable(buf)
+  if not pcall(vim.treesitter.start, buf) then
+    return
+  end
 
 
-  highlight = {
-    enable = true,
+  vim.wo[0][0].foldexpr = 'v:lua.vim.treesitter.foldexpr()'
+  vim.wo[0][0].foldmethod = 'expr'
+end
 
 
-    -- to disable slow treesitter highlight for large files
-    disable = function(lang, buf)
-        local max_filesize = 100 * 1024 -- 100 KB
-        local ok, stats = pcall(vim.uv.fs_stat, vim.api.nvim_buf_get_name(buf))
-        if ok and stats and stats.size > max_filesize then
-            return true
-        end
-    end,
-    additional_vim_regex_highlighting = false,
-  },
-}
+vim.api.nvim_create_autocmd('FileType', {
+  callback = function(args) enable(args.buf) end,
+})
+
+-- Startup filetype detection can precede this config being sourced.
+if vim.bo.filetype ~= '' then
+  enable(0)
+end