nano commands and shortcuts

35 useful Nano Commands and Shortcuts for Raspberry Pi users

Nano is not the most intuitive text editor, it’s difficult for a beginner, but when you master the key shortcuts you will save much time in files edition.
As an old vim user, I know what I’m talking about 🙂 but Raspberry Pi and Raspbian promote nano as the default editor, so it’s better to know how to use it.

Nano is a text editor, installed by default on Raspberry Pi. Use “nano <filename>” to open it, and one of the many shortcuts available to make changes in a file.

ActionNano shortcut
SaveCTRL + O
ExitCTRL + X
SearchCTRL + W
Next resultALT + W
Next pageCTRL + Y
Previous pageCTRL + V
Beginning of lineCTRL + A
End of lineCTRL + E
UndoALT + U
RedoALT + E
Nano main shortcut

We’ll see of these, and more, so if you remember them and use them as often as possible, you’ll master the main nano commands and shortcuts.
I voluntarily removed everything that is not indispensable, so you can focus on the primary shortcuts.

If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!

Want the best experience? Become a premium member for ad-free browsing, access exclusive content, and ask questions in our private forums. Your membership helps support the site!

Nano commands

Before opening a file and seeing all the shortcuts available, you have to know that nano offers many options when opening a file.
In this first part, I’ll show you what you can do directly in the command line and general shortcuts:

  • Opening nano
    nano
    nano <filename>

    The filename can be an existing file or the new filename you want to create.
    It can be just the name in the current folder, or a path to the file.
    Don’t forget to use sudo if you need root access to edit the file:
    sudo nano /etc/ssh/sshd_config
  • Nano options
    You can start nano with many useful options I will show you here:
    • +line,column: open the file and place the cursor at the specified position
    • -B: create a backup file when saving (backup file starts with a ~)
    • -C <dir>: keep each version of the file in the specified backup directory
    • -Y <language>: force the syntax highlighting for the specified language
      Available languages are located in /usr/share/nano/*.nanorc
    • -l: Shows line numbers in the left column
    • -v: Read-only mode
  • Exit nano
    To exit Nano at any time, you can use CTRL+X.
  • Shortcut cancel
    Nano provides many shortcuts and if you type one by error, you can exit the contextual menu with CTRL+C.

Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember and a free downloadable cheat sheet so you can have the commands at your fingertips.

Files

For file management, there aren’t many commands to know. To be sure you know how to do this, here are the two commands you will need to use:

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now
  • Create a new file
    To create a new file, the easiest way is to tell nano the filename directly when starting it, like this:
    nano /dir/file.txt
    If you just use nano to open it, it will ask you a filename when saving.
  • Save a file
    To save a file at any time you can use CTRL+O.
    Don’t ask me how they chose the shortcut key ^^.
    CTRL+S ? Nooo, it would have been too easy for us :).

Search and in file navigation

Another feature I use a lot with Vim and never took the time to master on nano, was the search in file (by the way, if you don’t know Vim, I have an article about it here).
Here is everything you need to know about this:

  • Search for a string
    To locate a string in a file, you can use CTRL+W.

    Then enter the string (or regular expression if you want), and confirm with Enter.
    While typing the string, you can use a few options to filter your search results (like case-sensitive search).
  • Next item in the search results
    To move to the next matching result, use ALT+W.
  • Go back to the first line of the file
    If you are lost in the file, you can move back to the beginning with ALT+\.
  • Go to the end of the file
    The same thing, to move directly to the end of the file, use ALT+/.
    Please, don’t use the down arrow 58 times to do this :).
  • Move one screen up
    For fast scrolling, use CTRL+Y to move to the previous page of the file.
  • Move one screen down
    And the opposite, CTRL+V is to move to the next page.

Navigation through lines and columns

To move more precisely in a file, here are the keys and shortcut to use:

  • Move on a line or from line to line
    Arrows 🙂
    I don’t really understand why there are so many shortcuts to move from a character or line to another.
    For me, arrows are the easiest way to do the same.
    Arrow up: previous line
    Arrow down: next line
    Arrow left: previous character on the same line
    Arrow right: next character on the same line
    I think it’s a good idea to keep all of this easy when possible.
  • Go directly to the beginning of the line
    To go to the first character of the line you can use CTRL+A.
  • Go to the end of the line
    And for the last character on the line, use CTRL+E.

Content edition

Ok in this part we move to the file-edition process.
You can save time by remembering a few shortcuts.

  • Undo
    To cancel your last action, you can use ALT+U.
  • Redo
    If you change your mind, use ALT+E to finally make it.
  • Copy and paste strings or lines
    Another thing to keep simple, don’t use shortcuts for this.
    When you use nano on your Raspberry Pi you’re probably using SSH, so use your client features to manage copy and paste.
    Copy: Select a text or line with the mouse
    Paste: Move to the paste spot and right-click to paste
  • Cut an entire line
    If you want to cut or remove a line, you can use CTRL+K to do this.
    I often use this to remove useless lines.
  • Paste the line
    To paste the line you just cut, use CTRL+U.
  • Editing
    For everything else, use nano like any other text editor.
    It’s a nano strength to allow you to edit a file directly.
    Working keys are for example Backspace to delete a character, TAB to indent, Enter to add a new line, etc.
Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Nano options

And finally, here are a few other useful shortcuts for Nano I didn’t give you in the previous parts:

  • Remove the help
    To stay focused on your file, you can hide the bottom shortcut help with ALT+X.
    This way you get one or two extra lines of your files on the same screen.
    Same shortcut to show it back.
  • Disable syntax highlighting
    When syntax highlighting doesn’t help, you can disable it while editing with ALT+Y.

    Did you never have the ugly dark blue color exactly where you need to focus? 🙂
  • Enable backup
    If you didn’t set it when starting nano, you can enable backup at any time while in nano with ALT+B.
  • Display the help for all shortcuts
    If one shortcut I give you here was not clear, or if you want to see the long list of not so useful shortcuts, use CTRL+G to display the nano help.
Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.

Conclusion

That’s it!
We are already at the end of this list of commands and shortcuts to know to use nano like a pro.

If you like it, you can also check my post with 57 essentials commands to know on Raspberry Pi.

And if you want to try another text editor, you can always try Vim on your Raspberry Pi, or one of these best text editors I’ve picked here.

Also: Tired of Raspberry Pi OS? Level up with these top-rated systems.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Whenever you’re ready, here are other ways I can help you:

The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

You can also find all my recommendations for tools and hardware on this page.

How would you rate this article?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Spread the word!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Similar Posts