10

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).

3 Answers 3

9

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

This works for me in nano version 2.5

bind    ^]          cutwordleft         main
bind    ^\\         cutwordright        main

This works for me in nano version 2.9.3

bind    ^]          cutwordleft         main
bind    ^\          cutwordright        main
5
  • I realize the right square bracket cutting left is silly, but the keybinding for control left square bracket was broken, in some way. Commented Feb 1, 2019 at 15:49
  • Isn't that because of the [ being an escape character? Commented Jan 2, 2020 at 15:20
  • if you can get [ to cut left and ] to cut right, please edit my answer or let me know what works for you and i'll change my answer to include it. thanks @MichałKapracki Commented Jan 3, 2020 at 17:30
  • 1
    Just a note, but in nano 6.0+ you have to use chopwordleft and chopwordright Commented Jan 17, 2022 at 20:53
  • 1
    What is nano's definition of a "word"? Now it see that it is not anything between spaces. Example: __xxx_yyy __ after ^] becomes __xxx_ (unexpected), instead of __xxx_yyy (expected). How to change the definition to be "anything between spaces"? Commented May 19, 2022 at 13:13
2

In later versions such as 7.2 onward, it is:

bind ^H chopwordleft main

If you'd like to also use ctrl+backspace as your whole word deletion shortcut (in addition to alt+backspace) (as it is in non-terminal text editors in linux)

0

On mine (kitty with nano 7.2) I had to do

bind ^W chopwordleft main

In order to bind ctrl+backspace to word deletion

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.