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
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
run: |
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 '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
run: |
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
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
call s:load('env')

View file

@ -19,6 +19,12 @@
### 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,
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

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
```
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.

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.
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

View file

@ -34,7 +34,7 @@ nnoremap <leader>W :%s/\s\+$//<CR>:let @/=''<CR>
vnoremap <leader>W :s/\s\+$//<CR>:let @/=''<CR>gv
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>
vnoremap <leader>* :s///g<Left><Left><Left>
@ -240,12 +240,13 @@ function! s:CheatSheet() abort
execute bufwinnr(l:name) . 'wincmd w | bd'
return
endif
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, [
let l:has_lsp = get(g:, 'chopsticks_enable_lsp', 1)
let l:has_lint = get(g:, 'chopsticks_enable_lint', 1)
let l:has_undotree = exists('g:plugs["undotree"]')
let l:has_previm = exists('g:plugs["previm"]')
let l:lines = [
\ ' chopsticks ,? close',
\ ' ─────────────────────────────',
\ '',
@ -263,6 +264,10 @@ function! s:CheatSheet() abort
\ ' ,fm marks',
\ '',
\ ' ── code ──────────────────',
\ ]
if l:has_lsp
call extend(l:lines, [
\ ' gd definition',
\ ' gy type definition',
\ ' gi implementation',
@ -272,19 +277,37 @@ function! s:CheatSheet() abort
\ ' ,ca code action',
\ ' ,f format',
\ ' ,o outline',
\ ' ,cr run file',
\ ' ,mp markdown preview',
\ ' ,mt table of contents',
\ ' [g ]g LSP diagnostics',
\ ' :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',
\ ' :LspInstallServer setup LSP',
\ ])
endif
call extend(l:lines, [
\ '',
\ ' ── edit ──────────────────',
\ ' gc comment',
\ ' ,S+2ch easymotion jump',
\ ' 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)',
\ ' Alt+j/k move line (v)',
\ ' ,* replace word (v)',
@ -330,6 +353,13 @@ function! s:CheatSheet() abort
\ ' ,sv reload vimrc',
\ ' :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
nnoremap <buffer> <silent> q :bd<CR>
nnoremap <buffer> <silent> <leader>? :bd<CR>