Get a free website with any plan

See how
LINUX AND SSH

Editing files on the server with nano (and surviving vim)

Last updated

IN SHORT

To edit files directly on a Flashcloud Linux server over SSH, use the nano command-line text editor. Open a file with nano filename, make edits in the normal text buffer, and press Ctrl+O to save and Ctrl+X to exit. If you get trapped in vim instead, press Esc, type :q!, and press Enter to quit without saving.

Open a file with nano filename.php, make your edit, then press Ctrl+O to save and Ctrl+X to exit. That covers nano, the easier of the two editors you'll run into over SSH. If you land in vim instead (some systems alias vi to it, or a script opens it for you), the fix for "I'm stuck and can't type" is Esc then :q! and Enter to quit without saving.

Both are command-line text editors for making quick changes to files on your server without downloading them first. Useful for a one-line config tweak, a quick look at an error log, or fixing a typo in wp-config.php without opening an FTP client.

nano: the one to use

nano is available on effectively every Linux server, including Flashcloud's. Open any file with:

nano path/to/file.txt

You're in a normal text buffer immediately, no modes to think about. Arrow keys move the cursor, typing inserts text, backspace deletes. The bottom two rows show the available commands with ^ standing in for Ctrl:

  • Ctrl+O ("Write Out") saves the file. Nano will ask you to confirm the filename, press Enter to accept.
  • Ctrl+X exits. If you have unsaved changes it asks whether to save them first.
  • Ctrl+K cuts the current line, Ctrl+U pastes it back.
  • Ctrl+W searches for text in the file.
  • Ctrl+G opens the help screen if you forget any of this mid-edit.

That's most of what you'll ever need. Save, exit, done.

Why you might see vim instead

Some minimal server images ship without nano, or a package's default editor points at vi/vim. Vim is a modal editor: it starts in "normal mode" where typed characters are commands, not text, which is exactly why people get stuck. Pressing i to type a word and then trying to save with familiar keyboard shortcuts doesn't work the way it does in nano.

The keys that get you unstuck:

  • i enters insert mode, now you can type normally.
  • Esc leaves insert mode and returns to normal mode.
  • :wq then Enter, from normal mode, saves and quits.
  • :q! then Enter, from normal mode, quits without saving. Use this if you've made a mess and want out.

If you only remember one thing about vim, remember Esc then :q!. It's the universal escape hatch.

If nano isn't installed and you don't want to fight vim, most distributions let you install it with your package manager (for example apt install nano on Debian/Ubuntu, or yum install nano on CentOS-based systems), assuming you have permission to install packages on that server.

Where you'll actually use this

On Flashcloud shared and WordPress hosting, SSH access is scoped to your account, so you're editing your own site's files. Connection setup is similar to your FTP and SFTP account.

On a VPS, you have root access, so you can edit anything on the system, including files owned by other users or system-level configs like nginx or PHP settings. That's more power and more risk: a typo in a system config can take a service down until you fix it or restore from a snapshot. Always double-check the path before you save, and consider copying a file before editing it if you're not fully sure of the change:

cp nginx.conf nginx.conf.bak

A couple of habits worth keeping

  • Know before you open a file whether you're on shared hosting (scoped to your account) or a VPS (root, so mistakes can affect the whole server).
  • For config files you don't edit often, make a backup copy first. It's one command and it saves you from reconstructing a file from memory.
  • If a file looks like garbled text or binary data when you open it, don't save changes, exit and check you've got the right file.

Common questions

How do I exit vim if I am stuck?

Press Esc, type :q!, and hit Enter. This exits vim immediately without saving any changes.

How do I save changes in nano?

Press Ctrl+O and hit Enter to confirm the filename. Press Ctrl+X when you are ready to exit the editor.

Can I install nano if my server only has vim?

Yes, provided you have package installation permissions on the server. Run apt install nano on Debian or Ubuntu, or yum install nano on CentOS systems.

How do I prevent breaking a server config file?

Make a backup copy of the file before opening it. Run cp filename filename.bak so you can restore the original configuration if a mistake takes a service down.

CAN'T FIND IT?

Real humans answer fast.

Hosting with us? Open a ticket and a real person replies - no scripts, no upsells. Still choosing a host? The same team is included with every plan, from day one.