This repository serves as a quick reference guide for Vim, my favorite editor for focused coding sessions. It includes essential commands and configurations to help you get started with Vim quickly.
For those who want to dive right in, check out the QUICKSTART.md file. It provides a concise reference of essential Vim commands and configurations to get you productive immediately.
- Introduction
- Getting Started with .vimrc
- Vim Modes
- Navigation
- Movement Commands
- File Operations
- Editing Operations
- Copy and Paste
- Visual Mode
Vim is a highly configurable, efficient text editor built to enable fast text editing. Unlike many text editors, Vim has several modes of operation that make it powerful once you understand how to use them.
This guide covers the essential commands and configurations to help you be productive with Vim quickly.
The .vimrc
file is where you configure Vim to suit your preferences. Here's what my basic configuration does:
" Show line numbers and relative line numbers (perfect for fast navigation)
set number relativenumber
" Configure tabs to use 4 spaces
set tabstop=4
set shiftwidth=4
set expandtab
" Enable syntax highlighting
syntax on
" Enable mouse support (if available)
set mouse=a
" Show matching brackets
set showmatch
" Enable incremental search
set incsearch
" Highlight search matches
set hlsearch
" Case insensitive searching
set ignorecase
set smartcase
" Enable auto indent
set autoindent
These settings provide a solid foundation that enhances your Vim experience with:
- Line numbers for easier navigation
- Consistent tab behavior (4 spaces)
- Syntax highlighting for code readability
- Mouse support for easier interaction
- Bracket matching for better code navigation
- Improved search functionality
- Smart indentation
Vim has different modes for different operations:
Mode | Description | How to Enter |
---|---|---|
Normal | Default mode for navigation and commands | Press Esc from any other mode |
Insert | For inserting/editing text | Press i from Normal mode |
Visual | For selecting text | Press v from Normal mode |
Command | For entering commands | Type : from Normal mode |
The fundamental navigation keys in Vim (Normal mode):
Key | Action |
---|---|
h |
Move left |
j |
Move down |
k |
Move up |
l |
Move right |
Remember: navigate in Normal mode (press Esc
to ensure you're in Normal mode).
Faster movement commands in Normal mode:
Command | Action |
---|---|
w |
Jump to the start of the next word |
b |
Jump to the start of the previous word |
e |
Jump to the end of the current/next word |
0 |
Jump to the start of the line |
$ |
Jump to the end of the line |
gg |
Go to the first line of the document |
G |
Go to the last line of the document |
{NUMBER}j |
Move down {NUMBER} lines |
{NUMBER}k |
Move up {NUMBER} lines |
a |
Insert text after the cursor |
A |
Insert text at the end of the line |
Common file operations (Command mode):
Command | Action |
---|---|
:w |
Save the file |
:q |
Quit (fails if unsaved changes) |
:q! |
Force quit (discards unsaved changes) |
:wq or :x |
Save and quit |
:e {filename} |
Open a file for editing |
Basic editing commands (Normal mode):
Command | Action |
---|---|
x |
Delete character under cursor |
dw |
Delete word |
dd |
Delete entire line |
d{NUMBER}d |
Delete {NUMBER} lines |
u |
Undo last action |
Ctrl+r |
Redo last undone action |
r{character} |
Replace character under cursor with {character} |
cw |
Change (replace) word |
Copy and paste operations (Normal mode):
Command | Action |
---|---|
yy |
Yank (copy) current line |
y{NUMBER}y |
Yank {NUMBER} lines |
yw |
Yank word |
p |
Paste after cursor (or below current line) |
P |
Paste before cursor (or above current line) |
Visual mode allows you to select text before performing operations on it:
Command | Action |
---|---|
v |
Enter Visual mode (character-wise) |
Shift+v |
Enter Visual Line mode (selects entire lines) |
Ctrl+v |
Enter Visual Block mode (selects rectangular blocks) |
After selecting text in Visual mode, you can:
- Press
y
to copy the selection - Press
d
to delete the selection - Press
>
to indent or<
to outdent
This guide covers the essentials to get you started with Vim. For more detailed information, check out Vim's built-in help by typing :help
in command mode.