86

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?

83

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.

  • 2
    Linux Mint seems to accept CTRL+ALT+6 to mark the beginning of the block. – pbaldauf Dec 5 '16 at 8:42
  • This is a superior answer – Rexford Feb 15 '18 at 10:12
  • 2
    The shortcut for marking the beginning of the block is actually CTRL + ^. So CTRL + SHIFT + 6 might not be correct depending on your keyboard layout. – nibarius Feb 22 '18 at 9:44
  • As asked, we seeks for the way that not affecting the clipboard. Thanks anyway. – Nam G VU Dec 9 '18 at 7:06
44

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.

  • 3
    This doesn't work for long lines. The moment you see that $, the line will be truncated. – NightKnight on Cloudinsidr.com Feb 22 '16 at 20:07
  • 1
    nano does support cutting of blocks Ctrl+Shift+6, highlight, Ctrl+k – alleyoopster Feb 6 '18 at 15:26
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.

4
CTRL SHIFT K

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

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

  • Thanks but that seems overkill the line delete need – Nam G VU Jun 3 '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 4 '17 at 16:22
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.