3

I'd like to rebind the alt-left and alt-right keybindings in nano, can't seem to get it to work. I'm on ubuntu 16.04

my ~/.nanorc file:

bind M-right nextword main
bind M-left prevword main

version info:

GNU nano, version 2.5.3
(C) 1999..2016 Free Software Foundation, Inc.
Email: [email protected] Web: http://www.nano-editor.org/
Compiled options: --disable-libmagic --disable-wrapping-as-root --enable-utf8
4
  • 1
    Taking a quick look at src/global.c where the detaults are loaded, it seemed to me that either "M-Left" (with uppercase L) or "M-←" (with U+2190, that's what's encoded in UTF-8 there) would work, however, they don't (in accordance with the docs as shown in Thomas's answer). I recommend that you file a bug / feature request in nano's bugtracker at savannah.gnu.org/bugs/?group=nano.
    – egmont
    Commented Sep 13, 2017 at 22:40
  • So I'm looking at the nano source and I found this: git.savannah.gnu.org/cgit/nano.git/tree/src/… (Line 1147) This doesn't seem to work though :/ bind M-\xE2\x86\x90 nextword main bind M-\xE2\x86\x92 prevword main Anyone know c? Commented Sep 14, 2017 at 0:24
  • 1
    The C compiler interprets those \x escapes, and it becomes the raw UTF-8 representation of '←' as I've shown above.
    – egmont
    Commented Sep 14, 2017 at 7:00
  • 1
    See also savannah.gnu.org/bugs/?51685#comment3.
    – egmont
    Commented Sep 14, 2017 at 20:13

2 Answers 2

5

If you see messages like [ backup files enabled ] when you try those shortcuts, it means they are producing Alt+B and Alt+F escape sequences. So you can just rebind those like so:

unbind M-B all 
bind M-B prevword main 
unbind M-F all 
bind M-F nextword main

See this bug report thread for more info.

1
  • OMG! Thank you so much for this! I added it to my .nanorc and I can finally move around in my files like a normal human being. I literally created an account to thank you. So thank you. Commented Mar 14, 2019 at 16:11
2

It doesn't work because

  • nano does not have a way to bind the cursor-keys (left, right, up, down), and
  • those keys do not correspond to a character, and
  • your cursor-keys send a character sequence which nano does not understand.

Referring to the manual:

The format of key should be one of:

^ followed by an ASCII character or the word "Space". Example: ^C.
M- followed by a ASCII character or the word "Space". Example: M-C.
F followed by a numeric value from 1 to 16. Example: F10.

The manual also mentions that you can use an escape character before the ASCII character when entering a key, though that would not help in this case because your cursor-keys send several ASCII characters, e.g.,

escape[1;3D

for the "Alt-left" which several terminal emulators (beginning with xterm) use.

0

You must log in to answer this question.

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