Neovim Survival Guide π
Core Concepts
The 3 Main Modes:
NORMAL mode β Navigate and commands (default when opening)
INSERT mode β Edit text (like normal editor)
VISUAL mode β Select text
Golden rule: Always return to NORMAL mode with Esc
To learn on interetarive mode, open nvim and type
:Tutor
1. OPEN AND QUIT (most important!)
# OPEN
nvim file.ex # Open specific file
nvim . # Open in current directory
nvim +10 file.ex # Open at line 10
# QUIT
:q # Quit
:q! # Force quit (discard changes)
:w # Write (save)
:wq # Write and quit
:x # Write and quit (shortcut)
ZZ # Save and quit (in NORMAL mode)
ZQ # Quit without saving (in NORMAL mode)
# EMERGENCY (everything frozen?)
Esc Esc :q! Enter # Force quit from any situation
2. MODES (enter and exit)
# ENTER INSERT MODE (to edit)
i # Insert before cursor
a # Append after cursor
I # Insert at beginning of line
A # Append at end of line
o # Open new line below
O # Open new line above
# EXIT INSERT MODE
Esc # Return to NORMAL mode
Ctrl+[ # Alternative to Esc
Ctrl+c # Alternative to Esc
# ENTER VISUAL MODE
v # Visual mode (character)
V # Visual LINE mode (entire line)
Ctrl+v # Visual BLOCK mode (block/column)
# EXIT VISUAL MODE
Esc # Return to NORMAL mode
v # Toggle off
3. BASIC NAVIGATION (NORMAL mode)
Character movement:
h # β Left (the left key)
j # β Down (J as a arrow)
k # β Up
l # β Right (the right key)
# Tip: Practice hjkl for 5 minutes = never forget
Word movement:
w # Word β next word
b # Back β previous word
e # End β end of word
ge # End β end of previous word
W, B, E # Same, but considers punctuation
Line movement:
0 # Beginning of line (column 0)
^ # First non-blank character
$ # End of line
g_ # Last non-blank character
File movement:
gg # Beginning of file (line 1)
G # End of file
:10 # Go to line 10
10G # Go to line 10 (alternative)
50% # Go to 50% of file
Ctrl+d # Half page DOWN
Ctrl+u # Half page UP
Ctrl+f # Full page forward
Ctrl+b # Full page backward
Contextual movement:
{ # Previous paragraph
} # Next paragraph
( # Previous sentence
) # Next sentence
% # Go to matching parenthesis/brace
4. SEARCH (find text)
/text # Search "text" forward
?text # Search "text" backward
n # Next occurrence
N # Previous occurrence
* # Search word under cursor (forward)
# # Search word under cursor (backward)
:noh # No highlight (clear highlight)
5. BASIC EDITING
Delete (and auto-copy):
x # Delete character under cursor
X # Delete character before cursor
dd # Delete entire line
dw # Delete word (to next word)
d$ # Delete to end of line
D # Delete to end of line (shortcut)
d0 # Delete to beginning of line
Copy (yank):
yy # Yank (copy) entire line
yw # Yank word
y$ # Yank to end of line
Y # Yank entire line (shortcut)
Paste:
p # Paste after cursor/line
P # Paste before cursor/line
Undo/Redo:
u # Undo
Ctrl+r # Redo
U # Undo all changes on line
Replace:
r # Replace one character
R # Replace mode (overwrite)
cw # Change word (delete and enter INSERT)
cc # Change line (delete and enter INSERT)
C # Change to end of line
s # Substitute character
S # Substitute line
Duplicate:
yyp # Duplicate line below
yyP # Duplicate line above
6. VISUAL SELECTION (VISUAL mode)
v # Enter visual mode
V # Visual LINE mode
Ctrl+v # Visual BLOCK mode
# After selecting:
d # Delete selection
y # Yank (copy) selection
c # Change (delete and insert)
> # Indent (increase indentation)
< # Dedent (decrease indentation)
Quick selections:
viw # Visual Inner Word
vaw # Visual A Word (includes space)
vi" # Visual inside quotes "..."
va" # Visual quotes + content
vi( # Visual inside parentheses (...)
vi{ # Visual inside braces {...}
vit # Visual Inner Tag (HTML)
7. SEARCH AND REPLACE
# Replace in current line
:s/old/new/ # First occurrence
:s/old/new/g # All in line (global)
# Replace in entire file
:%s/old/new/g # All in file
:%s/old/new/gc # All, asking confirmation
# Replace in range
:10,20s/old/new/g # Lines 10-20
:'<,'>s/old/new/g # Visual selection
8. MULTIPLE FILES
Buffers (open files):
:e file.ex # Edit (open) file
:bnext # Next buffer
:bprev # Previous buffer
:b name # Go to buffer "name"
:bd # Buffer delete (close)
:ls # List buffers
Splits (split screen):
:split file # Horizontal split
:vsplit file # Vertical split
Ctrl+w s # Horizontal split (current buffer)
Ctrl+w v # Vertical split (current buffer)
# Navigate between splits
Ctrl+w h # Go to left split
Ctrl+w j # Go to split below
Ctrl+w k # Go to split above
Ctrl+w l # Go to right split
Ctrl+w w # Cycle between splits
# Resize splits
Ctrl+w = # Equalize sizes
Ctrl+w > # Increase width
Ctrl+w < # Decrease width
Ctrl+w + # Increase height
Ctrl+w - # Decrease height
# Close splits
:q # Close current split
Ctrl+w q # Close current split
Ctrl+w o # Close others (only)
Tabs:
:tabnew file # New tab
gt # Next tab
gT # Previous tab
:tabclose # Close tab
9. COMMANDS WITH NUMBERS (multipliers)
# Repeat action N times
5j # Move down 5 lines
3w # Move forward 3 words
10dd # Delete 10 lines
4yy # Copy 4 lines
2p # Paste 2 times
# Go to specific line
:42 # Go to line 42
42G # Go to line 42 (alternative)
10. MACROS (record command sequence)
qa # Record macro in register 'a'
# ... execute commands ...
q # Stop recording
@a # Execute macro 'a'
@@ # Repeat last macro
10@a # Execute macro 'a' 10 times
11. USEFUL DAILY COMMANDS
# Indentation
>> # Indent line
<< # Dedent line
== # Auto-indent line
gg=G # Auto-indent entire file
# Join (join lines)
J # Join line below with current
# Uppercase/Lowercase
gU # Uppercase (in visual mode)
gu # Lowercase (in visual mode)
~ # Toggle case of character
# Numbers
Ctrl+a # Increment number
Ctrl+x # Decrement number
# Repeat (repeat last command)
. # Repeat last action
12. TELESCOPE (fuzzy finder) - Kickstart.nvim
<leader>ff # Find Files
<leader>fg # Find Grep (search text)
<leader>fb # Find Buffers
<leader>fh # Find Help
# Inside Telescope
Ctrl+n / Ctrl+j # Next result
Ctrl+p / Ctrl+k # Previous result
Enter # Open file
Esc # Close Telescope
13. LSP (Language Server) - Kickstart.nvim
gd # Go to Definition
gr # Go to References
K # Hover (documentation)
<leader>rn # Rename
<leader>ca # Code Action
[d # Previous diagnostic
]d # Next diagnostic
14. GIT (in Neovim)
:Git # Open Fugitive (if installed)
:Git status # Git status
:Git commit # Git commit
:Git push # Git push
# Gitsigns (Kickstart.nvim)
]c # Next hunk
[c # Previous hunk
<leader>hs # Stage hunk
<leader>hr # Reset hunk
<leader>hp # Preview hunk
15. TERMINAL IN NEOVIM
:terminal # Open terminal
:term # Shortcut
# In terminal
Ctrl+\ Ctrl+n # Return to NORMAL mode
i # Return to terminal (INSERT)
:q # Close terminal
16. EMERGENCY COMMANDS
# Frozen? Force quit
Esc Esc :q! Enter
# Readonly file?
:w !sudo tee % # Save with sudo
# Lost changes?
:earlier 10m # Go back 10 minutes
:later 5m # Go forward 5 minutes
# Reload file
:e! # Reload (discard changes)
:e # Reload (if no changes)
17. USEFUL SETTINGS
# Show line numbers
:set number # Absolute numbers
:set relativenumber # Relative numbers
:set number relativenumber # Both
# Search
:set ignorecase # Ignore case when searching
:set smartcase # Case-sensitive if uppercase present
# Indentation
:set expandtab # Use spaces instead of tabs
:set tabstop=2 # Tab = 2 spaces
:set shiftwidth=2 # Indent = 2 spaces
# View current setting
:set number? # Shows current value
18. HELP (built-in help)
:help # Open help
:help w # Help about command 'w'
:help :split # Help about command :split
:help i_<Esc> # Help about Esc in INSERT mode
:help v_d # Help about 'd' in VISUAL mode
Ctrl+] # Follow link in help
Ctrl+o # Go back in help
:q # Close help
COMPACT CHEATSHEET (print this)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
NEOVIM SURVIVAL GUIDE
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
QUIT: :q :q! :wq ZZ
MODES: i a o Esc v V
NAVIGATE: hjkl w b gg G Ctrl+d Ctrl+u
SEARCH: /text n N * #
EDIT: dd yy p u Ctrl+r
VISUAL: viw vi" vi( va{
REPLACE: :%s/old/new/g
SPLITS: Ctrl+w v Ctrl+w s Ctrl+w hjkl
TELESCOPE: <leader>ff <leader>fg <leader>fb
LSP: gd gr K <leader>rn
REPEAT: .
EMERGENCY: Esc Esc :q! Enter
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
LEARNING PLAN (30 days)
Week 1: Survival
Day 1-2: Open, edit, save, quit (i, Esc, :wq)
Day 3-4: Basic navigation (hjkl, w, b, gg, G)
Day 5-7: Editing (dd, yy, p, u)
Week 2: Productivity
Day 8-10: Search (/, n, *)
Day 11-12: Visual mode (v, V, vi", va{)
Day 13-14: Splits (Ctrl+w v, Ctrl+w hjkl)
Week 3: Advanced
Day 15-17: Telescope (<leader>ff, <leader>fg)
Day 18-20: LSP (gd, gr, K)
Day 21: Macros (qa, @a)
Week 4: Mastery
Day 22-24: Combinations (di", ca{, ci()
Day 25-27: Advanced text objects and motions
Day 28-30: Customization and plugins
PRACTICAL EXERCISES
Exercise 1: Navigation (5 min)
# Open any file
nvim test.ex
gg # Go to beginning
G # Go to end
10G # Go to line 10
/function # Search "function"
n # Next occurrence
Ctrl+o # Go back
Exercise 2: Editing (5 min)
dd # Delete line
u # Undo
yy # Copy line
p # Paste
5dd # Delete 5 lines
u # Undo
Exercise 3: Visual mode (5 min)
V # Visual LINE
j j j # Select 3 lines
d # Delete selection
u # Undo
viw # Select word
y # Copy
p # Paste
VIMTUTOR (interactive tutorial)
# Open interactive tutorial (30 min)
nvim +Tutor
# Or
vimtutor
Do this NOW before anything else! Best 30-minute investment.
FINAL TIPS
- Practice hjkl for 5 minutes - Disable arrow keys if needed
- Use dot (.) to repeat - More powerful than it seems
- Visual mode is your friend - More intuitive in the beginning
- Telescope everything - Fuzzy finder is faster than navigating
- Don't try to learn everything - Master basics first
- Use :help - Documentation is excellent
- Be patient - First week is frustrating, second week improves
TEXT OBJECTS (advanced selection)
# Inner (inside delimiters, excludes them)
iw # Inner word
i" # Inside quotes
i' # Inside single quotes
i( or ib # Inside parentheses
i{ or iB # Inside braces
i[ # Inside brackets
it # Inside tag (HTML/XML)
ip # Inner paragraph
# Around (includes delimiters)
aw # A word (includes space)
a" # Around quotes (includes quotes)
a' # Around single quotes
a( or ab # Around parentheses
a{ or aB # Around braces
a[ # Around brackets
at # Around tag
ap # Around paragraph
# Usage examples
diw # Delete inner word
ci" # Change inside quotes
ya{ # Yank around braces
vit # Visual select inside tag
COMBINING OPERATORS + TEXT OBJECTS
# Operators
d # Delete
c # Change (delete + insert mode)
y # Yank (copy)
v # Visual select
# Text objects (see above)
iw, i", i(, i{, it, ip # Inner
aw, a", a(, a{, at, ap # Around
# Powerful combinations
diw # Delete word under cursor
ci" # Change text inside quotes
yi{ # Yank code inside braces
dit # Delete HTML tag content
dap # Delete paragraph
ca( # Change code in parentheses (includes them)
vi[ # Visual select inside brackets
MOTIONS (advanced movement)
# Find character
f{char} # Find next {char} in line
F{char} # Find previous {char} in line
t{char} # Till next {char} (before it)
T{char} # Till previous {char} (after it)
; # Repeat last f/F/t/T
, # Repeat last f/F/t/T in opposite direction
# Examples
df) # Delete until ) (inclusive)
dt, # Delete until , (exclusive)
cf: # Change until : (inclusive)
y2f" # Yank until second "
# Marks (bookmarks)
m{a-z} # Set mark (lowercase = file-local)
m{A-Z} # Set mark (uppercase = global)
'{mark} # Jump to mark line
`{mark} # Jump to exact mark position
'' # Jump to previous position
`. # Jump to last change
REGISTERS (clipboard system)
# Named registers (a-z)
"ayy # Yank line into register a
"ap # Paste from register a
"bdiw # Delete word into register b
# Special registers
"0 # Last yank
"1-"9 # Delete history (numbered)
"+ # System clipboard
"* # Primary selection (Linux)
"" # Unnamed (default) register
"% # Current file name
": # Last command
# View registers
:reg # Show all registers
:reg a b c # Show specific registers
# Examples
"+yy # Copy line to system clipboard
"+p # Paste from system clipboard
"ayy # Copy to register a
"ap # Paste from register a
ADVANCED FEATURES
Folding (collapse code blocks):
zo # Open fold
zc # Close fold
za # Toggle fold
zR # Open all folds
zM # Close all folds
Marks and jumps:
Ctrl+o # Jump to older position
Ctrl+i # Jump to newer position
`` # Jump to previous position
'. # Jump to last change position
Editing multiple files:
:args *.ex # Load all .ex files
:argdo %s/old/new/g # Replace in all loaded files
:argdo update # Save all
COMMON WORKFLOW PATTERNS
Refactoring a function name:
* # Search word under cursor
cgn # Change next occurrence
# Type new name
Esc
. # Repeat for next occurrence
n.n.n. # Continue for all occurrences
Swap two words:
# Cursor on first word
daw # Delete a word
w # Move to next word
vaw # Visual select word
p # Paste (deleted word)
Delete all lines containing pattern:
:g/pattern/d # Delete all lines with "pattern"
:g!/pattern/d # Delete all lines WITHOUT "pattern"
:v/pattern/d # Same as above
Copy all matching lines:
:g/pattern/y A # Yank matching lines to register A
"ap # Paste from register A
PLUGINS ESSENTIAL COMMANDS (Kickstart.nvim)
File tree (if using neo-tree):
<leader>e # Toggle file explorer
a # Add file/directory
d # Delete
r # Rename
y # Copy
x # Cut
p # Paste
Comment (using Comment.nvim):
gcc # Comment line
gc{motion} # Comment motion
gcap # Comment paragraph
gc} # Comment until end of block
Surround (if installed):
ys{motion}{char} # Surround with {char}
ysiw" # Surround word with quotes
yss) # Surround line with parentheses
cs"' # Change surrounding " to '
ds" # Delete surrounding "
DEBUGGING TIPS
Check what's mapped:
:map # Show all mappings
:nmap # Show normal mode mappings
:imap # Show insert mode mappings
:vmap # Show visual mode mappings
:verbose map <leader>ff # Show where mapping was defined
Check loaded plugins:
:Lazy # Open Lazy.nvim (plugin manager)
:checkhealth # Health check (very useful!)
:messages # Show message history
Performance:
:profile start profile.log # Start profiling
:profile func * # Profile all functions
:profile file * # Profile all files
# Do slow operations
:profile stop # Stop and write to file
Save this guide and refer to it whenever needed! π
Next step: nvim +Tutor
β 30 minutes β Basic mastery guaranteed! π