From 74071f74640472b40ee46bcee6082ce759d1984f Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Thu, 9 Apr 2026 12:43:47 +0800 Subject: [PATCH] feat: absorb 15 best practices from top global vim configs (amix, tpope, ThePrimeagen, YADR, spf13) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings (vim-sensible / community consensus): - set ttimeoutlen=10 — eliminates ESC lag in terminal Vim - set display+=lastline — show truncated last line instead of @@@ - set complete-=i — faster Ctrl+n/p by not scanning included files - set wildignorecase — case-insensitive filename completion - set path+=** — recursive :find with wildignore exclusions - set sessionoptions — clean session saves without stale plugin options - Expand wildignore: node_modules, __pycache__, dist, build Visible whitespace: - set listchars (TTY: ASCII; GUI: Unicode symbols) — F6 to toggle Line-length guides (textwidth + colorcolumn=+1): - Python: 88, Go: 120, JS/TS: 100, Rust: 100, Shell: 80 - Markdown: no limit (colorcolumn=0), all others via +1 Autocmds: - ChopstickFormatOptions: formatoptions-=cro on BufEnter (disables auto-comment-continuation — universally desired, overrides filetype plugins) - ChopstickPaste: InsertLeave → set nopaste (prevents broken indent) Key mappings: - vnoremap J/K — move selected lines with =gv re-indent (ThePrimeagen) - gV — reselect last pasted text (`[v`] — spf13, YADR) - cnoremap Ctrl+p/n — command history navigation (amix, spf13) - e — :Explore (built-in file browser, plugin-free fallback) - cd — lcd to current file's directory (was: cd, now window-local) - F6 — toggle visible whitespace - sv — reload vimrc with confirmation echo --- .vimrc | 103 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 83 insertions(+), 20 deletions(-) diff --git a/.vimrc b/.vimrc index 037d62a..b59391a 100644 --- a/.vimrc +++ b/.vimrc @@ -73,9 +73,15 @@ set wildmenu " Make wildmenu behave like similar to Bash completion set wildmode=list:longest -" There are certain files that we would never want to edit with Vim -" Wildmenu will ignore files with these extensions +" Case-insensitive filename completion in wildmenu (spf13, YADR) +set wildignorecase + +" Files and directories to exclude from wildmenu and :find set wildignore=*.docx,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.exe,*.flv,*.img,*.xlsx +set wildignore+=*/node_modules/*,*/.git/*,*/__pycache__/*,*/dist/*,*/build/* + +" Recursive :find across the project tree (works with wildignore above) +set path+=** " Enable mouse support set mouse=a @@ -119,6 +125,11 @@ set novisualbell set t_vb= set tm=500 +" Separate timeout for keycodes (arrow keys, Esc) vs leader sequences +" ttimeoutlen=10 eliminates the ~500ms ESC lag in terminal Vim (vim-sensible) +set ttimeout +set ttimeoutlen=10 + " Enable 256 colors palette in Gnome Terminal if $COLORTERM == 'gnome-terminal' set t_Co=256 @@ -132,6 +143,9 @@ if has("gui_running") set guitablabel=%M\ %t endif +" Show last line partially instead of replacing it with @@@ (vim-sensible) +set display+=lastline + " Use Unix as the standard file type set ffs=unix,dos,mac @@ -288,6 +302,14 @@ endif " => Text, Tab and Indent Related " ============================================================================ +" Visible whitespace characters (toggled with ) +" TTY: ASCII equivalents; GUI/modern terminal: Unicode symbols +if g:is_tty + set listchars=tab:>-,trail:.,extends:>,precedes:<,nbsp:_ +else + set listchars=tab:→\ ,trail:·,extends:▸,precedes:◂,nbsp:· +endif + " Use spaces instead of tabs set expandtab @@ -357,17 +379,30 @@ augroup END " Opens a new tab with the current buffer's path map te :tabedit =expand("%:p:h")/ -" Switch CWD to the directory of the open buffer -map wd :cd %:p:h:pwd +" Change window-local CWD to current file's directory (lcd = local, safer than cd) +map cd :lcd %:p:h:pwd + +" Open built-in file browser (works on any Vim, no plugins needed — tpope) +nnoremap e :Explore " Remap VIM 0 to first non-blank character map 0 ^ -" Move a line of text using ALT+[jk] or Command+[jk] on mac +" Reselect last pasted text (gV = visual select last paste) — spf13, YADR +nnoremap gV `[v`] + +" Command-line history navigation with Ctrl+p/n (amix, spf13) +cnoremap +cnoremap + +" Move a line of text using ALT+[jk] (normal mode) nmap mz:m+`z nmap mz:m-2`z -vmap :m'>+`mzgv`yo`z -vmap :m'<-2`>my`+1gv=gv +vnoremap K :m '<-2gv=gv " Pressing ,ss will toggle and untoggle spell checking map ss :setlocal spell! @@ -387,6 +422,9 @@ nnoremap :set invnumber " Toggle relative line numbers nnoremap :set invrelativenumber +" Toggle visible whitespace (tabs, trailing spaces, non-breaking spaces) +nnoremap :set list! + " Enable folding with the spacebar nnoremap za @@ -863,6 +901,19 @@ fun! CleanExtraSpaces() call setreg('/', old_query) endfun +" Disable auto-insertion of comment leaders when pressing Enter or o/O +" Must run at BufEnter because filetype plugins reset formatoptions per buffer +augroup ChopstickFormatOptions + autocmd! + autocmd BufEnter * setlocal formatoptions-=c formatoptions-=r formatoptions-=o +augroup END + +" Auto-disable paste mode when leaving insert mode (prevents broken indentation) +augroup ChopstickPaste + autocmd! + autocmd InsertLeave * set nopaste +augroup END + augroup ChopstickCleanup autocmd! " Run for real files only; skip special buffers (NERDTree, Startify, terminal, etc.) @@ -885,13 +936,16 @@ augroup ChopstickFiletype autocmd BufNewFile,BufRead *.tsx setlocal filetype=typescript.tsx " Python specific settings - autocmd FileType python setlocal expandtab shiftwidth=4 tabstop=4 colorcolumn=88 + autocmd FileType python setlocal expandtab shiftwidth=4 tabstop=4 textwidth=88 colorcolumn=+1 - " JavaScript specific settings - autocmd FileType javascript,typescript setlocal expandtab shiftwidth=2 tabstop=2 + " JavaScript / TypeScript specific settings + autocmd FileType javascript,typescript setlocal expandtab shiftwidth=2 tabstop=2 textwidth=100 colorcolumn=+1 - " Go specific settings - autocmd FileType go setlocal noexpandtab shiftwidth=4 tabstop=4 + " Go specific settings (standard: no textwidth limit, but 120 is common) + autocmd FileType go setlocal noexpandtab shiftwidth=4 tabstop=4 textwidth=120 colorcolumn=+1 + + " Rust specific settings + autocmd FileType rust setlocal expandtab shiftwidth=4 tabstop=4 textwidth=100 colorcolumn=+1 " HTML/CSS specific settings autocmd FileType html,css setlocal expandtab shiftwidth=2 tabstop=2 @@ -899,11 +953,11 @@ augroup ChopstickFiletype " YAML specific settings autocmd FileType yaml setlocal expandtab shiftwidth=2 tabstop=2 - " Markdown specific settings - autocmd FileType markdown setlocal wrap linebreak spell tw=0 + " Markdown specific settings (no line-length limit; wrap at window edge) + autocmd FileType markdown setlocal wrap linebreak spell textwidth=0 colorcolumn=0 " Shell script settings - autocmd FileType sh setlocal expandtab shiftwidth=2 tabstop=2 + autocmd FileType sh setlocal expandtab shiftwidth=2 tabstop=2 textwidth=80 colorcolumn=+1 " Makefile settings (must use tabs) autocmd FileType make setlocal noexpandtab shiftwidth=8 tabstop=8 @@ -951,6 +1005,9 @@ endfunc set synmaxcol=200 set ttyfast +" Don't scan included files for completion — makes Ctrl+n/p much faster (vim-sensible) +set complete-=i + " Reduce updatetime for better user experience set updatetime=300 @@ -978,6 +1035,10 @@ endif set exrc set secure +" Session options: exclude 'options' (stale plugin settings) and 'globals'; +" include terminal buffers — compatible with vim-obsession/vim-prosession +set sessionoptions=blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal + " ============================================================================ " => Additional Engineering Utilities " ============================================================================ @@ -1006,8 +1067,8 @@ nnoremap so :source % " Edit vimrc quickly nnoremap ev :edit $MYVIMRC -" Reload vimrc -nnoremap sv :source $MYVIMRC +" Reload vimrc with confirmation echo +nnoremap sv :source $MYVIMRC:echo "vimrc reloaded" " Search and replace word under cursor nnoremap * :%s/\<\>//g @@ -1264,9 +1325,9 @@ if exists('g:plugs["vim-which-key"]') \ 'f': 'copy-filename', \ } - " [e]dit group + " [e]dit / [e]xplore group let g:which_key_map['e'] = { - \ 'name': '+edit', + \ 'name': '+edit/explore', \ 'v': 'edit-vimrc', \ } @@ -1331,8 +1392,10 @@ if exists('g:plugs["vim-which-key"]') \ 'name': '+save/window', \ 'a': 'save-all', \ 's': 'workspace-symbols', - \ 'd': 'change-dir', \ } + + " [c]hange-dir (standalone — cd changes window-local CWD) + let g:which_key_map['cd'] = 'change-local-dir' endif " ============================================================================