3

I am looking to create a keyboard shortcut for the Nano text editor to remove the word to the left of the cursor using the key combination Ctrl + Backspace.

Is the key backspace able to be included in a custom keyboard shortcut in a .nanorc file? Here is an example of what I am looking to do, which contains an invalid 'key' entry ^Backspace:

bind ^Backspace cutwordleft main

Here is some additional information from the nanorc v5 man page, wherein it mentions the 'Shift' key, but not 'Backspace':

The format of key should be one of:

^X where X is a Latin letter, or one of several ASCII characters (@, ], , ^, _), or the word "Space". Example: ^C.

M-X where X is any ASCII character except [, or the word "Space". Example: M-8.

Sh-M-X where X is a Latin letter. Example: Sh-M-U. By default, each Meta+letter keystroke does the same as the corresponding Shift+Meta+letter. But when any Shift+Meta bind is made, that will no longer be the case, for all letters.

FN where N is a numeric value from 1 to 24. Example: F10. (Often, F13 to F24 can be typed as F1 to F12 with Shift.)

Ins or Del.

5
  • Welcome to AskUbuntu, the keys like Backspace or Cursor are often not understood correctly by system. When you use a remote server or so, these non-teletype characters are not printable. So that is a little useless to define such a shortcut. You can use Shift-Ctrl-Del for that purpose. Commented Nov 9, 2021 at 0:20
  • 1
    Thanks @SadaharuWakisaka, this is exactly what I was looking for!
    – gridlocdev
    Commented Nov 9, 2021 at 0:26
  • 1
    @SadaharuWakisaka post an answer please - it looks like your comment solved the specific problem here
    – muru
    Commented Nov 9, 2021 at 1:32
  • @gridlocdev, that's good, happy to be useful. Commented Nov 9, 2021 at 2:53
  • @muru, I thought that until you are writing an answer. Please take my comment in your answer. I am not interesting into earn my contribution but helping users and get helped myself. I'm old. Commented Nov 9, 2021 at 2:56

1 Answer 1

1

Typically a terminal application doesn't receive a "Backspace" the way GUI application does. It receives a control character, which it will interpret like backspace. The terminal emulator, which is a GUI application, does the job of translating from the GUI Backspace to the appropriate control code, and this can be configured in the terminal emulator's settings. The usual control codes for Backspace can be ^H (the ASCII backspace character) or ^? (the ASCII Del character). Press CtrlV and then Backspace while in your shell to see which one it is.

3
  • It looks like for my shell (the default Gnome shell) the control code for 'Ctrl+Backspace' is ^H and the one for regular backspace appears as ^?! Would it be possible to modify my terminal settings to interpret the control code ^H to press an unused key (such as any of the F13-F24 keys)? I could then probably add that new key to the .nanorc file accompanied by the command to run.
    – gridlocdev
    Commented Nov 9, 2021 at 0:44
  • IIRC the GNOME Terminal configuration only has an option to change what gets sent for Backspace, but nothing for Ctrl-Backspace.
    – muru
    Commented Nov 9, 2021 at 0:48
  • 1
    Darn, yeah I've just checked the gnome terminal preferences and it looks like that's the case. Thankfully, it looks like Nano has a default keybinding for 'Ctrl+Shift+Del' for the function I'm looking for so I think I'll use that instead!
    – gridlocdev
    Commented Nov 9, 2021 at 1:18

You must log in to answer this question.

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