Step 5 of 5

Commenting

Commenting

Ctrl-c toggles a line comment on every line the selection touches. Helix knows the comment syntax for the file’s language — // for Rust, # for Python, and so on — and puts the marker at the line’s indentation level, so the code keeps its shape. Press Ctrl-c on a commented line and the marker comes off again.

With several lines selected, or several cursors, one press comments them all. If some of those lines are already commented, Helix comments the lot rather than uncommenting the few.

Plain text has no comment syntax, so this step’s practice file is comment.rs, a small Rust program sitting alongside the usual buffer. Work through the checklist below: open it, comment a line, uncomment it, then comment two lines at once.

  1. Open comment.rs with :o comment.rs Type :o comment.rs and hit Enter — the editor switches to the Rust file.
  2. Comment out the println! line with Ctrl-c Move down to line 2 and press Ctrl-c// appears at the start of the code.
  3. Uncomment it with Ctrl-c again Press Ctrl-c on the same line — the // goes away.
  4. Comment out let a and let b together Move down to let a, press x twice to select both lines, then Ctrl-c.
Open comment.rs with :o comment.rs Type :o comment.rs and hit Enter — the editor switches to the Rust file.

Next: Comment out the println! line with Ctrl-c

Loading editor…