155

I can select all file by going to the 1st line Alt+\, start marking the text by Alt+A, go to the last line by Alt+/

But there, I don't know which key to remove the selected text. Hit delete doesn't work for me but Ctrl+K to cut the text will destroy my clipboard.

So, what is the hotkey to delete selected text?

user1251007
  • 1,101
  • 2
  • 12
  • 30
Nam G VU
  • 2,138
  • 4
  • 21
  • 30

13 Answers13

177

nano of course can delete blocks, see this article

  1. use CTRL+Shift+6 to mark the beginning of your block
  2. move cursor with arrow keys to end of your block, the text will be highlighted.
  3. use CTRL+K to cut/delete block.

To paste the block to another place, move cursor to the position and the use CTRL+U. You can paste the block as often as you want to.

Videonauth
  • 33,045
  • 16
  • 104
  • 120
Thomas Klein
  • 1,779
  • 1
  • 9
  • 2
49

nano does not support deleting a block of text, only cutting it (to the server's clipboard).

Instead, if you are using Putty, do the following:

  1. Select the text you wish to copy to the clipboard with the mouse first -- this copies it to your local clipboard (i.e. Windows 7 clipboard), which nano can't touch:

    enter image description here

  2. Then, select your block in nano and use Ctrl-K to delete it.

  3. Finally, move your cursor to the position where you want to insert the text you copied in Step 1 (you can close nano, open another file, etc. too as long as you don't select another block of text with the mouse). Right-click to paste the copied text at the cursor position.

ish
  • 138,666
  • 36
  • 303
  • 312
19

If you are trying to empty all of the lines.

A pretty elegant and simplest approach is from the bash-cli:

  • echo "" > filename.txt
  • nano filename.txt
morgz
  • 191
  • 1
  • 3
13
CTRL SHIFT K

deletes current line, It can also be useful for quick editing. Thanks

Edit1:

In some of the putty streams, the following works too

CTRL K
th3pirat3
  • 231
  • 2
  • 5
6

To delete multiple block without overriding your clipboard, first mark the text with Alt+A (You will appear Mark Set then select the text using arrow keys) and then use Ctrl+Shift+K to delete selected text,deleted text won't appear in clipboard.

Lakindu Akash
  • 1,371
  • 1
  • 15
  • 34
5

Sadly, nano doesn't seem to have any way of bulk-deleting without clobbering the clipboard.

The safest thing to do while staying within the document is probably to paste your clipboard before deleting, then re-cut it again afterwards.

If you have a block of text already selected, then Ctrl+U will paste the clipboard text, including it in your selected block. You can then unmark the pasted text and just cut your originally selected block.

These steps don't preserve your clipboard, exactly, but at least effectively perform a swap between your selection and the clipboard, allowing you to re-cut the lines you had in there before.

mwfearnley
  • 3,213
  • 2
  • 21
  • 28
2

In Nano

  • Ctrl+6 to set a mark
  • Alt+T will delete all content in a file
  • Ctrl+K will delete the current line at your cursor.
zx485
  • 2,249
  • 11
  • 24
  • 34
Akhil S
  • 121
  • 3
2

You could open up a separate buffer to stash your clipboard in:

  • Make sure "reading into separate buffer" is enabled (you can toggle this with Alt+F)

  • Use Ctrl+R and press Enter (without entering a filename), to open a blank file buffer

  • Paste your current clipboard in there with Ctrl+U

  • Use Alt+< or Alt+> to switch between open buffers

mwfearnley
  • 3,213
  • 2
  • 21
  • 28
  • Thanks but that seems overkill the line delete need – Nam G VU Jun 03 '17 at 15:38
  • 1
    Yeah, I agree.. To be honest, I'd probably recommend posting the issue as a bug report. Sadly they don't seem to have a section for feature requests, but there are existing reports with [Request] in the title. – mwfearnley Jun 04 '17 at 16:22
1

Recent versions of nano (3.2+) now have this feature if you enable the zap option. Put set zap in your nanorc (or start nano with -Z/--zap), select the text your want to delete, and hit to delete your selection without affecting the cutbuffer.

saagarjha
  • 111
  • 3
1

As pointed out by @saagarjha around version 3.2 of nano they introduced a zap command which allows you to delete text without affecting the cutbuffer.

M-Del Throw away the current line (or marked region)

To delete a line by itself use Alt+Delete with the cursor on the line you want to delete.

To delete a block of text, first set the starting mark with Alt+a and select the text to be deleted and finally press Alt+Delete.

To undo a delete, press Alt+u. To redo a delete, press Alt+e. For me redo didn't work until I disabled alt menu access keys in the preferences of my terminal emulator.

Yetoo
  • 35
  • 10
Lenny
  • 19
  • 1
0

For me (on a mac) Control + K did what I wanted (deleted a full line)

SudoPlz
  • 101
  • 2
0

Ctrl+6 (Sets the mark position)
Ctrl+- (Enter the lines nos to delete)
Ctrl+K (Delete the selection)

Paul
  • 4,451
  • 5
  • 25
  • 45
0

Ctrl + T (opens Command to execute tab)

Ctrl + V (Cut Till End)

Tested on Ubuntu Server