Why Doesn't Terminal Doesn't Handle Escape Codes?

The short version is that I'm on Mavericks 10.9.2 and when I edit my keyboard, anything after \033[ and a digit is treated as text, indicating the \033[ is not being read as an escape code. I want to edit some of the cursor movement keys (mainly home, end, and forward delete) and I've put in the proper escape codes, but none of them work. as of now I have:


  • Home: \033[1~
  • End: \033[4~
  • Delete (forward): \033[3~


They will not work. In each case, when I use any of these three keys, I get a tilde (~) printed on the console, but no action at all. (I have the same issue with anything other keys, including pre-set ones, that use escape codes in Terminal.)


I have the terminal set to emulate a VT102.


I just like to get the escape sequences working on the Terminal.


--------------------------------------------

Background:


I just upgraded from an iMac from 2007/2008 (bought it refurbished in 2009). The older iMac had been upgraded to 10.9.1. Migration Assistant would not work and did not copy any files - but sat there and claimed to be working. So I set up my account and re-created ~/Library/KeyBindings/DefaultKeyBinding.dict (included at the end of this post) and I copied over ~/Library/Saved Application State/com.apple.Terminal from the old iMac to the new one. I tried to find any folders in ~/Library/Application Support, but there was nothing there.


This was working fine on my old iMac under 10.9.1, but never once worked on my new one, on 10.9.1 or 10.9.2


Here is my DefaultKeyBinding.dict:


{

/* Remap Home / End keys to be correct */

"\UF729" = moveToBeginningOfLine:; /* Home */

"\UF72B" = moveToEndOfLine:; /* End */

"$\UF729" = moveToBeginningOfLineAndModifySelection:; /* Shift + Home */

"$\UF72B" = moveToEndOfLineAndModifySelection:; /* Shift + End */

"@\UF729" = moveToBeginningOfDocument:; /* Cmd + Home */

"@\UF72B" = moveToEndOfDocument:; /* Cmd + End */

"$@\UF729" = moveToBeginningOfDocumentAndModifySelection:; /* Shift + Cmd + Home */

"$@\UF72B" = moveToEndOfDocumentAndModifySelection:; /* Shift + Cmd + End */

/* "\UF739" = (insertText:, "Testing text to see if anything works."); */

}

iMac (27-inch, Late 2013), OS X Mavericks (10.9.2)

Posted on Mar 6, 2014 8:49 PM

Reply
5 replies

Mar 7, 2014 8:21 AM in response to HalNineThousand

By changing the name of the Library folder from KeyBindings to Keybindings I was able to get this to work (never tried it before) . I know file system is not case sensitive so why? But it did.


The following


{

"\033" = {

"f" = "moveWordForward:"; /* ESC f */

"b" = "moveWordBackward:"; /* ESC b */

};

}


gave me forward and backward word on ESC f and ESC b


I found the name change suggestion here https://www.object.com/TechNotes/DefaultKeyBinding.html

Mar 7, 2014 10:20 AM in response to Frank Caggiano

Frank, I'm at work, so I'll be trying that this evening. I found that the KeyBindings did work because the home and end keys started working in other places, so it's being read by the OS. So it's not that the data isn't being read and used. But I know the Terminal app handles things differently. For some reason, when it gets the escape sequence, it seems to see it as dead characters and just prints the character after escape.


Also, did you have to reboot for that to work? Or did it work on programs you launched after the change?

Mar 7, 2014 10:31 AM in response to HalNineThousand

I had to log out and back in but not reboot. However I only tried it in OS X apps, Notes, Safari, etc . not in the terminal.


While I was searching the web for this I do remember coming across one site that did mention something about after doing this you had to do something else to get bash to respond but I can;t remember off the top of my head what that was or were the site is. If I can track that down again I'll post it.


regards

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.

Why Doesn't Terminal Doesn't Handle Escape Codes?

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