From fd081a239715e2b157cbdfa6c9ec61361a17098b Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Wed, 13 May 2026 14:32:50 +0800 Subject: [PATCH] Make Ctrl-S save opt-in (#42) * Make Ctrl-S save opt in * Avoid hanging CI Vim installation * Keep Homebrew Vim on macOS CI --- .github/workflows/test.yml | 6 +++++- .vimrc | 2 ++ QUICKSTART.md | 1 - README.md | 3 ++- modules/core.vim | 6 ++++-- modules/tools.vim | 1 - scripts/test.sh | 10 +++++++++- 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b237e6..f97cab4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,11 +16,15 @@ jobs: - uses: actions/checkout@v4 - name: Install Vim + timeout-minutes: 5 run: | if [ "$(uname)" = "Darwin" ]; then brew install vim + elif command -v vim >/dev/null 2>&1; then + vim --version | head -1 else - sudo apt-get update && sudo apt-get install -y vim + sudo apt-get update + sudo apt-get install -y vim fi - name: Install vim-plug diff --git a/.vimrc b/.vimrc index a9d76f0..535c074 100644 --- a/.vimrc +++ b/.vimrc @@ -11,6 +11,8 @@ endif if exists('g:chopsticks_loaded') | finish | endif let g:chopsticks_loaded = 1 +let g:surround_no_insert_mappings = get(g:, 'surround_no_insert_mappings', 1) + function! s:load(mod) abort execute 'source ' . fnameescape(g:chopsticks_dir . '/modules/' . a:mod . '.vim') endfunction diff --git a/QUICKSTART.md b/QUICKSTART.md index 55e8ca0..0486976 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -39,7 +39,6 @@ Esc back to Normal ,w save ,x save + quit :q! force quit -Ctrl+s save from any mode ,? cheat sheet (toggle sidebar) ``` diff --git a/README.md b/README.md index 6a9cbac..5e78f4b 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ let g:chopsticks_profile = 'minimal' " core navigation/editing/git/markdown let g:chopsticks_profile = 'engineer' " default: LSP, ALE, syntax extras let g:chopsticks_profile = 'full' " engineer + heavier Markdown feedback let g:chopsticks_enable_jk_escape = 1 " optional: insert-mode jk exits insert +let g:chopsticks_enable_ctrl_s_save = 1 " optional: Ctrl-S saves ``` `minimal` avoids LSP, ALE, completion plugins, extra language syntax plugins, @@ -217,7 +218,7 @@ Each module is self-contained. Comment out one line in `.vimrc` to disable it. A | Plugins not loading | `:PlugInstall` then `:PlugUpdate` | | LSP not starting | `:LspInstallServer` for current filetype | | Colors wrong | `export COLORTERM=truecolor` in shell rc | -| `Ctrl+s` freezes | `stty -ixon` in shell rc | +| Optional `Ctrl+s` freezes | `stty -ixon` in shell rc | | Everything slow | Large file? Auto-disabled >10MB | | What's installed? | `:ChopsticksStatus` shows tools, LSP, linters | diff --git a/modules/core.vim b/modules/core.vim index 3757409..7f59a18 100644 --- a/modules/core.vim +++ b/modules/core.vim @@ -137,8 +137,10 @@ nnoremap N Nzzzv vnoremap // y/\V=escape(@",'/\') -nnoremap :w -inoremap :w +if get(g:, 'chopsticks_enable_ctrl_s_save', 0) + nnoremap :w + inoremap :w +endif nnoremap zz vnoremap zz diff --git a/modules/tools.vim b/modules/tools.vim index a131483..0aa1ca6 100644 --- a/modules/tools.vim +++ b/modules/tools.vim @@ -422,7 +422,6 @@ function! s:CheatSheet() abort \ ' ,w save', \ ' ,q quit', \ ' ,x save + quit', - \ ' Ctrl+s save (any mode)', \ ' Esc exit insert', \ ' :w!! sudo save', \ ' ,ev edit vimrc', diff --git a/scripts/test.sh b/scripts/test.sh index c05a4e5..84b6b5e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -204,6 +204,7 @@ check_vim() { XDG_CONFIG_HOME="$EMPTY_XDG" vim -u .vimrc -i NONE -es -N \ -c 'if maparg("0", "n") !=# "" || maparg("0", "v") !=# "" || maparg("Y", "n") !=# "" || maparg("Q", "n") !=# "" || maparg("", "n") !=# "" | cquit | endif' \ -c 'if maparg("jk", "i") !=# "" | cquit | endif' \ + -c 'if maparg("", "n") !=# "" || maparg("", "i") !=# "" | cquit | endif' \ -c 'if maparg("", "n") !=# "" || maparg("", "n") !=# "" || maparg("", "n") !=# "" || maparg("", "n") !=# "" | cquit | endif' \ -c 'if maparg("", "n") !=# "" | cquit | endif' \ -c 'if maparg(",ff", "n") !~# "SmartFiles" | cquit | endif' \ @@ -215,6 +216,13 @@ check_vim() { -c 'if maparg("jk", "i") !~# "" | cquit | endif' \ -c 'qa!' 2>&1 + XDG_CONFIG_HOME="$EMPTY_XDG" vim -u NONE -i NONE -es -N \ + -c 'let g:chopsticks_enable_ctrl_s_save = 1' \ + -c 'source .vimrc' \ + -c 'if maparg("", "n") !~# ":w" | cquit | endif' \ + -c 'if maparg("", "i") !~# ":w" | 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' \ @@ -275,7 +283,7 @@ check_vim() { grep -Fq ',dk hover docs' "$TMP_ROOT/cheat-default.txt" grep -Fq ',dp ,dn LSP diagnostics' "$TMP_ROOT/cheat-default.txt" grep -Fq 'hjkl navigate splits' "$TMP_ROOT/cheat-default.txt" - if grep -Eq 'Ctrl\\+p find file|Ctrl\\+hjkl navigate splits|jk exit insert|gd definition|K hover docs|\\[g \\]g LSP diagnostics' "$TMP_ROOT/cheat-default.txt"; then + if grep -Eq 'Ctrl\\+p find file|Ctrl\\+hjkl navigate splits|Ctrl\\+s save|jk exit insert|gd definition|K hover docs|\\[g \\]g LSP diagnostics' "$TMP_ROOT/cheat-default.txt"; then cat "$TMP_ROOT/cheat-default.txt" exit 1 fi