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


Esc3 will comment or uncomment the selected lines in the nano editor. 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).

  • 1
    Do you mean Esc + numeric 3 digit key will do multiline comment? It's not working for me. – Curious Developer Apr 9 '20 at 6:36
  • @CuriousDeveloper Did you first select the lines that you wanted to comment with Esc+A? Then I used Esc+3 with 3 from the top row of the keyboard to comment out. I don't have a separate numeric keypad. – Kusalananda Apr 9 '20 at 6:49
  • I selected the lines to comment from my mouse and then used Esc + 3 and nothing happened. – Curious Developer Apr 9 '20 at 6:54
  • I just took a backup of my file and removed the lines I wanted to comment on. However, for future use, I am curious about how this thing works. – Curious Developer Apr 9 '20 at 6:55
  • @CuriousDeveloper There are three ways to select text in nano, 1) Use Esc+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). When the text has been selected, press Esc+3 to comment out. See the nano manual (man nano) for further info. – Kusalananda Apr 9 '20 at 6:59

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.