9

I have been through at least a dozen articles and internet searches (including this one) and I cannot find a setting that satisfies what I want: Both iTerm2 (at command prompt) and VIM to recognize Home and End the way they're meant to be used.

If I set Home to hex code 0x01 in iTerm2 key mapping, it starts working at the prompt, but stops working in VIM.

If I leave it alone, hitting Home and End work fine in VIM, but not at prompt.

What the hell is going on?

I have a Mac Keybinds file (located at ~/Library/KeyBindings/DefaultKeyBinding.dict) that looks like this; and I have the same behavior when the keyword is BeginningOfLine as what's set here (BeginningOfParagraph):

{
/* Home Button*/
"\UF729" = "moveToBeginningOfParagraph:";

/* End Button */
"\UF72B" = "moveToEndOfParagraph:";

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

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

/* Ctrl + Home Button */
"^\UF729" = "moveToBeginningOfDocument:";

/* Ctrl + End Button */
"^\UF72B" = "moveToEndOfDocument:";

/* Shift + Ctrl + Home Button */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:";

/* Shift + Ctrl + End Button*/
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:";
}

1 Answer 1

12

The problem turned out to be Zshell.

New macbooks come default with zshell now, creating confusion for setting these keys on a full size keyboard. Typing bash and using that as my default shell worked without a problem, but I wanted to know how to accomplish this in zshell.

The solution was to first remove any keybindings set in iTerm for home and end; then modify ~/.zshrc with the following I got from this link:

bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line

Then, obviously, source ~/.zshrc.

4
  • you might wanna add, that first we need to remove the home and key bindings from iterm2 key preferences, and then set the values in ~/.zshrc as you said. Commented Aug 12, 2021 at 5:14
  • how do you know the "^[[H" is for Home and "^[[F" is for End? where i can found the reference table for each key? This solution worked fine, thx! Commented Aug 11, 2023 at 16:39
  • 1
    Hey @ArthurMelo, the link is right there in my post.
    – Locane
    Commented Sep 3, 2023 at 18:39
  • thank you so much for this - it was the only solution I've seen that actually accomplishes what I needed. To add to it though, I just want to say that unfortunately this won't help in all MacOS applications - you will have to just get used to using command-left / command-right to move to beginning and end of lines in other apps like chrome.
    – tamale
    Commented May 15 at 19:31

You must log in to answer this question.

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