You are feeling the best productive self and in the hurry, you make a typo while typing in GNU nano.
How to undo that?
For most people, it is the
Alt + U key combination that you are looking for, and if you are using macOS, use
Option + U key combination.
You are not restricted to undo. You can also redo an undo. Use the
Alt+E keys for that. Mac users can use the
Here's a quick table for you.
|Action||Linux users||macOS users|
Let's see about undo and redo operation in Nano editor in a bit more detail.
The undo operation is critical to any text editor. It allows you to rectify your mistakes.
GNU nano is one such editor that, like many others, allows you to undo your mistakes and then carry on with your work as if nothing happened.
GNU nano is a very simplistic editor that gets out of your way, but since its key combinations are a bit different than most modern text editors like Sublime Text, VS Code, Atom etc, you will find that pressing
Ctrl + Z does not undo an action.
To carry out the undo operation in GNU nano, press the
Alt + U key combination.
Side tip: Just in case you pressed
Ctrl + Z to undo and realized that you have returned back to your shell, know that nano is now a background command. We have a guide on running Linux commands in the background and foreground.
A redo operation is just as useful as an undo operation. What if you only wanted to undo it once but tried to undo it twice? How to undo the undo?
To redo an undo, below are the key combinations that you can use.
To carry out the redo operation, use the
Alt + E key combination.
A note for Macintosh users...
As a Macintosh user, you might have noticed that most modern Macs do not have an "Alt" key. It is replaced by "Option" key.
Apple is also moving away from software that is licensed under the GNU (v3) software license, so this might be subject to change. But hoping for the best, here is an option you can try.
You can replace the "Alt" key with the "Option" key if you are lucky. Sadly, it does not work on my 2018 Mac.
If you are curious, you can a full list of all the keyboard shortcuts that you can, press
Ctrl + G key combination.
You can always install Linux on your Mac though... :p
With that, you now know how to correct your mistakes in Nano editor by undoing and redoing. You can also undo-redo in Vim if you use Vim occasionally.