35 useful Nano Commands and Shortcuts for Raspberry Pi users

1. nano -h: Display help information about nano.
2. Ctrl+G: Display the current nano version.
3. Ctrl+X: Exit nano.
4. Ctrl+O: Save the current file.
5. Ctrl+R: Insert a file into the current file.
6. Ctrl+W: Search for a string in the current file.
7. Ctrl+\: Search and replace a string in the current file.
8. Ctrl+J: Justify the current paragraph.
9. Ctrl+C: Display the current line number.
10. Ctrl+K: Cut the current line.
11. Ctrl+U: Uncut the current line.
12. Ctrl+T: Spell check the current file.
13. Ctrl+Y: Go to a specific line number.
14. Ctrl+_: Undo the last action.
15. Ctrl+\: Redo the last action.
16. Alt+A: Move to the beginning of the current line.
17. Alt+E: Move to the end of the current line.
18. Alt+V: Move to the previous page.
19. Alt+X: Move to the next page.
20. Alt+F: Move forward one word.
21. Alt+B: Move backward one word.
22. Alt+\: Move to the beginning of the file.
23. Alt+/: Move to the end of the file.
24. Alt+D: Delete the current word.
25. Alt+T: Swap the current two words.
26. Alt+L: Convert the current word to lowercase.
27. Alt+U: Convert the current word to uppercase.
28. Alt+C: Capitalize the current word.
29. Alt+W: Copy the current line.
30. Alt+Y: Paste the copied line.
31. Alt+O: Open a new line.
32. Alt+J: Join the current line with the next line.
33. Alt+Q: Format the current paragraph.
34. Alt+H: Display the nano help page.
35. Alt+G: Go to a specific line number.
36. Alt+Z: Suspend nano.
37. Alt+X: Exit nano.
38. Alt+S: Save the current file.
39. Alt+R: Insert a file into the current file.
40. Alt+F: Search for a string in the current file.
41. Alt+\: Search and replace a string in the current file.
42. Alt+J: Justify the current paragraph.
43. Alt+C: Display the current line number.
44. Alt+K: Cut the current line.
45. Alt+U: Uncut the current line.
46. Alt+T: Spell check the current file.
47. Alt+Y: Go to a specific line number.
48. Alt+_: Undo the last action.
49. Alt+\: Redo the last action.
50. Ctrl+Alt+G: Go to a specific line number.

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.

Action Nano shortcut
Save CTRL + O
Exit CTRL + X
Search CTRL + W
Next result ALT + W
Next page CTRL + Y
Previous page CTRL + V
Beginning of line CTRL + A
End of line CTRL + E
Undo ALT + U
Redo ALT + 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.

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.

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:

  • 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.

Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.

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.

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.

I hope this post was useful for you, let me know in the comment.
If you like it, you can also check my post with 57 essentials commands to know on Raspberry Pi.

35 Useful Nano Commands and Shortcuts for Raspberry Pi Users

Nano is a text editor for the Raspberry Pi that is easy to use and understand. It is a great tool for editing configuration files, writing code, and taking notes. Here are some useful commands and shortcuts to help you get the most out of Nano.

1. Opening a File

To open a file in Nano, type nano filename in the terminal. Replace filename with the name of the file you want to open.

2. Saving a File

To save a file in Nano, press Ctrl + O. You will be prompted to enter a filename. Enter the filename and press Enter.

3. Exiting Nano

To exit Nano, press Ctrl + X. You will be prompted to save the file if it has been modified. Press Y to save the file or N to discard the changes.

4. Searching for Text

To search for text in Nano, press Ctrl + W. You will be prompted to enter the text you want to search for. Enter the text and press Enter.

5. Replacing Text

To replace text in Nano, press Ctrl + \. You will be prompted to enter the text you want to search for and the text you want to replace it with. Enter the text and press Enter.

6. Cutting Text

To cut text in Nano, press Ctrl + K. You will be prompted to enter the number of lines you want to cut. Enter the number and press Enter.

7. Copying Text

To copy text in Nano, press Ctrl + 6. You will be prompted to enter the number of lines you want to copy. Enter the number and press Enter.

8. Pasting Text

To paste text in Nano, press Ctrl + U. The text you have cut or copied will be pasted at the current cursor position.

9. Undoing Changes

To undo changes in Nano, press Ctrl + _. You can undo up to the last 10 changes.

10. Redoing Changes

To redo changes in Nano, press Ctrl + Y. You can redo up to the last 10 changes.

11. Moving the Cursor

To move the cursor in Nano, use the arrow keys. You can also press Ctrl + A to move the cursor to the beginning of the line, Ctrl + E to move the cursor to the end of the line, and Ctrl + F to move the cursor forward one character.

12. Selecting Text

To select text in Nano, press Ctrl + 6 and then use the arrow keys to select the text you want. You can also press Ctrl + K to select the current line.

13. Deleting Text

To delete text in Nano, press Ctrl + K. You will be prompted to enter the number of lines you want to delete. Enter the number and press Enter.

14. Inserting Text

To insert text in Nano, press Ctrl + O. You will be prompted to enter the text you want to insert. Enter the text and press Enter.

15. Go to Line

To go to a specific line in Nano, press Ctrl + _. You will be prompted to enter the line number. Enter the line number and press Enter.

16. Word Wrap

To enable word wrap in Nano, press Ctrl + W. You can also press Ctrl + X to disable word wrap.

17. Syntax Highlighting

To enable syntax highlighting in Nano, press Ctrl + T. You can also press Ctrl + X to disable syntax highlighting.

18. Spell Check

To enable spell check in Nano, press Ctrl + V. You can also press Ctrl + X to disable spell check.

19. Line Numbers

To enable line numbers in Nano, press Ctrl + C. You can also press Ctrl + X to disable line numbers.

20. Auto Indent

To enable auto indent in Nano, press Ctrl + J. You can also press Ctrl + X to disable auto indent.

21. Tab Size

To change the tab size in Nano, press Ctrl + I. You will be prompted to enter the tab size. Enter the tab size and press Enter.

22. Help

To view the help menu in Nano, press Ctrl + G. You can also press Ctrl + X to exit the help menu.

23. Go to Beginning of File

To go to the beginning of the file in Nano, press Ctrl + Home.

24. Go to End of File

To go to the end of the file in Nano, press Ctrl + End.

25. Go to Previous Word

To go to the previous word in Nano, press Alt + B.

26. Go to Next Word

To go to the next word in Nano, press Alt + F.

27. Go to Previous Line

To go to the previous line in Nano, press Alt + P.

28. Go to Next Line

To go to the next line in Nano, press Alt + N.

29. Go to Previous Page

To go to the previous page in Nano, press Alt + V.

30. Go to Next Page

To go to the next page in Nano, press Alt + C.

31. Go to Line Number

To go to a specific line number in Nano, press Alt + G. You will be prompted to enter the line number. Enter the line number and press Enter.

32. Insert Date and Time

To insert the current date and time in Nano, press Alt + =.

33. Insert File

To insert a file in Nano, press Alt + R. You will be prompted to enter the filename. Enter the filename and press Enter.

34. Insert Output

To insert the output of a command in Nano, press Alt + Y. You will be prompted to enter the command. Enter the command and press Enter.

35. Insert File List

To insert a list of files in Nano, press Alt + F. You will be prompted to enter the directory. Enter the directory and press Enter.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?