Make Vim help profile aware

This commit is contained in:
m1ngsama 2026-04-30 17:04:53 +08:00
parent a9e16d22d3
commit 7ff5326932
6 changed files with 99 additions and 26 deletions

View file

@ -70,6 +70,13 @@ jobs:
exit 1 exit 1
fi fi
- name: Verify path-safe module loading
run: |
mkdir -p "/tmp/chopsticks path/modules"
cp .vimrc "/tmp/chopsticks path/.vimrc"
cp modules/*.vim "/tmp/chopsticks path/modules/"
vim -u "/tmp/chopsticks path/.vimrc" -i NONE -es -N -c 'qa!' 2>&1
- name: Verify minimal profile - name: Verify minimal profile
run: | run: |
vim -u NONE -i NONE -es -N \ vim -u NONE -i NONE -es -N \
@ -78,6 +85,32 @@ jobs:
-c 'if has_key(g:plugs, "ale") || has_key(g:plugs, "vim-lsp") || has_key(g:plugs, "vim-lsp-settings") || has_key(g:plugs, "asyncomplete.vim") | cquit | endif' \ -c 'if has_key(g:plugs, "ale") || has_key(g:plugs, "vim-lsp") || has_key(g:plugs, "vim-lsp-settings") || has_key(g:plugs, "asyncomplete.vim") | cquit | endif' \
-c 'qa!' 2>&1 -c 'qa!' 2>&1
- name: Verify local config hook
run: |
mkdir -p /tmp/chopsticks-ci
printf "%s\n" "let g:chopsticks_profile = 'minimal'" > /tmp/chopsticks-ci/local.vim
vim -u NONE -i NONE -es -N \
-c 'let g:chopsticks_local_config = "/tmp/chopsticks-ci/local.vim"' \
-c 'source .vimrc' \
-c 'if g:chopsticks_profile !=# "minimal" || has_key(g:plugs, "ale") || has_key(g:plugs, "vim-lsp") | cquit | endif' \
-c 'qa!' 2>&1
- name: Verify profile-aware cheat sheet
run: |
vim -u NONE -i NONE -es -N \
-c 'let g:chopsticks_profile = "minimal"' \
-c 'source .vimrc' \
-c 'normal ,?' \
-c 'redir! > /tmp/chopsticks-cheat.txt' \
-c 'silent %print' \
-c 'redir END' \
-c 'qa!' 2>&1
if grep -Eq 'definition|LspInstallServer|ALE errors|undo tree|markdown preview' /tmp/chopsticks-cheat.txt; then
cat /tmp/chopsticks-cheat.txt
exit 1
fi
grep -q ',cr run file' /tmp/chopsticks-cheat.txt
- name: Verify Markdown quiet defaults - name: Verify Markdown quiet defaults
run: | run: |
vim -u .vimrc -i NONE -es -N README.md \ vim -u .vimrc -i NONE -es -N README.md \

2
.vimrc
View file

@ -9,7 +9,7 @@ if exists('g:chopsticks_loaded') | finish | endif
let g:chopsticks_loaded = 1 let g:chopsticks_loaded = 1
function! s:load(mod) abort function! s:load(mod) abort
execute 'source ' . g:chopsticks_dir . '/modules/' . a:mod . '.vim' execute 'source ' . fnameescape(g:chopsticks_dir . '/modules/' . a:mod . '.vim')
endfunction endfunction
call s:load('env') call s:load('env')

View file

@ -19,6 +19,12 @@
### Changed ### Changed
- `,?` cheat sheet is now profile-aware and hides LSP/ALE/preview/UndoTree keys
when those features are disabled
- Module reload/source paths now use `fnameescape()` so installs in paths with
spaces are handled correctly
- CI now verifies path-safe module loading, the local config hook, and
minimal-profile cheat sheet output
- Markdown now opens in quiet writing mode by default: no real-time markdownlint, - Markdown now opens in quiet writing mode by default: no real-time markdownlint,
no Marksman LSP, no spell noise, no conceal, no sign column, and no realtime preview no Marksman LSP, no spell noise, no conceal, no sign column, and no realtime preview
- Native `s` is no longer shadowed by EasyMotion; use `,S` for the two-character jump - Native `s` is no longer shadowed by EasyMotion; use `,S` for the two-character jump

View file

@ -104,4 +104,7 @@ syntax. Enable the heavier Markdown tools only when you want them.
:ChopsticksStatus see what's installed and what's missing :ChopsticksStatus see what's installed and what's missing
``` ```
The `,?` cheat sheet follows your active profile, so `minimal` users only see
keys for features that are actually loaded.
See [README](README.md) for the full reference. See the [wiki](https://github.com/m1ngsama/chopsticks/wiki) for deep dives. See [README](README.md) for the full reference. See the [wiki](https://github.com/m1ngsama/chopsticks/wiki) for deep dives.

View file

@ -78,7 +78,8 @@ Startify, UndoTree, and browser Markdown preview. `full` keeps those and opts
into Markdown lint, format, spell, conceal, Marksman, and LSP virtual text. into Markdown lint, format, spell, conceal, Marksman, and LSP virtual text.
Project updates leave `~/.config/chopsticks.vim` alone, so put local choices Project updates leave `~/.config/chopsticks.vim` alone, so put local choices
there instead of editing the managed `.vimrc`. there instead of editing the managed `.vimrc`. The `,?` cheat sheet follows the
active profile and only shows keys for enabled features.
## Keys ## Keys

View file

@ -34,7 +34,7 @@ nnoremap <leader>W :%s/\s\+$//<CR>:let @/=''<CR>
vnoremap <leader>W :s/\s\+$//<CR>:let @/=''<CR>gv vnoremap <leader>W :s/\s\+$//<CR>:let @/=''<CR>gv
nnoremap <leader>ev :edit $MYVIMRC<CR> nnoremap <leader>ev :edit $MYVIMRC<CR>
nnoremap <leader>sv :unlet! g:chopsticks_loaded<CR>:source $MYVIMRC<CR>:echo "vimrc reloaded"<CR> nnoremap <leader>sv :unlet! g:chopsticks_loaded<CR>:execute 'source ' . fnameescape($MYVIMRC)<CR>:echo "vimrc reloaded"<CR>
nnoremap <leader>* :%s/\<<C-r><C-w>\>//g<Left><Left> nnoremap <leader>* :%s/\<<C-r><C-w>\>//g<Left><Left>
vnoremap <leader>* :s///g<Left><Left><Left> vnoremap <leader>* :s///g<Left><Left><Left>
@ -240,12 +240,13 @@ function! s:CheatSheet() abort
execute bufwinnr(l:name) . 'wincmd w | bd' execute bufwinnr(l:name) . 'wincmd w | bd'
return return
endif endif
execute 'vertical botright new ' . l:name
vertical resize 42 let l:has_lsp = get(g:, 'chopsticks_enable_lsp', 1)
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile let l:has_lint = get(g:, 'chopsticks_enable_lint', 1)
setlocal nowrap nonumber norelativenumber signcolumn=no let l:has_undotree = exists('g:plugs["undotree"]')
setlocal winfixwidth let l:has_previm = exists('g:plugs["previm"]')
call setline(1, [
let l:lines = [
\ ' chopsticks ,? close', \ ' chopsticks ,? close',
\ ' ─────────────────────────────', \ ' ─────────────────────────────',
\ '', \ '',
@ -263,28 +264,50 @@ function! s:CheatSheet() abort
\ ' ,fm marks', \ ' ,fm marks',
\ '', \ '',
\ ' ── code ──────────────────', \ ' ── code ──────────────────',
\ ' gd definition', \ ]
\ ' gy type definition',
\ ' gi implementation', if l:has_lsp
\ ' gr references', call extend(l:lines, [
\ ' K hover docs', \ ' gd definition',
\ ' ,rn rename', \ ' gy type definition',
\ ' ,ca code action', \ ' gi implementation',
\ ' ,f format', \ ' gr references',
\ ' ,o outline', \ ' K hover docs',
\ ' ,cr run file', \ ' ,rn rename',
\ ' ,mp markdown preview', \ ' ,ca code action',
\ ' ,mt table of contents', \ ' ,f format',
\ ' [g ]g LSP diagnostics', \ ' ,o outline',
\ ' [e ]e ALE errors', \ ' [g ]g LSP diagnostics',
\ ' ,af format on save', \ ' :LspInstallServer setup LSP',
\ ' :LspInstallServer setup LSP', \ ])
endif
call add(l:lines, ' ,cr run file')
if l:has_previm
call add(l:lines, ' ,mp markdown preview')
endif
call add(l:lines, ' ,mt table of contents')
if l:has_lint
call extend(l:lines, [
\ ' [e ]e ALE errors',
\ ' ,af format on save',
\ ])
endif
call extend(l:lines, [
\ '', \ '',
\ ' ── edit ──────────────────', \ ' ── edit ──────────────────',
\ ' gc comment', \ ' gc comment',
\ ' ,S+2ch easymotion jump', \ ' ,S+2ch easymotion jump',
\ ' cs"'' surround', \ ' cs"'' surround',
\ ' ,u undo tree', \ ])
if l:has_undotree
call add(l:lines, ' ,u undo tree')
endif
call extend(l:lines, [
\ ' ,y ,p clipboard y/p (v)', \ ' ,y ,p clipboard y/p (v)',
\ ' Alt+j/k move line (v)', \ ' Alt+j/k move line (v)',
\ ' ,* replace word (v)', \ ' ,* replace word (v)',
@ -330,6 +353,13 @@ function! s:CheatSheet() abort
\ ' ,sv reload vimrc', \ ' ,sv reload vimrc',
\ ' :ChopsticksStatus health', \ ' :ChopsticksStatus health',
\ ]) \ ])
execute 'vertical botright new ' . l:name
vertical resize 42
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
setlocal nowrap nonumber norelativenumber signcolumn=no
setlocal winfixwidth
call setline(1, l:lines)
setlocal nomodifiable readonly setlocal nomodifiable readonly
nnoremap <buffer> <silent> q :bd<CR> nnoremap <buffer> <silent> q :bd<CR>
nnoremap <buffer> <silent> <leader>? :bd<CR> nnoremap <buffer> <silent> <leader>? :bd<CR>