Using Nano
Use nano when you need a simple terminal editor for config files, credentials, commit messages, or quick text edits.
Open a file
Section titled “Open a file”Open an existing file or create it if it does not exist.
nano FILE_NAMEOpen a file at a specific line.
nano +LINE_NUMBER FILE_NAMEOpen a file with line numbers visible.
nano --linenumbers FILE_NAMERead nano shortcuts
Section titled “Read nano shortcuts”Nano shows common shortcuts at the bottom of the editor.
^ means Ctrl, so ^X means Ctrl+X.
M- means Meta, which is usually Alt or Esc, so M-U means Alt+U or Esc, then U.
Basic editing flow
Section titled “Basic editing flow”Open the file.
nano FILE_NAMEEdit the text normally.
Save and exit
Section titled “Save and exit”Save changes.
Ctrl+OEnterSave changes with a different file name.
Ctrl+ONEW_FILE_NAMEEnterExit nano.
Ctrl+XIf nano asks whether to save a modified file, press Y to save or N to discard. Press Enter to confirm the file name when saving.
Search and replace
Section titled “Search and replace”Search with Where Is.
Ctrl+WFind the next match.
Alt+WFind the previous match.
Alt+QReplace text.
Ctrl+\Cut, copy, and paste
Section titled “Cut, copy, and paste”Cut the current line. This works like deleting the whole line unless you paste it back.
Ctrl+KCopy the current line.
Alt+6Paste the cut or copied text.
Ctrl+USelect text
Section titled “Select text”Start or stop selecting text.
Alt+AMove the cursor to expand the selection, then cut or copy the selected text.
Ctrl+KAlt+6Command glossary
Section titled “Command glossary”| Command | Meaning |
|---|---|
nano FILE_NAME | Open or create a file. |
nano +LINE_NUMBER FILE_NAME | Open a file at a specific line. |
nano --linenumbers FILE_NAME | Open a file with line numbers visible. |
Ctrl+G | Open nano help. |
Ctrl+O | Write out the file, usually used to save changes. |
Ctrl+S | Save the current file in nano versions that support it. |
Ctrl+X | Exit nano. |
Ctrl+R | Read another file into the current file. |
Ctrl+W | Search with Where Is. |
Ctrl+\ | Start search and replace. |
Alt+R | Start search and replace in nano versions that support it. |
Alt+W | Find the next search match. |
Alt+Q | Find the previous search match. |
Ctrl+K | Cut the current line or selected text. Use this to delete a whole line. |
Ctrl+U | Paste cut or copied text. |
Alt+6 | Copy the current line or selected text. |
Ctrl+T | Execute a command or open tool actions from some prompts. |
Ctrl+J | Justify the current paragraph or selected text. |
Ctrl+C | Show the current cursor position. |
Ctrl+/ | Go to a specific line. |
Alt+G | Go to a specific line in nano versions that support it. |
Alt+A | Start or stop selecting text. |
Alt+U | Undo. |
Alt+E | Redo. |
Alt+] | Jump to the matching bracket. |
Alt+O | Go to the previous item in contexts that support it. |
Ctrl+B | Move back one character. |
Ctrl+F | Move forward one character. |
Ctrl+Left | Move to the previous word. |
Ctrl+Right | Move to the next word. |
Ctrl+A | Move to the start of the current line. |
Ctrl+E | Move to the end of the current line. |
Ctrl+P | Move to the previous line. |
Ctrl+N | Move to the next line. |
Alt+N | Toggle line numbers. |
Alt+S | Toggle soft wrapping. |