Editing text file in Nano and wondering how to delete entire line?
In this quick Nano tutorial, I'll show the following:
- Deleting a single line
- Deleting selected few lines
- Deleting all lines of the file
Let's see it in action.
Delete a single line
To delete a single line, move to the desired line first. Use the arrow keys to move around in Nano.
Now press the
Ctrl+K and it will delete the line at the current cursor position. It doesn't matter if you are at the beginning of the line or not, it will still be deleted.
If you are happy with the decision, save and exit nano by pressing the
If you are unhappy with it, you can easily undo the action in Nano using
Delete multiple lines
This one is slightly tricky than deleting a single line.
The trick here is to select a block of text first and then use Ctrl+K to cut/delete it.
First, move to the beginning of the line from where you want to start deleting. It is important that the cursor is at the beginning of the line.
Ctrl+Shift+6 as most keys don't have dedicated ^ symbol) to set the mark. Now if you press the down key, it will start selecting the text block.
Go until the end of the line you desire to delete.
If you are happy with the selected text, press
If you like the result, save and exit Nano (Ctrl+X) else undo the changes (Alt+U).
Delete all lines
Move to the beginning of the file. You can press
Alt+\ keys for that.
Alt+T and it will delete all the text from your current cursor position (which is why you moved to the beginning of the file).
Again, you can easily undo with Alt+U.
That's all you need to know about deleting lines in Nano text editor. Enjoy it.