27

How do I delete selected text in the nano editor?

I came across this issue while needing to delete the virtual host file and replace its content completely by other content. But the problem is that I can't select and delete the entire text at once. And if I delete it character by character, it won't be a computer thing.

Seth
  • 58,122
vaibhav
  • 395
  • No, It's not duplicate. I am particularly asking for deleting the selected content that is not available on link you are saying to be duplicate of. – vaibhav Jul 22 '14 at 11:10
  • your question seems to me like problem in editing a text, now I can understand that you are asking about selecting text using mouse and delete... see my answer... – A J Jul 22 '14 at 11:29

1 Answers1

41

You can't select with mouse and delete text using nano editor. For faster delete you can use Ctrl + K to delete(cut) the present line of text.

Note : Ctrl + K will cut the line of text. Using Ctrl + U you can paste it.

EDIT: Additional Info from steeldriver

You can select and cut something other than the current line using Ctrl-^ to mark the start of the text, then advancing the cursor e.g. using Ctrl-F (forward one character) and/or Ctrl-Space (forward one word) and/or arrow keys, and then pressing Ctrl-K

A J
  • 11,367
  • 17
  • 44
  • 59
  • 8
    You can select and cut something other than the current line using Ctrl-^ to mark the start of the text, then advancing the cursor e.g. using Ctrl-F (forward one character) and/or Ctrl-Space (forward one word) and/or arrow keys, and then pressing Ctrl-K – steeldriver Jul 22 '14 at 11:45
  • like @steeldriver said.. that's how you delete in nano! First set the mark with Ctrl + ^, then select with arrow keys, use the cut Ctrl + K and to delete, don't follow that by a paste Ctrl + U;) To copy the key combo is Alt + ^ – rusty Jul 22 '14 at 12:09
  • So is the simple answer 'hold down the Backspace/Delete key?' :) +1 Very useful – Wilf Jul 22 '14 at 14:45
  • 1
    like @steeldriver said.. for selection you can use SHIFT+ARROW to move any direction. And for Mac or if Ctrl-^ not work then CTRL+SHIFT+^ should work. – itsazzad Dec 16 '15 at 21:32
  • 1
    Also, you can enable the mouse in Nano if invoked with -m option or set mouse in ~/.nanorc You can set the mark with the mouse with a double-click. – nathangiesbrecht Apr 07 '16 at 16:17