The cut, copy, and paste file editing operations are key in the mastery of Linux file management. On a graphical text editor like LibreOffice Writer, the implementation of these file editing operations are a no-brainer.
However, the nano text editor offers some file editing flexibility not evident in graphical file editors like LibreOffice Writer. For instance, it is easier to navigate to various file paths and open them via the nano editor than it is to achieve the same objective using a graphical text editor.
This tutorial will show us how easy it is to achieve cut, copy, and paste text operations while using the nano text editor in Linux.
Problem Statement
For this tutorial to be interactive and well understood, we need a reference file for demonstrating the cut, copy, and paste operations we will be addressing through the nano editor.
Consider the following sample file:
Cut and Paste Text in Nano Editor
The implementation of the cut text operation can be interpreted in the following manner. The cut text operation deletes the highlighted line entry from the currently open file.
For instance, in the above open file, we can cut the line entry “I am a file called new_file.txt!” in the following manner.
The first step is to position the cursor on the line entry you wish to cut using the keyboard arrow key.
From here, use the keyboard key combination [Ctrl]+6
to mark the text selection starting point.
Now use the keyboard arrow keys to highlight the text you wish to cut.
To cut our text, we will use the keyboard key combination [Ctrl]+k
.
To paste our cut text, navigate to the file entry position where you would like to paste the cut text. It could be the same file or on another file opened by the nano editor.
Once you are at the right pasting position, use the keyboard key combination [Ctrl]+u
to paste the cut text content.
Copy and Paste Text in Nano Editor
Text copying operation only duplicates a highlighted line entry on a text file. To copy the text “I am a file called new_file.txt!” we will follow the following steps.
Position the cursor on the line entry you wish to copy using the keyboard arrow key.
Use the keyboard key combination [Ctrl]+6
to mark the text selection starting point.
Use the keyboard arrow keys to highlight the text you wish to copy.
To copy our text, we will use the keyboard key combination [Alt]+6
.
To paste the copied text, navigate to the preferred file position and implement the keyboard key combination [Ctrl]+u
.
Once you are through with cutting or pasting your text, you can save (Ctrl+o)
and exit (Ctrl+x)
your file.
In our next article guide, we will address how to search and replace text in nano editor.