Nano Editor – How to Edit Keyboard Shortcuts

bashmacosterminal

Is there a way to edit the keyboard shortcuts in Nano?

I would like to change Move to next word from Right (Ctrl + Space) and Left (Alt + Space),
to Alt + or .

According to this thread on AskUbuntu, one should be able to edit /etc/nanorc. However, on my OS X computer, that file is empty except for this line:

set nowrap

Assuming that this is the only file there is, how could I override the keyboard settings here?

Best Answer

If you install a more up-to-date version of nano, it has improved keyboard navigation. In nano 2.7, the move word shortcut is ctrl+left/right. So you might not even need to do keybindings if you are satisfied with ctrl instead of alt.

  1. Install homebrew: https://brew.sh/
  2. Install nano: brew install nano

If you really want alt, then keep reading.

  1. If using Mac Terminal, you will need to enable the Use Option as Meta key setting. Otherwise the alt key won't work.

  2. /etc/nanorc might be ignored, depending on the flags when your nano was compiled. You can use ~/.nanorc instead, that will work for sure.

  3. Add these lines to ~/.nanorc. (It seems that nanorc does not allow left/right arrows for keybindings, so I chose , and . since they are the same keys as < and >.

    bind M-, prevword main
    bind M-. nextword main
    

Now alt+, and alt+. will move to prev/next words.

You can find the full list of commands here: https://www.nano-editor.org/dist/v2.7/nanorc.5.html#REBINDING%20KEYS . (You may want to find the exact version of your nano if not v2.7).