Skip to content

Vim 9.1+ config optimization: DX, cleanup, lazy-loading#10

Open
tony wants to merge 15 commits intomasterfrom
vim/optimize
Open

Vim 9.1+ config optimization: DX, cleanup, lazy-loading#10
tony wants to merge 15 commits intomasterfrom
vim/optimize

Conversation

@tony
Copy link
Owner

@tony tony commented Mar 14, 2026

Summary

Comprehensive optimization of the Vim configuration targeting DX ergonomics, dead code removal, architecture fixes, and startup performance. Each commit is atomic and independently revertible.

Bug Fixes

  • Fix <Leader>p conflict: <Leader>p was mapped to both copy-path (line 27) and :bprevious (line 109), with bprevious silently winning. Restored copy-path intent, consolidated buffer nav to <Leader>]/[ only
  • Fix autochdir vs vim-rooter conflict: autochdir silently undoes vim-rooter's directory changes on every buffer switch, breaking LSP and FZF working directory expectations
  • Fix lib#ColorSchemeExists side effect: replaced colorscheme <name> try/catch (which applies every scheme in the fallback chain) with side-effect-free globpath() check

Dead Code Removal

  • Remove BufClose config (references removed plugin), javascript_enable_domhtmlcss (no consumer), set ttyfast (always-on in Vim 9.1), empty v:version >= 800 block, commented-out gruvbox-material
  • Remove obsolete version guards from sensible.vim (has('autocmd'), v:version > 703, fish shell fix for Vim < 7.4.276)

Plugin Audit

  • Remove sonokai (not in colorscheme fallback chain)
  • Remove ag.vim (superseded by FZF+ripgrep)
  • Remove nvim-yarp + vim-hug-neovim-rpc (unused since wilder sets use_python_remote_plugin=0)
  • Remove typescript-vim (yats.vim is a superset with TSX support)
  • Remove vim-autoformat (consolidated formatting to ALE + CoC)

New Features

  • lightline.vim statusline with coc-git branch display and ALE diagnostic counts (E:/W:), live-updated via CocGitStatusChange and ALELintPost hooks
  • <leader>f remapped from primitive gg=G re-indent to CocActionAsync('format') for LSP-aware formatting
  • JSON/TOML added to CoC formatOnSave scope (replaces vim-autoformat's dprint)
  • b:biome_checked guard + b:coc_preferences_formatOnSave=false prevents ALE+CoC double-format when Biome is detected

Startup Performance

  • NERDTree: lazy-loaded on first command (NERDTreeFocus/NERDTreeToggle/NERDTree)
  • Copilot: deferred to BufReadPost ++once (front-loads Node.js init while user reads file)
  • Language plugins: filetype-based lazy loading for Dockerfile, TypeScript, Vue, MDX, JSX, HTML template literals, Rust, Terraform, and Elixir plugins

Stats

  • 10 files changed: 84 insertions, 91 deletions (net -7 lines)
  • 5 plugins removed, 1 plugin added (lightline.vim)
  • 10+ plugins now lazy-loaded by command or filetype

Test plan

  • just test — 13 passed (hermetic core + startup suites)
  • just test-integration — 2 passed (gated plugins + project root)
  • Manual: verify <Leader>p copies path, <Leader>]/[ navigate buffers
  • Manual: open git-tracked file, verify branch in statusline
  • Manual: save .ts file with/without biome.json, verify single formatter
  • Manual: <leader>e opens NERDTree (lazy-loaded)
  • Manual: Copilot suggestions work after opening a file

tony added 15 commits March 14, 2026 16:08
…ppings

why: <Leader>p mapped to both copy-path (line 27) and
     bprevious (line 109), with bprevious silently winning;
     multiple duplicate buffer navigation bindings existed
what:
- Keep <Leader>p for copy file path (restore original intent)
- Consolidate buffer nav to <Leader>]/[ only (nnoremap)
- Keep single <Leader><BS> for :BB (alt buffer)
- Remove duplicate <leader>3 format mapping (keep <leader>f)
- Remove commented-out arrow resize and nerdcommenter mappings
- Fix <Leader>]/[ from map to nnoremap (convention fix)
why: BufClose config references a removed plugin; version
     guards and ttyfast are no-ops on Vim 9.1+;
     javascript_enable_domhtmlcss is read by no installed
     plugin or Vim 9.1 runtime file
what:
- Remove BufClose config from autocmd.vim (g:BufClose_AltBuffer,
  cnoreabbr bq)
- Remove dead javascript_enable_domhtmlcss variable
- Remove commented-out gruvbox-material from plugins.vim
- Remove empty v:version >= 800 block from vimrc
- Remove no-op set ttyfast from vimrc
why: autochdir silently undoes vim-rooter's directory changes
     on every buffer switch, breaking LSP working directory
     expectations and making :Rg/:FZFRoot behavior
     unpredictable
what:
- Remove set autochdir from vimrc
- vim-rooter (manual mode), <space> FZFRoot, and :Rooter
  remain available for project-root navigation
why: lib#ColorSchemeExists executes 'colorscheme <name>' to
     check existence, which fires ColorScheme autocommands
     and pollutes highlight groups as a side effect; every
     scheme in the fallback chain gets applied then discarded
what:
- Replace try/catch colorscheme with globpath-based check
- Remove gruvbox-material from fallback chain (plugin not
  installed)
- Update test allowed colorscheme list
why: sonokai not in colorscheme fallback chain (dead weight);
     ag.vim superseded by FZF+ripgrep (:Rg, :RG, <C-F>);
     nvim-yarp/vim-hug-neovim-rpc unused since wilder.nvim
     sets use_python_remote_plugin=0
what:
- Remove sonokai from plugin declarations
- Remove ag.vim from s:conditional_plugins
- Remove nvim-yarp and vim-hug-neovim-rpc from Vim 8 branch
- Update gated_plugins.vim test assertions
why: yats.vim is a superset of typescript-vim with TSX
     support; loading both risks syntax highlight conflicts
what:
- Remove leafgarland/typescript-vim from node conditional
  plugins
- Update gated_plugins.vim test assertions
why: Three formatting systems (ALE fix_on_save, coc-prettier,
     vim-autoformat) could conflict; <leader>f used Vim's
     primitive gg=G re-indent instead of LSP formatting
what:
- Remove vim-autoformat plugin (dprint JSON/TOML formatting)
- Add JSON/TOML to CoC formatOnSave scope in coc-settings
- Add b:biome_checked guard to avoid redundant findfile()
- Set b:coc_preferences_formatOnSave=false when Biome is
  detected to prevent ALE+CoC double-format
- Remap <leader>f to CocActionAsync('format') for LSP-aware
  formatting
why: No statusline means no visibility into git branch,
     ALE diagnostics, or file state during editing
what:
- Add lightline.vim plugin with CoC-git and ALE integration
- Add LightlineGitStatus component using g:coc_git_status
  and b:coc_git_status
- Add LightlineALE component showing E:/W: diagnostic counts
- Hook CocGitStatusChange and ALELintPost for live updates
- Remove manual rulerformat from settings.vim (lightline
  handles statusline)
why: Version checks for Vim < 7.4 are dead code on Vim 9.1+;
     fish shell fix targeted a Vim 7.4 bug that was patched
     long ago
what:
- Flatten always-true has('autocmd') conditional
- Flatten always-true v:version > 703 formatoptions guard
- Remove always-false fish shell fix for Vim < 7.4.276
- Keep nvim compat guard, t_Co terminal check, matchit load
why: NERDTree loads on every startup but is only used
     on-demand via <leader>e; lazy loading defers its cost
what:
- Add 'on' option to defer NERDTree until NERDTreeFocus,
  NERDTreeToggle, or NERDTree commands are called
- g:NERDTreeShowHidden and g:NERDTreeIgnore are set eagerly
  at startup via global vars (unaffected by lazy loading)
why: Copilot starts a Node.js process on VimEnter; deferring
     to BufReadPost gives it time to initialize while the
     user reads the file, avoiding startup cost
what:
- Use plug#load on BufReadPost ++once to lazy-load copilot
- g:copilot_filetypes config set eagerly (unaffected by
  deferred loading)
- BufReadPost chosen over InsertEnter to front-load Node.js
  initialization before user enters insert mode
why: Language plugins load on every startup but are only
     needed when editing matching filetypes
what:
- Restructure s:conditional_plugins entries to support
  [spec, opts] lists alongside plain strings
- Add type() dispatch in loop to pass opts to PlugIfCommand
- Add 'for' lazy-load option to Dockerfile, yats, vue, mdx,
  jsx-improve, html-template-literals, rust, terraform, and
  elixir plugins
- vim-plug loads ftdetect/ even for lazy plugins, so
  filetype detection is unaffected
why: Provide comprehensive coverage of vim-rooter behavior
     across auto/manual modes, non-project fallbacks, and
     autochdir interactions before changing rooter config
what:
- Add 11 parametrized scenarios via pytest + generated
  Vimscript suites exercising FindRootDirectory() and cwd
- Cover auto-rooter with .git, Pipfile, deep nesting,
  non-project current/empty fallback, manual :Rooter,
  autochdir interactions, and multiple root markers
- Note autochdir limitation in Vim headless Ex mode
why: With autochdir removed (commit ec78fa8), enable
     vim-rooter auto mode for LazyVim-like project root DX;
     'current' fallback preserves :e relative-to-file
     behavior for non-project files (the original 2018
     autochdir motivation from commit 5e7996d)
what:
- Set g:rooter_manual_only = 0 (was 1)
- Set g:rooter_change_directory_for_non_project_files
  to 'current' for autochdir-like fallback
why: With g:rooter_manual_only = 0, the BufEnter autocmd
     changes cwd before any manual :Rooter invocation;
     the old manual-mode assertion is now invalid
what:
- Rename Test_rooter_command_changes_to_project_root to
  Test_rooter_auto_changes_to_project_root
- Assert cwd equals project root immediately after
  VimTestOpen (no explicit :Rooter needed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant