Vim and Neovim remain the quintessential modal text editors for developers, platform engineers, and system administrators. Unlike standard GUI editors where keystrokes insert characters, Vim operates through specialized execution modes designed for high-speed text manipulation without touching the mouse.
Key Takeaways
- Master Normal, Insert, Visual, and Command-Line modes for modal editing speed.
- Learn shortcut commands to save and exit Vim cleanly (`:wq`, `:q!`, `ZZ`).
- Leverage text objects (verb + modifier + noun, e.g. `ci"`, `da{`) to edit code blocks instantly.
- Split windows (`:vsp`, `:sp`) and use tabs (`:tabnew`, `gt`) for high-density multi-file editing.
- Automate repetitive multi-step edits across lines using registered macros (`qa`, `@a`).
What is the fundamental mode concept in Vim and Neovim?
Vim is a modal text editor where key behavior depends on the active mode. Pressing Esc always returns the editor to Normal mode, where keystrokes execute navigation and editing commands rather than typing text.
Modes Reference
| Key | Mode | What you can do |
|---|---|---|
| (default) | Normal | Navigate, execute commands, manipulate text |
i | Insert | Type text before the cursor |
a | Insert | Type text after the cursor |
A | Insert | Type text at the end of the line |
o | Insert | Open a new line below and enter Insert mode |
O | Insert | Open a new line above and enter Insert mode |
v | Visual | Highlight and select character blocks |
V | Visual Line | Highlight and select entire lines |
Ctrl+v | Visual Block | Highlight and select rectangular columns |
: | Command | Execute Ex commands (:w, :q, :s) |
/ | Search | Search text forward |
? | Search | Search text backward |
Exiting Vim Shortcuts
| Command | Action |
|---|---|
:q | Quit current window (only if no unsaved changes) |
:q! | Force quit immediately, discarding all unsaved changes |
:w | Save (write) changes without quitting |
:wq | Save changes and quit |
:x | Save changes and quit (identical to :wq) |
ZZ | Save changes and quit (Normal mode shortcut) |
ZQ | Quit without saving (Normal mode shortcut) |
What are the most essential Vim movement and navigation commands?
Vim navigation relies on home-row keys (h, j, k, l) and word/line jump operators to move the cursor without mouse reliance.
Basic, Word & Page Movement
| Key | Movement Action |
|---|---|
h j k l | Move Left · Down · Up · Right |
w | Jump forward to the start of the next word |
W | Jump forward to the next WORD (space-delimited) |
b | Jump backward to the start of the previous word |
e | Jump forward to the end of the word |
0 | Jump to the absolute start of the line |
^ | Jump to the first non-blank character of the line |
$ | Jump to the end of the line |
gg | Jump to the first line of the file |
G | Jump to the last line of the file |
:5 or 5G | Jump directly to line 5 |
Ctrl+d | Scroll down half a page |
Ctrl+u | Scroll up half a page |
Ctrl+f | Scroll down full page |
Ctrl+b | Scroll up full page |
zz | Recenter screen view around the cursor |
% | Jump between matching parentheses, brackets, or braces |
{ } | Jump backward / forward between paragraphs and blank lines |
How do you edit, cut, copy, paste, and undo text in Vim?
Editing in Vim combines verbs (d for delete, c for change, y for yank/copy) with counts and motions to execute atomic edits.
| Command | Action |
|---|---|
x | Delete character under cursor |
X | Delete character before cursor |
dd | Delete (cut) current line |
5dd | Delete 5 consecutive lines |
dw | Delete word from cursor to next word |
d$ or D | Delete from cursor to end of line |
d0 | Delete from cursor to start of line |
yy | Yank (copy) current line |
5yy | Yank 5 lines |
yw | Yank word |
p | Paste copied/cut text after cursor |
P | Paste copied/cut text before cursor |
u | Undo last action |
Ctrl+r | Redo last undone action |
. | Repeat last editing operation |
r | Replace single character under cursor |
R | Enter Replace mode (overtype text) |
cc | Change (delete) line and enter Insert mode |
cw | Change word from cursor |
c$ or C | Change from cursor to end of line |
~ | Toggle case of character under cursor |
gu | Convert selection to lowercase (Visual mode) |
gU | Convert selection to uppercase (Visual mode) |
J | Join current line with the line below |
How do you perform search, replace, and global matching in Vim?
Search and replace uses the substituted Ex command syntax :%s/pattern/replacement/flags to modify patterns globally or within selected lines.
" Replace all occurrences of 'foo' with 'bar' across entire file
:%s/foo/bar/g
" Replace all occurrences with interactive confirmation prompt
:%s/foo/bar/gc
" Case-insensitive global replace
:%s/foo/bar/gi
" Replace only within lines 10 through 30
:10,30s/foo/bar/g
" Replace only within a visual selection (highlight lines, then type :)
:'<,'>s/foo/bar/g
" Delete all blank lines in file
:g/^$/d
" Delete all lines containing 'TODO'
:g/TODO/d
" Clear current search highlighting
:nohHow do you manage split windows, tabs, marks, and text objects?
Window splitting, tab navigation, marks, and text objects provide high-density workspace controls for editing multiple files.
Split Panes & Tabs
| Command | Action |
|---|---|
:sp | Horizontal window split (same file) |
:sp file.js | Horizontal split with another file |
:vsp | Vertical window split |
:vsp file.js | Vertical split with another file |
Ctrl+w h/j/k/l | Move cursor focus between split panes |
Ctrl+w = | Equalize height and width of all split panes |
Ctrl+w _ | Maximize height of current split pane |
Ctrl+w | | Maximize width of current split pane |
:q | Close current split pane |
:tabnew | Open new empty tab page |
:tabnew file.js | Open file in a new tab page |
gt | Switch to next tab page |
gT | Switch to previous tab page |
:tabclose | Close current tab page |
Marks & Jumps
| Command | Action |
|---|---|
ma | Set position mark a at cursor |
`a | Jump to exact line and column of mark a |
'a | Jump to line of mark a |
Ctrl+o | Jump back to previous cursor position |
Ctrl+i | Jump forward to newer cursor position |
'' | Jump back to position before last jump |
Text Objects Grammar
| Text Object | Target Scope | Example Usage |
|---|---|---|
iw | Inner word | ciw (change word under cursor) |
aw | Word + space | daw (delete word and trailing space) |
i" | Inside double quotes | ci" (change text inside "...") |
a" | Double quotes + contents | da" (delete quotes and contents) |
i' | Inside single quotes | ci' (change text inside '...') |
i( or ib | Inside parentheses | ci( (change function arguments) |
a( or ab | Parentheses + contents | da( (delete function call params) |
i{ or iB | Inside curly braces | ci{ (change block body) |
it | Inside HTML/XML tag | cit (change inner tag HTML) |
ip | Inner paragraph | yip (copy inner paragraph) |
How do you use macros to automate repetitive edits?
Macros record a sequence of normal mode keystrokes into a register so they can be replayed across multiple lines.
- Position cursor on the line to edit.
- Press
qato start recording into registera. - Perform your multi-step edit (e.g.
A;<Esc>to add a semicolon). - Press
qto stop recording. - Press
@ato replay the macro once, or10@ato replay 10 times.
What is a recommended modern starter .vimrc configuration?
A clean starter config sets relative line numbers, smart indentation, search highlighting, and system clipboard integration.
" Line numbers
set number
set relativenumber
" Indentation
set tabstop=2
set shiftwidth=2
set expandtab
set autoindent
" Search
set hlsearch
set incsearch
set ignorecase
set smartcase
" UI
set cursorline
set scrolloff=8
set colorcolumn=80
syntax enable
" Mouse support
set mouse=a
" System clipboard & backup
set clipboard=unnamedplus
set noswapfileFrequently Asked Questions
How do I exit Vim if I am stuck?
Press Esc to return to Normal mode, then type :wq and press Enter to save and quit, or :q! to quit without saving changes. For a dedicated guide, read How to Exit Vim, Vi, and Nano.
What is the main difference between Vim and Neovim?
Neovim is a modernized fork of Vim that introduces Lua for configuration and plugins, built-in Language Server Protocol (LSP) support, asynchronous plugin execution, and improved terminal emulator features.
What to Read Next
- Linux Bash Cheat Sheet: Commands & Scripting — Essential terminal commands and shell workflows.
- cURL Command-Line Cheat Sheet — API testing from terminal panes.
- iScreen Suite: Open-Source Browser Productivity — Build Bento-grid launchpads and custom browser widgets.



