3

How to delete the complete word where cursor is positioned in nano text editor? Or if cursor is on white space, I assume it should delete the next word?

Nano help shows these two functions but they are not bound to any shortcuts:

Cut backward from cursor to word start
Cut forward from cursor to next word start

Those don't appear to be what I'm looking for, but if nothing else is available, I'd like to know how to use them (especially with a shortcut key).

2

Save this file to ~/.nanorc and ctrl+] cuts the word to the left, and ctrl+\ cuts right

bind    ^]          cutwordleft         main
bind    ^\\         cutwordright        main

This works for me in nano version 2.5

  • I realize the right square bracket cutting left is silly, but the keybinding for control left square bracket was broken, in some way. – activedecay Feb 1 at 15:49
1

When it comes to editing text in Nano, I find these keyboard shortcuts are of great benefit:

  • Alt+M - Enable/Disable mouse support mode.
  • Ctrl+6- Switch on marking (mark set/unset)
  • Ctrl+A- Move to beginning of current line.
  • Ctrl+K- This shortcut has magical dual functionalities, it cuts (deletes) the whole line of selection when mouse support mode is disabled, and it cuts (deletes) the whole selected word/text when mouse support mode is enabled.
  • Ctrl+D- Delete the character under the cursor
  • Ctrl+H- Delete the character to the left of the cursor
  • Ctrl+U- Uncut from the cutbuffer into the current line.
  • Ctrl+space- Move forward one word. When mose support mode is enabled, it will select the words one by one with every hit on the keys.

If you would like to make edits at/to a specific word in the text, then you need to do the following:

  • Hit Alt+M to enable "mouse support mode".
  • Double click on the word of choice and this will switch on marking (mark set/unset). When you click on the word of choice and marking is set on, then select the word or the text of choice using the mouse (exactly like how you usually select text in any word editor e.g. gedit). Or, alternatively you can hit Ctrl+6 to enable marking, then Ctrl+space to select the word/text that you would like to edit.
  • Use Ctrl+H to delete the characters of that selected word, or alternatively use Ctrl+K to cut (delete) the selected word/text when mouse support mode is enabled.

In order to undo/redo actions, nano has experimental undo/redo feature. In nano manual:

   $man nano
. . . .

   -u (--undo)
          Enable experimental generic-purpose undo code. By default, the undo and redo shortcuts are Meta-U and Meta-E, respectively.
. . . .

To activate "undo/redo" mode, you’ll need to start nano with the -u option:

$ nano -u file.txt

… and then you can use Alt+U to undo and Alt+E to redo.

More details about the Nano's keyboard shortcuts

  • 1
    undo is alt+u while ctrl+u is for uncut – elig Sep 17 '18 at 22:42
  • 1
    What is the commend for deleting a whole word? That's my question. – MountainX Sep 19 '18 at 3:21
  • You didn't even answer the question – activedecay Oct 2 '18 at 13:24

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.