C.W.K.
Stream
Lesson 03 of 04 · published

Spell Check and Code Folding

~10 min · vim, spell, folding

Level 0Trapped
0 XP0/35 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Spell-checking inside Vim

Vim has a respectable spell checker built in. Turn it on and misspelled words get highlighted; navigate to them, get suggestions, or add unknown words to your personal dictionary. Useful for prose, commit messages, and even comments in code.

Folding — collapse code you're not looking at

Folding hides ranges of lines behind a single placeholder line. Useful for navigating big files: collapse all the functions you don't care about and focus on one. Vim has multiple fold methods — manual, indent, syntax, marker, expression. The most useful for code is indent (folds by indentation level) or syntax (folds by language structure, requires a syntax file).

Fold commands

Navigation: zo open the fold under the cursor, zc close it, za toggle. zR opens all folds in the file; zM closes all. zj / zk jump to next / previous fold.

Manual mode: zf{motion} creates a fold over a region. zf3j folds the next three lines; zfap folds around a paragraph; zd deletes the fold (manual only).

Don't use folds at first. Most beginners fight them — the editor keeps collapsing things and they don't know how to open them back up. zR opens everything; remember that and you can always escape. Try syntax-based folding (Track 8 has Treesitter folding) after you've learned to navigate big files without it.

Code

Spell-checking·vim
:set spell                    " enable spell check
:set spelllang=en_us          " set language
:set nospell                  " disable

]s        " jump to next misspelled word
[s        " jump to previous
z=        " suggest corrections (interactive)
zg        " add word under cursor to your dictionary
zw        " mark word as misspelled
zug       " undo zg
zuw       " undo zw
Folding·vim
:set foldmethod=indent     " fold by indentation
:set foldmethod=syntax     " fold by syntax (needs a syntax file)
:set foldmethod=marker     " fold by markers in the buffer
:set foldmethod=manual     " you create folds explicitly

zo        " open fold under cursor
zc        " close fold under cursor
za        " toggle fold
zR        " open ALL folds
zM        " close ALL folds
zj        " jump to next fold
zk        " jump to previous fold
zf{motion}    " create fold over motion (manual mode)
zd        " delete fold (manual mode)

External links

Exercise

Open a long source file or markdown document. Set foldmethod=indent, then walk through the file with zM (close all), zj / zk (jump fold to fold), zo (open one to inspect), zR (open all to escape). For spell-check, enable :set spell on a markdown file, navigate misspellings with ]s, and accept the first suggestion with z= + 1 + Enter.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.