logo
eng-flag

Nano Cheatsheet

Table of Contents

  1. Basic Operations
  2. Navigation
  3. Editing
  4. Search and Replace
  5. Cut, Copy, and Paste
  6. File Operations
  7. Display Options
  8. Other Functions
  9. Customization

Note: In this cheatsheet, ^X means "Ctrl+X", and M-X means "Alt+X".

Basic Operations

Starting Nano

  • Open nano: nano
  • Open a specific file: nano filename
  • Open a file with cursor at specific line and column: nano +line,column filename

Example:

$ nano
$ nano myfile.txt
$ nano +10,5 myfile.txt

Exiting Nano

  • Save and exit: ^X, then Y, then Enter
  • Exit without saving: ^X, then N

Getting Help

  • Display help menu: ^G or F1

Moving the Cursor

  • Move up one line: ^P or Up Arrow
  • Move down one line: ^N or Down Arrow
  • Move left one character: ^B or Left Arrow
  • Move right one character: ^F or Right Arrow
  • Move to previous word: M-Space
  • Move to next word: Ctrl+Space

Scrolling

  • Scroll up one line: ^Y
  • Scroll down one line: ^V
  • Scroll up one page: ^- or PgUp
  • Scroll down one page: ^_ or PgDn

Jumping to Specific Locations

  • Go to beginning of current line: ^A or Home
  • Go to end of current line: ^E or End
  • Go to first line of file: M- or M-|
  • Go to last line of file: M-/
  • Go to specific line number: ^_, then type the line number and press Enter

Editing

Inserting and Deleting Text

  • Insert character: Just type it
  • Delete character before cursor: Backspace
  • Delete character under cursor: ^D or Delete
  • Delete word before cursor: M-Backspace
  • Delete word under cursor: M-D

Undoing and Redoing

  • Undo last action: M-U
  • Redo last undone action: M-E

Selecting Text

  • Start selection: M-A
  • Cut selection: ^K
  • Copy selection: M-6

Indenting and Outdenting

  • Indent current line or marked region: M-}
  • Outdent current line or marked region: M-{

Search and Replace

Searching

  • Start a forward search: ^W
  • Start a backward search: M-W
  • Find next occurrence: ^W then Enter
  • Find previous occurrence: M-W then Enter

Replacing

  • Start a replace operation: ^
  • Replace all occurrences: During replace, press A

Example:

^W
Type "search term"
Enter
^Type "search term"
Enter
Type "replacement"
Enter
A (to replace all)

Cut, Copy, and Paste

Cutting and Copying

  • Cut current line: ^K
  • Cut from cursor to end of line: ^K
  • Copy current line: M-6

Pasting

  • Paste cut/copied text: ^U

Marking Text

  • Start marking text: M-A
  • Cut marked text: ^K
  • Copy marked text: M-6

File Operations

Saving Files

  • Save current file: ^O
  • Save file under a new name: ^O, then type new name and press Enter

Opening Files

  • Insert another file into current one: ^R
  • Open a new buffer (file): M-F

Switching Between Open Files

  • Switch to next buffer: M->
  • Switch to previous buffer: M-<

Display Options

Toggling Display Features

  • Toggle line numbers: M-#
  • Toggle syntax highlighting: M-Y
  • Toggle soft wrapping of lines: M-$
  • Toggle display of whitespace: M-P

Changing Color Scheme

  • Change color scheme: M-Y repeatedly

Other Functions

Spell Checking

  • Toggle spell checking: ^T
  • Move to next misspelled word: ^]

Executing Commands

  • Execute a command in the shell: ^T

Macros

  • Start/stop macro recording: ^]
  • Play back macro: M-]

Customization

Nano can be customized using a configuration file: ~/.nanorc

Common settings:

set linenumbers
set mouse
set softwrap
set tabsize 4
set tabstospaces

To include syntax highlighting, add lines like:

include "/usr/share/nano/python.nanorc"

You can also create custom syntax highlighting files and include them in your .nanorc file.

2024 © All rights reserved - buraxta.com