Vim

From G1Joshi/Agent-Skills · View interactive version

Vim is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Vim assistance covering modal editing, .vimrc configuration, registers, macros, search/replace, and plugin management via vim-plug. Use when editing text efficiently in terminal environments, writing Vimscript, recording macros, or configuring core Vim settings.

How to use this skill

Skill file

Vim

Vim is the universal text editor installed on every UNIX system. While Neovim innovates, Vim focuses on backward compatibility and stability.

When to Use

Quick Start

1. Minimal ~/.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. Core Editing Commands

Core Concepts

Modern Production Vimrc (`~/.vimrc`)

Configuring sensible defaults, plugin manager, and code navigation:

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

" General settings
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

" Leader key mapping
let mapleader = " "

" Fast split navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" Clear search highlight
nnoremap <leader>h :nohlsearch<CR>

Essential Text Objects & Grammar

Combining operators (d, c, y, v) with text objects and motions:

ci"      - Change inside double quotes ("foo" -> "")
di(      - Delete inside parentheses
yap      - Yank (copy) around paragraph
gUiw     - Convert inner word to UPPERCASE
dt,      - Delete from cursor until comma
.        - Repeat last change immediately

Macro Recording & Execution

Automating repetitive tabular data transformations:

1. Press `qa` to start recording macro into register 'a'
2. Perform text editing steps (e.g. `0iconst <Esc>A = true;<Esc>j`)
3. Press `q` to finish recording
4. Replay macro on current line: `@a`
5. Replay macro 50 times across lines: `50@a`
6. Run macro on visual selection: `:'<,'>normal @a`

Common Patterns

Macro Recording and Bulk Execution

Problem: Performing repetitive multi-step editing sequences across hundreds of lines manually.

Solution:

" Record macro to register q:
" qq -> enter normal/insert commands -> q to stop

" Replay macro on current line:
@q

" Replay macro across lines 1 to 50:
:1,50normal @q

Plugin Management with vim-plug

Problem: Install and organize Vim plugins without manual path manipulation.

Solution: Use vim-plug.

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

Run :PlugInstall inside Vim to install.

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| ------------------------------------------------------ | ----------------------------------------- | ---------------------------------------------------------------------------------- |

| System clipboard copy fails ("+y does nothing) | Vim compiled without +clipboard support | Install vim-gtk3 (Ubuntu) or macvim / neovim with clipboard support enabled. |

| Arrow keys insert A, B, C, D characters | Running in strict Vi compatible mode | Add set nocompatible at top of ~/.vimrc. |

| Trailing whitespace highlighting persists after search | Highlight search remained active | Press :nohlsearch or bind <leader>h :nohlsearch<CR>. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.