Communitygithub.com

G1Joshi/Agent-Skills / Vim 專家

專業的 Vim 輔助技能,涵蓋模式編輯、.vimrc 設定、暫存器、巨集、搜尋取代及透過 vim-plug 的套件管理。適合在終端環境中高效編輯文字、編寫 Vimscript、錄製巨集或設定核心 Vim 設定時使用。

Agent-Skills / Vim 專家 是什麼?

此技能提供 Vim 編輯器的深入專業知識,專注於其在通用 Unix/伺服器環境中的穩定與向後相容特性。它能協助開發者進行系統設定編輯、高效的文字操作(如運用運算子-動作語法)、以及終端機環境中的自動化巨集錄製與批次執行。技能內容涵蓋最簡化的 .vimrc 設定、核心編輯命令、文字物件與動作的組合應用,以及透過 vim-plug 進行套件管理等實務模式。此外,還包含 2026 年的最佳實務建議,例如強調模式導航與文字物件的熟練使用,並提供常見問題的故障排除指引,例如處理剪貼簿支援、相容性模式與搜尋反白的問題。此技能適用於 Claude Code、Cursor 及任何整合 AI 代理的開發環境,特別是需要在無法隨意安裝軟體的遠端終端機中進行高效文字處理的情境。

相容平台~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/G1Joshi/Agent-Skills/tree/HEAD/skills/tools/vim

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Vim

Vim 是安裝在每個 UNIX 系統上的通用文字編輯器。雖然 Neovim 持續創新,但 Vim 專注於向後相容性與穩定性。

