level 07
Commenting Code
Toggle comments over lines and motions with gcc and gc.
You comment and uncomment code dozens of times a day, mostly to silence noise while you debug. Plain Vim has no toggle for it, which is the one place the defaults let you down. Everybody fixes this the same way: commentary.vim on Vim, Comment.nvim on Neovim. They bolt on so cleanly you’ll forget they aren’t native.
Comment Commands
gcc → toggle comment on the current line
gc{motion} → toggle comment over a motion (gcap, gc3j, gcG)
gc (visual)→ toggle comment on the selection
gc is just another operator — it composes with every motion and text object you already know. gcip comments an inner paragraph; gc2j comments three lines. There’s nothing new to learn.
The editor below uses core Vim and doesn’t include the commentary plugin, so
gccwon’t fire here. The exercises practice the manual equivalent — using Visual block andI//— which produces the same result and reinforces Level 6.
Comment a line manually
- Put the cursor on the
console.logline. - Press
I, type//, pressEsc— the line is now commented. - To uncomment: press
0, thenxtwice (or2x) to remove the//.
goal I at the line start inserts a // prefix — the manual gcc.
Comment a block with Visual block
- Put the cursor at the start of the first
console.logline. - Press
Ctrl+v, thenjthree times to span all four lines. - Press
I, type//, pressEsc— all four are commented. - To uncomment:
Ctrl+v, select the//column, pressd.
goal One I// applied to a column comments many lines at once.
Debugging workflow — silence the logs
- With Visual block, select the start of the three
console.loglines. - Press
I, type//, pressEscto disable them. - Confirm the logic is untouched, then remove the
//column to re-enable.
goal Comment a block to test without noise, then restore it.