The nano text editor has a reputation for making life easier for most users on the journey of mastering the Linux operating system footprints. It is the perfect text editor to start with before adopting more advanced text editors like Vim.
Since human is to error, we tend to make mistakes while editing our files on a Linux operating system environment. A native solution to errors that occur during file editing operations is to navigate to the position of the incorrect text using the keyboard arrow keys and subsequently apply the keyboard backspace key to fix the issue.
However, when we master the implementation of undo and redo operations while working on a file opened with the nano text editor, it saves us a lot of valuable time that would be wasted trying to fix the edit issue via the keyboard navigation keys.
This article will walk us through the implementation of the undo and redo file operation functions in a nano text editor in Linux.
Install Nano Editor in Linux
If for some reason, the nano editor was uninstalled or does not exist on your Linux system, refer to the following commands for its re-installation on various Linux OS distributions.
$ sudo apt install nano [On Debian, Ubuntu and Mint] $ sudo yum install nano [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a app-editors/nano [On Gentoo Linux] $ sudo pacman -S nano [On Arch Linux] $ sudo zypper install nano [On OpenSUSE]
We should now be able to confirm the installed nano text editor version with the following command.
$ nano --version GNU nano, version 6.2
How to Undo and Redo in Nano Editor
For this article to be more fruitful, we should take the hands-on approach in explaining the undo and redo operations in nano editor.
Consider the following sample file opened with a nano text editor.
Undo Operation in Nano Editor
Supposing the line entry portion “…in nano editor” is a file entry mistake that we need to rectify. To undo the line entry portion we will use the keyboard key combination [Alt]+u
.
The [ Undid addition ]
tag confirms that the undo operation was a success. Please note that the undo operation applies to the last file entry after the file was saved.
Redo Operation in Nano Editor
Suppose the undo operation implemented above was a mistake and we wish to return our open file to its previous state, here is where we implement the redo operation.
To execute a redo operation, we will use the keyboard key combination [Alt]+e
.
The tag [Redid addition]
confirms that our redo operation was a success. From here, you can choose to save (Ctrl+o)
your file and close it (Ctrl+x)
or continue editing it further.
In our next article guide, we will handle the implementation of cut, copy, and paste operations on a nano text editor.