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.

2
  • 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, 2014 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, 2014 at 11:29

1 Answer 1

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

5
  • 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 Jul 22, 2014 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, 2014 at 12:09
  • So is the simple answer 'hold down the Backspace/Delete key?' :) +1 Very useful
    – Wilf
    Jul 22, 2014 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, 2015 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. Apr 7, 2016 at 16:17

Not the answer you're looking for? Browse other questions tagged .