I can able to select multiple lines using Esc+A. After this, what shortcut(s) should I use to comment/uncomment the selected lines?

2 Answers 2


Esc3 (or Alt+3) will comment or uncomment the selected lines in recent versions of the nano editor (the version shipped with macOS is too old; install a newer version with e.g. Homebrew). The default comment character used is # (valid in many scripting languages).

The comment character may be modified by the comment option in your ~/.nanorc file. This is from the manual:

comment "string"

Use the given string for commenting and uncommenting lines. If the string contains a vertical bar or pipe character (|), this designates bracket-style comments; for example, "/*|*/" for CSS files. The characters before the pipe are prepended to the line and the characters after the pipe are appended at the end of the line. If no pipe character is present, the full string is prepended; for example, "#" for Python files. If empty double quotes are specified, the comment/uncomment functions are disabled; for example, "" for JSON. The default value is "#".

See also the nanorc(5) manual on your system (man 5 nanorc).

Since it may need to be explained:

There are three ways to select text in nano:

  1. Use EscA (or Alt+A),
  2. Use Shift and the arrow keys,
  3. In a graphical environment, use Shift and the left mouse button (if nano is started with its -m option).

2022 update:

 1. Alt+A (set mark)
 2. Use Shift and the arrow keys to select lines
 3. Alt+3 (comment/uncomment lines)
 4. Alt+A (unset mark)
 5. ?????
New contributor
Lysak is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.