Modifying Key Assignments Nano Editor

I have been unable to change any key mappings in Nano editor using the "bind" and unbind" commands. If I add either of these commands to the .nanorc file I end up with an error which appears on the command line after I close the editor. None of the mappings work while I am in the editor.

Posted on Aug 22, 2019 10:29 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 22, 2019 4:49 PM

macOS nano is GNU nano version 2.0.6, and I do NOT think it supports the 'bind' command.


HomeBrew will install GNU nano, version 4.3, which DOES include the 'bind' command.

https://brew.sh

brew install nano

/usr/local/bin/nano

Similar questions

9 replies

Aug 23, 2019 6:26 AM in response to BenderR

I am not a nano person, and I've maybe played with nano less than 2 hours in the last 35 years, so just assume I'm asking the stupid questions that might spark a solution of your own 😀


I've played (hacked away until something worked), and I got the following:

unbind ^V       main
bind   ^V "^U"  main

unbind ^X       main
bind   ^X "^K"  main

unbind ^C       main
bind   ^C "^[6" main


WARNING: If you remap ^X then you will need another way to exit nano 😀


OK what you see is not exactly what you enter:


The ^V, the ^X and ^C are exactly what you see. The Caret key (shift-6 on the keyboard), followed by the letters V, X and C.


The values inside the "..." MUST be the literal escape and control characters, which you enter via nano using

escape v control-u
escape v control-k
escape v escape 6

I mean to literally

  • tap the escape key, tap the v key, hold control key and tap the u key
  • tap the escape key, tap the v key, hold control key and tap the k key
  • tap the escape key, tap the v key, tap the escape key, tap the 6 key


This worked for me using the HomeBrew nano v4.3


With respect to Vim, Emacs, and other editors, I fully understand that nano is what is available on other platforms you need to use and having a consistent editing interface is important. And unless you are writing a masters or doctors thesis in nano, or millions of lines of code, then there is no reason to learn other editors as switching back and forth can be counter productive.


I am a long time vi/Vim user and I do know how to bind keys in Vim, but I'm not going to go down that road, as I think it is just a distraction for you.


Good luck.


Aug 22, 2019 5:42 PM in response to BobHarris

Thanks for the reply. I installed 4.0.3 using Homebrew and verified that was the version running, but it’s still not accepting the bind/unbind command. I checked /etc/nanorc and the only setting there is set nowrap. /etc/nanrc.start has the same setting, but it’s commented out. I have ~/.nanorc which works and has allowed me to make some other, non-keystroke-related changes, but the second I try to bind or unbind a keystroke i get an error.


I use keybinding with the nano editor on my Windows machine at work and on Linux machines, with great success. The notion here is to have an editor that operates the same on all three processes. I’m truly at a loss.

Aug 22, 2019 7:55 PM in response to VikingOSX

Nano works very well for the three main areas I work in, TCL scripts, shell scripts and Cisco configs. The ability to work from BASH, using it to SSH into a Cisco router, being able to FTP directly from BASH and to be able to edit in Nano without ever invoking a mouse really helps.


If I'm able to keymap Nano, I can preserve the Ctrl-C, Ctrl-V, Ctrl-X conventions within my editor, the Cisco CLI and any other text-based work I’m doing. Using the native SSH client in Mac OS allows me to cut and paste directly into a Cisco device and it, along with Debian, are the only places I can do that. My workplace supports Windows 10 and Mac OS, so those are my choices and, overall, I always prefer Mac OS.

Aug 22, 2019 9:05 PM in response to MrHoffman

As far as I can tell, it is processing ~/.nanorc, it’s just rejecting the key bindings that I put in there. I have some custom colors that I’ve added for Syntax highlighting and they seem to work. I’ll post what I’m getting in the way of error messages, but it probably won’t happen until tomorrow after work.


I have experimented with VIM, but haven’t yet figured out how to bind keys. I’m a little reluctant to go that way because of the modal nature. Maybe EMACs would be the solution, but it’s too bad that I can’t get Nano to map, because it’s perfect for my needs.

Aug 22, 2019 9:54 PM in response to BenderR

Yes, you’re using nano. Yes, you’re attempting to bind keys. Yes, you’re getting errors. Specific commands used and example rc contents and exact error messages received all make it easier for someone else to understand the specific environment here, and to then try to reproduce the issues being encountered.


The previously-linked discussion covers the system-wide rc files accessed by nano, and the build-time settings which then select the rc files used for that particular build of nano.


Cut and Paste on macOS is a system shortcut. Prolly also on Windows, but I’ve not used that in a while.


The expect command can be interesting for scripting sessions.


bash can be configured to use vim or emacs key shortcuts. I don’t know off-hand if it also supports nano.


The version of bash provided with macOS is ancient, and Apple is switching the default shell from bash to zsh.


vim and binding: https://vim.fandom.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_1)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Modifying Key Assignments Nano Editor

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.