From: Xinqi Bao Date: Thu, 1 Oct 2026 13:40:07 +0000 (+0800) Subject: refactor(nvim): refresh editing and project workflows X-Git-Url: https://git.xinqibao.xyz/dotfiles.git/commitdiff_plain/5bf55e7a327bc780b3390b7a42685a2151937011?ds=sidebyside;hp=fc82a603cae257379fc1d37a450535b05916c507 refactor(nvim): refresh editing and project workflows --- diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index d38c9ff..ed35c32 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -3,16 +3,14 @@ let mapleader=" " 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 -"let &termencoding=&encoding 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 @@ -71,7 +69,7 @@ endif 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' @@ -84,11 +82,10 @@ call plug#begin() 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 'airblade/vim-gitgutter' + Plug 'lewis6991/gitsigns.nvim' Plug 'kdheepak/lazygit.nvim' Plug 'neoclide/coc.nvim', {'branch': 'release'} @@ -126,10 +123,22 @@ endif " 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 ProjectRg() nnoremap :GFiles - "as default / pair used to page down/up entire page - nnoremap :Tags + nnoremap :ProjectRg endif "---------------------- @@ -219,11 +228,18 @@ endif "---------------------- 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 lg :LazyGit endif "---------------------- @@ -251,10 +267,6 @@ nnoremap J :tabprevious nnoremap K :tabnext nnoremap J :tabmove -1 nnoremap K :tabmove +1 -nnoremap h -nnoremap j -nnoremap k -nnoremap l nnoremap " viwa"bi"lel nnoremap ' viwa'bi'lel nnoremap + :resize +5 @@ -273,10 +285,3 @@ xnoremap "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 index 0000000..a2526ca --- /dev/null +++ b/.config/nvim/lua/plugin-config/gitsigns.lua @@ -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', 'hp', gs.preview_hunk) + map('n', 'hs', gs.stage_hunk) + map('n', 'hr', gs.reset_hunk) + map('n', 'hb', function() gs.blame_line({ full = true }) end) + map('x', 'hs', function() + gs.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end) + map('x', 'hr', function() + gs.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end) + end, +}) diff --git a/.config/nvim/lua/plugin-config/nvim-treesitter.lua b/.config/nvim/lua/plugin-config/nvim-treesitter.lua index ab75996..9f160e3 100644 --- a/.config/nvim/lua/plugin-config/nvim-treesitter.lua +++ b/.config/nvim/lua/plugin-config/nvim-treesitter.lua @@ -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