Nano Cheat Sheet
Nano is a simple command-line text editor for Unix-like systems. Unlike vi or Vim, Nano’s interface and commands are more intuitive, making it a popular choice for quick edits.
1. Opening and Closing Files
nano filename
Opens (or creates, if it doesn’t exist) a file named filename in Nano.nano +line filename
Opens the file and places the cursor at the specified line number.nano -w filename
Disables word wrapping, ensuring each line remains intact.- Exiting and Saving
Ctrl + X
– Exits Nano. If there are unsaved changes, you’ll be prompted to save or discard them.Ctrl + O
– Writes (saves) the current file. You’ll be asked for a filename if the file is new.
2. Basic Navigation
Nano supports arrow keys for simple navigation. In addition, these shortcuts help you move around more quickly:
Ctrl + A
– Moves the cursor to the beginning of the current line.Ctrl + E
– Moves the cursor to the end of the current line.Ctrl + Y
– Scrolls up one page (when there is more text above).Ctrl + V
– Scrolls down one page (when there is more text below).Alt + \
(orEsc + \
) – Jumps to the beginning of the file.Alt + /
(orEsc + /
) – Jumps to the end of the file.
3. Editing and Deleting
Nano works in insert mode by default—just start typing to insert text. Here are the key editing commands:
Backspace
– Deletes the character to the left of the cursor.Delete
– Deletes the character under the cursor (if your terminal supports it).Ctrl + D
– Also deletes the character under the cursor.
4. Cutting, Copying, and Pasting
Nano refers to “cutting” instead of “deleting” entire lines or blocks of text. To copy text, you “mark” and then “uncut” (paste) it.
- Cutting (Removing) Text
Ctrl + K
– Cuts (removes) the entire current line and stores it in a buffer. Repeated presses will cut multiple lines.
- Uncutting (Pasting) Text
Ctrl + U
– Pastes the most recently cut text at the cursor’s position.
- Copying (Without Deleting) Text
Alt + 6
(orEsc + 6
) – Copies the currently highlighted text into the cut buffer without deleting it.Ctrl + U
– Pastes it elsewhere.
- Selecting Text
Ctrl + 6
– Sets a mark at the cursor’s position to start selecting. Move the cursor to highlight the desired region. Now you can cut or copy the selection.
5. Searching and Replacing
Nano has built-in search and replace functionality:
- Search
Ctrl + W
– Prompts for a search string. PressEnter
to jump to the first match. UseAlt + W
(orEsc + W
) to jump to the next match.
- Search and Replace
Ctrl + \
– Prompts for a string to search for and then a replacement string. Nano will show each match and ask whether to replace it.
6. Useful Command Shortcuts
Below are more shortcuts to enhance your editing experience:
Ctrl + G
– Opens Nano’s built-in help documentation.Ctrl + T
– Invokes the spell checker (if installed).Alt + A
(orEsc + A
) – Starts marking text (similar toCtrl + 6
).Ctrl + _
(then enter a number) – Jumps directly to a specific line number.Alt + ]
– Jumps to the matching bracket or parenthesis (if found).
7. Toggling Features (Line Numbers, etc.)
Depending on your Nano version and configuration, you can toggle certain features on the fly with these commands (in newer versions):
Alt + L
(orEsc + L
) – Toggles display of line numbers in the editor.Alt + M
– Toggles mouse support (if available and enabled in your system).
Alternatively, you can edit Nano’s configuration file (e.g., ~/.nanorc
) to always enable line numbers, syntax highlighting, and other features.
8. Wrapping Up
Nano’s ease of use makes it an excellent choice for quick text edits in the terminal. Here’s a quick recap of the most common commands:
- Open/Save/Exit:
nano filename
|Ctrl + O
(save) |Ctrl + X
(exit)
- Navigation:
- Arrow keys |
Ctrl + A
(line start) |Ctrl + E
(line end)
- Arrow keys |
- Cut/Copy/Paste:
Ctrl + K
(cut line) |Alt + 6
(copy selection) |Ctrl + U
(paste)
- Search/Replace:
Ctrl + W
(search) |Ctrl + \
(search & replace)
- Help:
Ctrl + G
brings up Nano’s help menu.
Mastering these commands will greatly speed up your text editing tasks in the terminal. With Nano’s simple interface and keyboard shortcuts, you can accomplish everything from quick edits to more substantial changes without the learning curve of other editors.