Kahibaro
Discord Login Register

Editing with nano

Starting nano

To open a file with nano:

  nano filename.txt
  nano newfile.txt
  nano +25 filename.txt

Common optional flags:

Example:

nano -l -m script.sh

nano interface basics

When nano opens, you’ll see:

^ means “Ctrl”. So:

M- means “Meta” (usually the Alt key):

Basic editing

Moving the cursor

Example: Ctrl + _, then 42 jumps to line 42. 42,10 jumps to line 42, column 10.

Inserting and deleting text

Saving and exiting

Saving (Write Out)

Exiting

Searching and replacing

Searching text

Useful search options (toggled after pressing Ctrl + W, then Alt + key):

Find and replace

Cutting, copying, and pasting

nano uses a “mark and cut” style selection.

Cutting and copying lines

Cutting/copying a selection

  1. Move cursor to start of the text.
  2. Set the mark: Ctrl + ^ (Ctrl + Shift + 6 on many keyboards)
  3. Use arrows to extend selection.
  4. Cut selection: Ctrl + K
  5. Paste selection: Ctrl + U

To “copy” instead of cut:

Undo and redo

Undo/redo covers most editing actions (insert, delete, cut, paste, search-replace, etc.), but history depth can be limited depending on version.

Working with multiple files and buffers

nano can work with multiple open files in one session.

Opening additional files

Switching between open buffers

nano shows the current buffer’s name in the status line.

Indentation and code editing helpers

nano is basic but has a few coding-friendly features, often enabled via options or config.

Common shortcuts:

These depend on your nano version and config; if they don’t work, your distro’s defaults may differ.

Enabling line numbers and syntax highlighting

Some distros enable these by default; others don’t. You can control them from within nano and via config.

Temporary (per session)

While in nano:

Or start nano with options:

Permanent (via config file)

User-level config: ~/.nanorc
System-wide config: /etc/nanorc (requires root)

Example ~/.nanorc:

set linenumbers
set softwrap
set tabsize 4
set autoindent
include "/usr/share/nano/*.nanorc"

Common options:

The include line loads syntax highlighting rules provided by your distro (language-specific .nanorc files).

Using nano as default editor

Some commands (like crontab -e, git commit, or editing system configs via tools) use the EDITOR or VISUAL environment variables.

To make nano your default editor for your user:

Add to ~/.bashrc or ~/.profile:

export EDITOR=nano
export VISUAL=nano

Apply immediately in the current shell:

export EDITOR=nano
export VISUAL=nano

Now tools that respect these variables will open nano instead of another editor.

Practical workflows and tips

  sudo nano /etc/filename.conf

Use Ctrl + G at any time to see nano’s built-in help screen, which lists many of these commands with their key combinations.

Views: 24

Comments

Please login to add a comment.

Don't have an account? Register now!