mirror of
https://oauth2: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@github.com/m1ngsama/chopsticks.git
synced 2026-05-10 19:10:59 +08:00
fix: usability and design improvements across .vimrc, install.sh, README
.vimrc:
- Remove global eventignore+=FileType corruption in large file handler
- Add t_8f/t_8b for tmux true color support
- Fix vnoremap J/K shadowing built-in J (join); use Alt+j/k in visual mode
- Replace map with nnoremap for buffer/tab/spell/misc mappings (prevents
visual/operator-pending mode contamination)
- Change BufEnter to FileType for formatoptions (fires less frequently)
- Remove duplicate whitespace trim (ALE already handles it via fix_on_save)
- Guard <leader>so to only source vim files
- Guard <leader>cp/<leader>cf with has('clipboard')
- Add completeopt=popup for floating completion docs (Vim 8.1.1517+)
- Change Startify header from "MINGSAMA" to "chopsticks"
- Make Startify bookmarks conditional (only show shell rc files that exist)
- EasyMotion <Leader>j/k: map → nmap (prevent visual mode leak)
- Move-line: nnoremap instead of nmap for normal mode variant
install.sh:
- Add --help flag
- Support NO_COLOR and non-TTY output (no ANSI codes when redirected)
- Include $BASH_COMMAND in ERR trap for better debugging
- Use mktemp for secure temp files instead of predictable /tmp paths
- Warn user when pip falls back to --break-system-packages
README:
- Add missing mappings: jk, F2-F6, gV, //, ,ev, ,sv, ,cp, ,cf, ,*, ,F, ,W, ,ms, ,ss
- Note that some language servers require Node.js even though vim-lsp doesn't
- Clarify Alt+j/k works in both normal and visual mode
This commit is contained in:
parent
0ba2e84e0c
commit
233ceabf53
3 changed files with 113 additions and 68 deletions
104
.vimrc
104
.vimrc
|
|
@ -160,6 +160,9 @@ call plug#end()
|
|||
" ============================================================================
|
||||
|
||||
if g:has_true_color && has('termguicolors') && !g:is_tty
|
||||
" Required for true color inside tmux
|
||||
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
|
||||
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
|
||||
set termguicolors
|
||||
endif
|
||||
|
||||
|
|
@ -216,20 +219,20 @@ nmap <leader>q :q<cr>
|
|||
nmap <leader>x :x<cr>
|
||||
|
||||
" Clear search highlight
|
||||
map <silent> <leader><cr> :noh<cr>
|
||||
nnoremap <silent> <leader><cr> :noh<cr>
|
||||
|
||||
" Buffer navigation
|
||||
map <leader>bd :Bclose<cr>
|
||||
map <leader>ba :bufdo bd<cr>
|
||||
map <leader>l :bnext<cr>
|
||||
map <leader>h :bprevious<cr>
|
||||
nnoremap <leader>bd :Bclose<cr>
|
||||
nnoremap <leader>ba :bufdo bd<cr>
|
||||
nnoremap <leader>l :bnext<cr>
|
||||
nnoremap <leader>h :bprevious<cr>
|
||||
|
||||
" Tab management
|
||||
map <leader>tn :tabnew<cr>
|
||||
map <leader>to :tabonly<cr>
|
||||
map <leader>tc :tabclose<cr>
|
||||
map <leader>tm :tabmove
|
||||
map <leader>t<leader> :tabnext<cr>
|
||||
nnoremap <leader>tn :tabnew<cr>
|
||||
nnoremap <leader>to :tabonly<cr>
|
||||
nnoremap <leader>tc :tabclose<cr>
|
||||
nnoremap <leader>tm :tabmove
|
||||
nnoremap <leader>t<leader> :tabnext<cr>
|
||||
|
||||
let g:lasttab = 1
|
||||
nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
|
||||
|
|
@ -238,8 +241,8 @@ augroup ChopstickTabHistory
|
|||
autocmd TabLeave * let g:lasttab = tabpagenr()
|
||||
augroup END
|
||||
|
||||
map <leader>te :tabedit <C-r>=expand("%:p:h")<cr>/
|
||||
map <leader>cd :lcd %:p:h<cr>:pwd<cr>
|
||||
nnoremap <leader>te :tabedit <C-r>=expand("%:p:h")<cr>/
|
||||
nnoremap <leader>cd :lcd %:p:h<cr>:pwd<cr>
|
||||
|
||||
" File browser (netrw — built-in, no plugins)
|
||||
nnoremap <leader>e :Explore<CR>
|
||||
|
|
@ -255,18 +258,18 @@ nnoremap gV `[v`]
|
|||
cnoremap <C-p> <Up>
|
||||
cnoremap <C-n> <Down>
|
||||
|
||||
" Move lines
|
||||
nmap <M-j> mz:m+<cr>`z
|
||||
nmap <M-k> mz:m-2<cr>`z
|
||||
vnoremap J :m '>+1<CR>gv=gv
|
||||
vnoremap K :m '<-2<CR>gv=gv
|
||||
" Move lines (Alt+j / Alt+k in both normal and visual mode)
|
||||
nnoremap <M-j> :m .+1<CR>==
|
||||
nnoremap <M-k> :m .-2<CR>==
|
||||
vnoremap <M-j> :m '>+1<CR>gv=gv
|
||||
vnoremap <M-k> :m '<-2<CR>gv=gv
|
||||
|
||||
" Spell checking
|
||||
map <leader>ss :setlocal spell!<cr>
|
||||
map <leader>sn ]s
|
||||
map <leader>sp [s
|
||||
map <leader>sa zg
|
||||
map <leader>s? z=
|
||||
nnoremap <leader>ss :setlocal spell!<cr>
|
||||
nnoremap <leader>sn ]s
|
||||
nnoremap <leader>sp [s
|
||||
nnoremap <leader>sa zg
|
||||
nnoremap <leader>s? z=
|
||||
|
||||
" Toggle modes
|
||||
set pastetoggle=<F2>
|
||||
|
|
@ -506,7 +509,11 @@ let g:lsp_signs_warning = {'text': '!'}
|
|||
let g:lsp_signs_information = {'text': 'i'}
|
||||
let g:lsp_signs_hint = {'text': '>'}
|
||||
|
||||
set completeopt=menuone,noinsert,noselect
|
||||
if has('patch-8.1.1517')
|
||||
set completeopt=menuone,noinsert,noselect,popup
|
||||
else
|
||||
set completeopt=menuone,noinsert,noselect
|
||||
endif
|
||||
set pumheight=15
|
||||
let g:asyncomplete_auto_popup = 1
|
||||
let g:asyncomplete_auto_completeopt = 1
|
||||
|
|
@ -587,9 +594,9 @@ let g:EasyMotion_smartcase = 1
|
|||
" s + two chars: jump anywhere on screen
|
||||
nmap s <Plug>(easymotion-overwin-f2)
|
||||
|
||||
" J/K: line motions
|
||||
map <Leader>j <Plug>(easymotion-j)
|
||||
map <Leader>k <Plug>(easymotion-k)
|
||||
" Line motions
|
||||
nmap <Leader>j <Plug>(easymotion-j)
|
||||
nmap <Leader>k <Plug>(easymotion-k)
|
||||
|
||||
" ============================================================================
|
||||
" => UndoTree
|
||||
|
|
@ -620,12 +627,12 @@ endif
|
|||
|
||||
if exists('g:plugs["vim-startify"]')
|
||||
let g:startify_custom_header = [
|
||||
\ ' ███╗ ███╗ ██╗███╗ ██╗ ██████╗ ███████╗ █████╗ ███╗ ███╗ █████╗ ',
|
||||
\ ' ████╗ ████║███║████╗ ██║██╔════╝ ██╔════╝██╔══██╗████╗ ████║██╔══██╗ ',
|
||||
\ ' ██╔████╔██║╚██║██╔██╗ ██║██║ ███╗███████╗███████║██╔████╔██║███████║ ',
|
||||
\ ' ██║╚██╔╝██║ ██║██║╚██╗██║██║ ██║╚════██║██╔══██║██║╚██╔╝██║██╔══██║ ',
|
||||
\ ' ██║ ╚═╝ ██║ ██║██║ ╚████║╚██████╔╝███████║██║ ██║██║ ╚═╝ ██║██║ ██║ ',
|
||||
\ ' ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝',
|
||||
\ ' ██████╗██╗ ██╗ ██████╗ ██████╗ ███████╗████████╗██╗ ██████╗██╗ ██╗███████╗',
|
||||
\ ' ██╔════╝██║ ██║██╔═══██╗██╔══██╗██╔════╝╚══██╔══╝██║██╔════╝██║ ██╔╝██╔════╝',
|
||||
\ ' ██║ ███████║██║ ██║██████╔╝███████╗ ██║ ██║██║ █████╔╝ ███████╗',
|
||||
\ ' ██║ ██╔══██║██║ ██║██╔═══╝ ╚════██║ ██║ ██║██║ ██╔═██╗ ╚════██║',
|
||||
\ ' ╚██████╗██║ ██║╚██████╔╝██║ ███████║ ██║ ██║╚██████╗██║ ██╗███████║',
|
||||
\ ' ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝',
|
||||
\ '',
|
||||
\ ]
|
||||
|
||||
|
|
@ -636,11 +643,16 @@ if exists('g:plugs["vim-startify"]')
|
|||
\ { 'type': 'bookmarks', 'header': [' Bookmarks'] },
|
||||
\ ]
|
||||
|
||||
let g:startify_bookmarks = [
|
||||
\ {'v': '~/.vimrc'},
|
||||
\ {'z': '~/.zshrc'},
|
||||
\ {'b': '~/.bashrc'},
|
||||
\ ]
|
||||
let g:startify_bookmarks = [{'v': '~/.vimrc'}]
|
||||
if filereadable(expand('~/.zshrc'))
|
||||
call add(g:startify_bookmarks, {'z': '~/.zshrc'})
|
||||
endif
|
||||
if filereadable(expand('~/.bashrc'))
|
||||
call add(g:startify_bookmarks, {'b': '~/.bashrc'})
|
||||
endif
|
||||
if filereadable(expand('~/.config/fish/config.fish'))
|
||||
call add(g:startify_bookmarks, {'f': '~/.config/fish/config.fish'})
|
||||
endif
|
||||
|
||||
let g:startify_session_persistence = 1
|
||||
let g:startify_session_autoload = 1
|
||||
|
|
@ -797,7 +809,7 @@ endfunc
|
|||
" Suppress comment continuation on Enter / o / O
|
||||
augroup ChopstickFormatOptions
|
||||
autocmd!
|
||||
autocmd BufEnter * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
|
||||
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
|
||||
augroup END
|
||||
|
||||
" Auto-disable paste mode on leaving insert
|
||||
|
|
@ -806,13 +818,6 @@ augroup ChopstickPaste
|
|||
autocmd InsertLeave * set nopaste
|
||||
augroup END
|
||||
|
||||
" Strip trailing whitespace on save (real files only)
|
||||
augroup ChopstickCleanup
|
||||
autocmd!
|
||||
autocmd BufWritePre *
|
||||
\ if empty(&buftype) && !empty(expand('<afile>')) | call CleanExtraSpaces() | endif
|
||||
augroup END
|
||||
|
||||
augroup ChopstickFiletype
|
||||
autocmd!
|
||||
|
||||
|
|
@ -907,7 +912,7 @@ nnoremap <leader><leader> <c-^>
|
|||
nnoremap <leader>W :%s/\s\+$//<CR>:let @/=''<CR>
|
||||
|
||||
" Source helpers
|
||||
nnoremap <leader>so :source %<CR>
|
||||
nnoremap <leader>so :if &filetype ==# 'vim' <Bar> source % <Bar> echo "Sourced " . expand('%') <Bar> else <Bar> echo "Not a vim file" <Bar> endif<CR>
|
||||
nnoremap <leader>ev :edit $MYVIMRC<CR>
|
||||
nnoremap <leader>sv :source $MYVIMRC<CR>:echo "vimrc reloaded"<CR>
|
||||
|
||||
|
|
@ -915,8 +920,10 @@ nnoremap <leader>sv :source $MYVIMRC<CR>:echo "vimrc reloaded"<CR>
|
|||
nnoremap <leader>* :%s/\<<C-r><C-w>\>//g<Left><Left>
|
||||
|
||||
" Copy path / filename to clipboard
|
||||
nnoremap <leader>cp :let @+ = expand("%:p")<CR>:echo "Copied: " . expand("%:p")<CR>
|
||||
nnoremap <leader>cf :let @+ = expand("%:t")<CR>:echo "Copied: " . expand("%:t")<CR>
|
||||
if has('clipboard')
|
||||
nnoremap <leader>cp :let @+ = expand("%:p")<CR>:echo "Copied: " . expand("%:p")<CR>
|
||||
nnoremap <leader>cf :let @+ = expand("%:t")<CR>:echo "Copied: " . expand("%:t")<CR>
|
||||
endif
|
||||
|
||||
" Scratch markdown buffer
|
||||
nnoremap <leader>ms :e ~/buffer.md<cr>
|
||||
|
|
@ -981,7 +988,6 @@ augroup END
|
|||
function! LargeFileSettings()
|
||||
setlocal bufhidden=unload
|
||||
setlocal undolevels=-1
|
||||
setlocal eventignore+=FileType
|
||||
setlocal noswapfile
|
||||
setlocal syntax=
|
||||
let b:ale_enabled = 0
|
||||
|
|
|
|||
22
README.md
22
README.md
|
|
@ -124,6 +124,10 @@ Supported languages and their servers:
|
|||
| Markdown | marksman |
|
||||
| SQL | sqls |
|
||||
|
||||
**Note:** While vim-lsp itself needs no Node.js, some language servers (TypeScript,
|
||||
HTML, CSS, JSON, YAML) are npm packages that require Node.js to run. Python (pylsp),
|
||||
Go (gopls), and Rust (rust-analyzer) language servers do not need Node.js.
|
||||
|
||||
**Markdown LSP** requires `marksman` as a standalone binary:
|
||||
|
||||
```bash
|
||||
|
|
@ -203,8 +207,14 @@ Press `,?` at any time to open the built-in cheat sheet.
|
|||
| `Space` | Toggle code fold |
|
||||
| `Y` | Yank to end of line |
|
||||
| `Ctrl+d` / `Ctrl+u` | Half-page scroll, cursor centred |
|
||||
| `Alt+j` / `Alt+k` | Move line down / up |
|
||||
| `Alt+j` / `Alt+k` | Move line down / up (normal and visual) |
|
||||
| `,u` | Undo tree (visual branch history) |
|
||||
| `F2` | Toggle paste mode |
|
||||
| `F3` / `F4` | Toggle line numbers / relative numbers |
|
||||
| `F5` | Toggle undo tree |
|
||||
| `F6` | Toggle invisible characters |
|
||||
| `gV` | Reselect last paste |
|
||||
| `//` | Search visual selection |
|
||||
|
||||
### Survival
|
||||
|
||||
|
|
@ -212,7 +222,8 @@ Press `,?` at any time to open the built-in cheat sheet.
|
|||
|-----|--------|
|
||||
| `jk` | Exit insert mode |
|
||||
| `Esc` | Exit insert / visual mode |
|
||||
| `Ctrl+s` | Save |
|
||||
| `jk` | Exit insert mode |
|
||||
| `Ctrl+s` | Save (any mode) |
|
||||
| `,w` | Save |
|
||||
| `,x` | Save and quit |
|
||||
| `,q` | Quit |
|
||||
|
|
@ -227,6 +238,13 @@ Press `,?` at any time to open the built-in cheat sheet.
|
|||
| `Esc Esc` | Exit terminal mode |
|
||||
| `,tn` / `,tc` | New tab / close tab |
|
||||
| `,tl` | Toggle to last tab |
|
||||
| `,ev` / `,sv` | Edit / reload `~/.vimrc` |
|
||||
| `,cp` / `,cf` | Copy file path / filename to clipboard |
|
||||
| `,*` | Search and replace word under cursor |
|
||||
| `,F` | Re-indent entire file |
|
||||
| `,W` | Strip trailing whitespace |
|
||||
| `,ms` | Open scratch markdown buffer |
|
||||
| `,ss` | Toggle spell checking |
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
53
install.sh
53
install.sh
|
|
@ -1,23 +1,41 @@
|
|||
#!/usr/bin/env bash
|
||||
# install.sh - chopsticks vim configuration installer
|
||||
# Usage: cd /path/to/chopsticks && ./install.sh [--yes]
|
||||
# Usage: cd /path/to/chopsticks && ./install.sh [--yes] [--help]
|
||||
#
|
||||
# --yes non-interactive: install all optional components automatically
|
||||
# --help show this help and exit
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
AUTO_YES=0
|
||||
[[ "${1:-}" == "--yes" ]] && AUTO_YES=1
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--yes) AUTO_YES=1 ;;
|
||||
--help|-h)
|
||||
echo "Usage: ./install.sh [OPTIONS]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --yes Non-interactive mode: select all defaults automatically"
|
||||
echo " --help Show this help and exit"
|
||||
echo ""
|
||||
echo "Supported platforms: macOS (brew), Debian/Ubuntu (apt), Arch (pacman), Fedora (dnf)"
|
||||
exit 0 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ── Colours ───────────────────────────────────────────────────────────────────
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
BOLD='\033[1m'
|
||||
CYAN='\033[0;36m'
|
||||
DIM='\033[2m'
|
||||
NC='\033[0m'
|
||||
# ── Colours (respect NO_COLOR and non-TTY) ───────────────────────────────────
|
||||
if [[ -t 1 ]] && [[ -z "${NO_COLOR:-}" ]]; then
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
BOLD='\033[1m'
|
||||
CYAN='\033[0;36m'
|
||||
DIM='\033[2m'
|
||||
NC='\033[0m'
|
||||
else
|
||||
GREEN='' YELLOW='' RED='' BOLD='' CYAN='' DIM='' NC=''
|
||||
fi
|
||||
|
||||
ok() { echo -e "${GREEN}[OK]${NC} $1"; }
|
||||
warn() { echo -e "${YELLOW}[!]${NC} $1"; }
|
||||
|
|
@ -50,13 +68,14 @@ ask() {
|
|||
|
||||
# ── Error trap ────────────────────────────────────────────────────────────────
|
||||
on_error() {
|
||||
echo -e "\n${RED}[FATAL]${NC} Unexpected error at line ${BASH_LINENO[0]}." >&2
|
||||
echo -e "\n${RED}[FATAL]${NC} Command '${BASH_COMMAND}' failed at line ${BASH_LINENO[0]}." >&2
|
||||
echo " To get a full debug log:" >&2
|
||||
echo " ./install.sh 2>&1 | tee /tmp/chopsticks-install.log" >&2
|
||||
echo " Report issues: https://github.com/m1ngsama/chopsticks/issues" >&2
|
||||
}
|
||||
trap on_error ERR
|
||||
trap 'rm -f /tmp/chopsticks-hadolint /tmp/chopsticks-marksman 2>/dev/null' EXIT
|
||||
_TMPDIR=$(mktemp -d "${TMPDIR:-/tmp}/chopsticks-XXXXXX")
|
||||
trap 'rm -rf "$_TMPDIR" 2>/dev/null' EXIT
|
||||
|
||||
# ── Safe download helper ──────────────────────────────────────────────────────
|
||||
safe_download() {
|
||||
|
|
@ -604,7 +623,7 @@ elif [[ $HAS_APT -eq 1 ]]; then
|
|||
else
|
||||
_do_binary_apt "hadolint" hadolint "$_I_HADOLINT" \
|
||||
"https://github.com/hadolint/hadolint/releases/download/${HVER}/hadolint-Linux-${HARCH}" \
|
||||
/tmp/chopsticks-hadolint
|
||||
"$_TMPDIR/hadolint"
|
||||
fi
|
||||
else
|
||||
skip "hadolint"; SKIPPED+=("hadolint")
|
||||
|
|
@ -621,7 +640,7 @@ elif [[ $HAS_APT -eq 1 ]]; then
|
|||
else
|
||||
_do_binary_apt "marksman" marksman "$_I_MARKSMAN" \
|
||||
"https://github.com/artempyanykh/marksman/releases/download/${MVER}/marksman-linux-${MARCH}" \
|
||||
/tmp/chopsticks-marksman
|
||||
"$_TMPDIR/marksman"
|
||||
fi
|
||||
else
|
||||
skip "marksman"; SKIPPED+=("marksman")
|
||||
|
|
@ -714,8 +733,10 @@ else
|
|||
if command -v "$check" >/dev/null 2>&1; then
|
||||
ok "$pkg (already installed)"; return
|
||||
fi
|
||||
if pip3 install --quiet "$pkg" 2>/dev/null || \
|
||||
pip3 install --quiet --break-system-packages "$pkg" 2>/dev/null; then
|
||||
if pip3 install --quiet "$pkg" 2>/dev/null; then
|
||||
ok "$pkg"; INSTALLED+=("$pkg")
|
||||
elif pip3 install --quiet --break-system-packages "$pkg" 2>/dev/null; then
|
||||
warn "$pkg installed with --break-system-packages (consider using a virtualenv)"
|
||||
ok "$pkg"; INSTALLED+=("$pkg")
|
||||
else
|
||||
fail "$pkg"; FAILED+=("$pkg")
|
||||
|
|
|
|||
Loading…
Reference in a new issue