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 gcc won’t fire here. The exercises practice the manual equivalent — using Visual block and I// — which produces the same result and reinforces Level 6.

Comment a line manually

  1. Put the cursor on the console.log line.
  2. Press I, type // , press Esc — the line is now commented.
  3. To uncomment: press 0, then x twice (or 2x) to remove the //.
normalpress i to type · hjkl to move

goal I at the line start inserts a // prefix — the manual gcc.

Comment a block with Visual block

  1. Put the cursor at the start of the first console.log line.
  2. Press Ctrl+v, then j three times to span all four lines.
  3. Press I, type // , press Esc — all four are commented.
  4. To uncomment: Ctrl+v, select the // column, press d.
normalpress i to type · hjkl to move

goal One I// applied to a column comments many lines at once.

Debugging workflow — silence the logs

  1. With Visual block, select the start of the three console.log lines.
  2. Press I, type // , press Esc to disable them.
  3. Confirm the logic is untouched, then remove the // column to re-enable.
normalpress i to type · hjkl to move

goal Comment a block to test without noise, then restore it.