Skip to main content

Nano Essentials

Deleting Lines in Nano

Here's all you need to know about deleting single, multiple or all lines in Nano editor.

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.

🚧
The delete function is actually cut operation here. The lines you 'cut' are saved to the buffer and you may paste them if needed. If you do not 'paste' them, it is as good as deleting the lines.

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.

delete single line in nano
Press Ctrl+K to cut or delete the current line

If you are happy with the decision, save and exit nano by pressing the Ctrl+X keys.

If you are unhappy with it, you can easily undo the action in Nano using Alt+U keys.

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.

Now, press Ctrl+^ (or 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 Ctrl+K.

delete multiple lines in nano
Set mark with Ctrl+^, move arrow to select text and Ctrl+K to delete

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.

Now press 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).

delete all lines in Nano
Move to start of file with Alt+\ and press Alt+t to delete all lines

Again, you can easily undo with Alt+U.

That's all you need to know about deleting lines in Nano text editor. Enjoy it.

Abhishek Prakash