使用時機

  • 通用伺服器與系統編輯:在任 Unix/Linux 伺服器上編輯系統設定、腳本和程式碼,無需安裝額外軟體。
  • 模式化文字處理:使用運算子-動作語法(dap、ci"、gUiw)組合文字轉換。
  • 無頭巨集自動化:錄製並重播重複的編輯操作,橫跨數百行程式碼(qa、@a)。
  • Git 提交與合併編輯:快速互動式編輯提交訊息、互動式變基以及差異衝突解決。

快速入門

1. 最簡 ~/.vimrc

syntax on
set number
set relativenumber
set tabstop=2
set shiftwidth=2
set expandtab
set hlsearch
set incsearch
set clipboard=unnamed

let mapleader = " "
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>

2. 核心編輯命令

  • i / a:插入模式(游標前 / 後)
  • ci":更改雙引號內內容
  • da{:刪除大括號周圍內容
  • :%s/foo/bar/g:取代檔案中所有 foo 為 bar
  • .:重複上次修改

核心概念

現代化的生產力 Vimrc(~/.vimrc)

設定合理的預設值、套件管理器和程式碼導航:

" ~/.vimrc
set nocompatible
filetype plugin indent on
syntax on

" 一般設定
set number
set relativenumber
set expandtab
set shiftwidth = 2
set tabstop = 2
set autoindent
set smartindent
set hlsearch
set incsearch
set ignorecase
set smartcase
set hidden
set backspace=indent,eol,start
set updatetime=300
set clipboard=unnamed

" 前導鍵映射
let mapleader = " "

" 快速分割視窗導航
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" 清除搜尋反白
nnoremap <leader>h :nohlsearch<CR>

必備文字物件與語法

結合運算子(d、c、y、v)與文字物件及動作:

ci"      - 更改雙引號內內容("foo" -> "")
di(      - 刪除括號內內容
yap      - 複製(Yank)整個段落
gUiw     - 將內單字轉為大寫
dt,      - 從游標刪除至逗號
.        - 立即重複上次修改

巨集錄製與執行

自動化重複的表格資料轉換:

1. 按下 `qa` 開始將巨集錄製到暫存器 'a'
2. 執行文字編輯步驟(例如 `0iconst <Esc>A = true;<Esc>j`)
3. 按下 `q` 結束錄製
4. 在當前行重播巨集:`@a`
5. 在多行程式碼上重播巨集 50 次:`50@a`
6. 在視覺選取範圍上執行巨集:`:'<,'>normal @a`

常見模式

巨集錄製與批次執行

問題:在多行程式碼中執行重複的多步驟編輯。 解決方案:將按鍵序列錄製到暫存器 q。

  1. 將游標置於目標起始位置。
  2. 按下 qq 開始錄製到暫存器 q。
  3. 執行編輯序列(例如 I" <Esc> A",<Esc> j ^)。
  4. 按下 q 停止錄製。
  5. 使用 @q 重播,或在 50 行程式碼中執行:50@q。

使用 vim-plug 進行套件管理

問題:安裝與組織 Vim 套件,無需手動管理路徑。 解決方案:使用 vim-plug。

call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-fugitive'
Plug 'preservim/nerdtree'
call plug#end()

在 Vim 內部執行 :PlugInstall 來安裝。

最佳實務(2026)

  • 務必熟練模式導航(h、j、k、l、w、b、e),並避免使用方向鍵。
  • 務必善用文字物件(ciw、da(、yi{)以最少的按鍵編輯結構化程式碼區塊。
  • 務必使用 dot 命令(.)在相似行上重複最近的文字轉換。
  • 務必啟用 set hidden,讓緩衝區能保持在背景而不強制立即儲存。
  • 切勿安裝數百個笨重的舊版 VimScript 套件;若需要豐富的 IDE 體驗,請轉向 Neovim Lua。
  • 切勿遺留交換檔(.swp);請設定 set noswapfile 或指定專用的交換目錄。
  • 切勿在 ~/.vimrc 中使用同步的外部呼叫,以免在遠端機器上造成明顯的啟動延遲。

故障排除

錯誤 / 症狀原因解決方案
系統剪貼簿複製失敗("+y 無作用)Vim 編譯時未啟用 +clipboard 支援安裝 vim-gtk3(Ubuntu)或啟用剪貼簿支援的 macvim / neovim。
方向鍵插入 A、B、C、D 字元以嚴格的 Vi 相容模式執行在 ~/.vimrc 開頭加入 set nocompatible。
搜尋後結尾空白反白持續存在搜尋反白仍然啟用按下 :nohlsearch 或綁定 <leader>h :nohlsearch<CR> 快捷鍵。

參考資料

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

G1Joshi/Agent-Skills

Expert Dask distributed computing assistance covering Dask DataFrames, Arrays, Futures, and cluster scaling. Use when analyzing datasets too large for pandas on a single machine or multi-node cluster.

G1Joshi/Agent-Skills

Expert dbt (data build tool) assistance covering SQL modeling, Jinja macros, tests, documentation, and semantic layer. Use when building analytics engineering pipelines on BigQuery, Snowflake, or PostgreSQL.

G1Joshi/Agent-Skills

Expert JAX assistance covering Autograd, XLA compilation (`jit`), vectorization (`vmap`), and parallelization (`pmap`). Use when building high-performance numerical computing and cutting-edge deep learning research.

G1Joshi/Agent-Skills

Expert Ray distributed computing assistance covering Ray Core (actors, tasks), Ray Train, Ray Tune, and Ray Serve. Use when scaling Python compute and ML training across multi-node clusters.

G1Joshi/Agent-Skills

Expert Git version control assistance covering branching, interactive rebase, cherry-pick, submodules, worktrees, and conflict resolution. Use when managing source code history and collaboration workflows.

G1Joshi/Agent-Skills

Expert K9s CLI assistance covering terminal Kubernetes cluster navigation, real-time log streaming, port forwarding, and pod debugging. Use when managing and troubleshooting Kubernetes clusters with speed.

G1Joshi/Agent-Skills

Expert SWC assistance covering high-performance Rust-based JavaScript/TypeScript compilation, .swcrc configuration, Jest testing via @swc/jest, and minification. Use when replacing Babel with SWC for faster builds, accelerating test execution, or compiling modern ECMAScript features.

G1Joshi/Agent-Skills

Expert Tig assistance covering text-mode interface for Git, interactive staging, commit graph visualization, diff exploration, and blame navigation. Use when navigating Git commit history in the terminal, staging hunks interactively, browsing file changes, or reviewing revisions.

G1Joshi/Agent-Skills

Expert Zed editor assistance covering high-performance Rust-based text editing, multi-buffer editing, language server protocols (LSP), and AI assistant integrations. Use when configuring Zed settings.json, setting up language extensions, collaborating in real-time channels, or optimizing editor startup speed.

G1Joshi/Agent-Skills

Expert Zsh assistance covering shell customization, Oh My Zsh plugins, Zinit plugin manager, prompt engineering (Starship/Powerlevel10k), and shell scripting. Use when configuring .zshrc, writing Zsh automation scripts, optimizing shell startup time, or configuring tab-completion.

G1Joshi/Agent-Skills

Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].

相關技能