From 002bc7bd3ebd7eaf145a669fec0759f724f2cced Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Sat, 16 May 2026 23:08:26 +0800 Subject: [PATCH] Make ,F full-file reindent opt-in (#69) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `,F` in normal mode mapped `gg=G\`\`` — reindent the entire file with no confirmation. A muscle-typo of `,F` instead of `,f` (LSP format) rewrites the whole buffer, and `=` does not always produce sensible indentation for languages where Vim's internal indent expression is poor. Gate the normal-mode binding behind `g:chopsticks_enable_reindent_file` (default off). The visual-mode binding (`vnoremap F =`) is bounded by the user's selection and stays as default. README's all-keybindings table now marks `,F re-indent (v)` to reflect the visual-only default. Closes #68 --- CHANGELOG.md | 3 +++ README.md | 3 ++- modules/tools.vim | 4 +++- scripts/test.sh | 11 +++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7049262..dafc435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ - `set exrc`/`set secure` are now opt-in via `g:chopsticks_enable_exrc = 1`; Vim no longer sources project-local `.vimrc`/`.exrc` from the working directory by default +- Normal-mode `,F` (reindent the entire file with `gg=G`) is now opt-in + via `g:chopsticks_enable_reindent_file = 1`; visual-mode `,F` (reindent + selection) stays as the default since it's bounded by the user's pick - `,?` 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 diff --git a/README.md b/README.md index 8830ed3..6466ef3 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ let g:chopsticks_enable_completion_keymaps = 1 " optional: Tab/Enter completion let g:chopsticks_enable_auto_pairs = 1 " optional: automatic pair insertion let g:chopsticks_enable_terminal_keymaps = 1 " optional: terminal Esc/Ctrl navigation let g:chopsticks_enable_exrc = 1 " optional: source project-local .vimrc/.exrc from CWD +let g:chopsticks_enable_reindent_file = 1 " optional: ,F reindents the entire file ``` `minimal` avoids LSP, ALE, completion plugins, extra language syntax plugins, @@ -124,7 +125,7 @@ Esc exit insert mode ,? cheat sheet ### Edit -`,S`+2ch jump | `gc` comment | `cs"'` surround | `Alt+j/k` move line | `,u` undo tree | `,y` clipboard | `,*` replace word | `,F` re-indent | `,W` strip whitespace | `[` `]` blank lines +`,S`+2ch jump | `gc` comment | `cs"'` surround | `Alt+j/k` move line | `,u` undo tree | `,y` clipboard | `,*` replace word | `,F` re-indent (v) | `,W` strip whitespace | `[` `]` blank lines ### Git diff --git a/modules/tools.vim b/modules/tools.vim index 098bb75..8506389 100644 --- a/modules/tools.vim +++ b/modules/tools.vim @@ -21,7 +21,9 @@ endfunction " ── Utilities ────────────────────────────────────────────────────────────── -nnoremap F gg=G`` +if get(g:, 'chopsticks_enable_reindent_file', 0) + nnoremap F gg=G`` +endif vnoremap F = nnoremap wa :wa diff --git a/scripts/test.sh b/scripts/test.sh index fd73ed8..38aa0dc 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -246,6 +246,17 @@ check_vim() { -c 'if !&exrc || !&secure | cquit | endif' \ -c 'qa!' 2>&1 + XDG_CONFIG_HOME="$EMPTY_XDG" vim -u .vimrc -i NONE -es -N \ + -c 'if maparg(",F", "n") !=# "" | cquit | endif' \ + -c 'if maparg(",F", "v") !~# "=" | cquit | endif' \ + -c 'qa!' 2>&1 + + XDG_CONFIG_HOME="$EMPTY_XDG" vim -u NONE -i NONE -es -N \ + -c 'let g:chopsticks_enable_reindent_file = 1' \ + -c 'source .vimrc' \ + -c 'if maparg(",F", "n") !~# "gg=G" | cquit | endif' \ + -c 'qa!' 2>&1 + XDG_CONFIG_HOME="$EMPTY_XDG" vim -u .vimrc -i NONE -es -N \ -c 'silent! delcommand LspStatus' \ -c 'silent! delcommand LspInstallServer' \