How can I change the keyboard shortcuts in nano?

10,405

Solution 1

The file /etc/nanorc contains some options that should allow you to customize the shortcuts used on the editor. Please note that this is a global config file and will modify the options for all users on your system.

Further details on the available options are given on the man nanorc page (the list is just too big to reproduce here):

enter image description here

It should be possible to keep the options localized only to your user by copying the system configuration file in to your user's home directory with

cp /etc/nanorc ~/.nanorc

and doing the modifications necessary there.

The configuration file on your home directory will prevail over the global settings one.

Solution 2

The following has been tested using nano from a terminal in MS-Windows.
It will get your nano one step closer supporting the "universal" shortcuts for copy/cut/paste etc. (at least in the Windows world).
Add these lines to the file /etc/nanorc

bind ^c copytext main
bind ^x cut main
bind ^v uncut main
bind ^z undo main
bind ^y redo main
bind ^f whereis main
bind F3 findnext main
bind ^h replace main
set tabsize 4
set linenumbers

Be aware they work per whole-line if you don't select text first :-/

If you have issues selecting text in nano with shift+arrow-keys then be aware this doesn't seem to be related to nano but your terminal program! It doesn't work in PuTTY, but it does e.g. work in Kitty (a fork of PuTTY, Windows-version / Linux-version) or Google's SSH client for Chrome.

(I'm using Debian buster)

Share:
10,405

Related videos on Youtube

flo
Author by

flo

I'm a Software Developer in Berlin, Germany.

Updated on September 18, 2022

Comments

  • flo
    flo over 1 year

    To indent a whole block of code in nano, after selecting it with alt+a, I have to press alt+{, which doesn't work on my german layout macintosh keyboard (and would be pretty annoying even if it did).

    How do I change and customize nano's keyboard shortcuts?

  • kurdtpage
    kurdtpage over 4 years
    Also: bind ^s writeout main
  • Kvothe
    Kvothe over 3 years
    For the issue of changing this only for the local user is there any way around this? (Want to change keybindings on a cluster. No root privileges can only install in my own folders. Should I create my own nano build and alter the path/ use an alias in order to use my own instead of the standard one.)
  • Kvothe
    Kvothe over 3 years
    Getting the error: Error in ~.nanorc on line 326: Could not map name "findnext" to a function Error in ~.nanorc on line 329: Unknown flag "linenumbers"
  • Kvothe
    Kvothe over 3 years
    Where do I find a list of available shortcuts to set? Is there version dependences and resources for these different versions?
  • MrCalvin
    MrCalvin over 3 years
    There is a list of keybindings here
  • deanresin
    deanresin over 2 years
    Great but then how do you quit out of Nano if you reassigned ^X?
  • MrCalvin
    MrCalvin over 2 years
    You should be able to see that in the menu at the bottom of the screen, it will probably change to F2
  • Jags
    Jags over 2 years
    @mrcalvin I'm getting errors for 2 key bindings, bind ^c copytext main and bind ^v uncut main, in Ubuntu MATE 21.04. Errors: Error in /home/admn/.nanorc on line 1: Cannot map name "copytext" to a function and Error in /home/admn/.nanorc on line 2: Cannot map name "uncut" to a function. Any idea on how to fix? Thanks.
  • br4nnigan
    br4nnigan over 2 years
    @Jags the linked documentation is outdated, try this. copytext is now just copy for example.
  • alper
    alper about 2 years
    Would it be possible to change keybinding for page down to M-v?