Mac – How to get Home and End working for BOTH iTerm2 and VIM

itermkeyboardmac

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:";
}

Best Answer

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.