Hostxpeed
Login Get Started →
Getting Started

How to Edit Files with Nano

5 min read
21 views
Jun 10, 2026

Prerequisites

Before using nano, make sure you have:

  • SSH access to your VPS
  • Write permissions for the file you want to edit

💡 nano is the easiest text editor for beginners and is pre-installed on most Linux distributions.

Step 1: Open a File with Nano

Connect to your VPS:

ssh hxroot@YOUR_SERVER_IP -p 22

Open a file (creates new file if doesn't exist):

nano filename.txt

Open with sudo (for system files):

sudo nano /etc/nginx/nginx.conf

Step 2: Basic Navigation

Once in nano:

  • Arrow keys - Move cursor
  • Page Up/Page Down - Scroll by page
  • Home - Beginning of line
  • End - End of line

Step 3: Editing Text

Just start typing to insert text.

Delete characters:

  • Backspace - Delete character before cursor
  • Delete - Delete character at cursor

Cut and paste:

  • Ctrl+K - Cut current line
  • Ctrl+U - Paste cut line
  • Alt+6 - Copy line (then Ctrl+U to paste)

Step 4: Save and Exit

Ctrl+O - Save file (write out)

Press Enter to confirm filename.

Ctrl+X - Exit nano

If you haven't saved, nano will ask: "Save modified buffer?"

  • Y - Yes, save then exit
  • N - No, exit without saving
  • Ctrl+C - Cancel, return to editing

Useful Nano Shortcuts

ShortcutAction
Ctrl+GHelp (lists all commands)
Ctrl+WSearch for text
Ctrl+Search and replace
Ctrl+CShow cursor position
Ctrl+_Go to line number
Ctrl+TCheck spelling
Alt+UUndo
Alt+ERedo
Alt+ASet mark (start selection)
Alt+6Copy selected text

Working with Multiple Files

Open multiple files:

nano file1.txt file2.txt

Switch between files:

  • Alt+, - Previous file
  • Alt+. - Next file

Enable Line Numbers

To enable line numbers, press Alt+N (toggle on/off).

To permanently enable, create or edit ~/.nanorc:

echo "set linenumbers" >> ~/.nanorc

Syntax Highlighting

Nano includes syntax highlighting for many file types.

Enable by default:

echo "include /usr/share/nano/*.nanorc" >> ~/.nanorc

Common Editing Examples

Edit SSH configuration:

sudo nano /etc/ssh/sshd_config

Edit hosts file:

sudo nano /etc/hosts

Edit PHP configuration:

sudo nano /etc/php/8.1/cli/php.ini

Edit crontab:

crontab -e

Recover Unsaved Files

If your SSH session disconnects while editing:

Nano saves backups as filename.save

Check for saved files:

ls -la | grep .save

Recover:

nano filename.save

Create .nanorc Configuration

# ~/.nanorc - Nano configuration
set tabsize 4
set tabstospaces
set autoindent
set linenumbers
set nowrap
set smooth
set backups
set backupdir ~/.nano_backups

Create backup directory:

mkdir -p ~/.nano_backups

Search and Replace Example

  1. Press Ctrl+
  2. Enter search text (e.g., "olddomain.com")
  3. Enter replacement text (e.g., "newdomain.com")
  4. Press A to replace all, or Y/N for each match

✅ You can now edit files using the nano text editor on your Hostxpeed VPS.

Was this article helpful?