Using an External Keyboard On macOS

Get Home and Keys To Work Generally

mkdir -p ~/Library/Keybindings
nano ~/Library/KeyBindings/DefaultKeyBinding.dict

Put this stuff into the file:

{
/* Remap Home / End keys */
/* Home Button*/
"\UF729" = "moveToBeginningOfLine:";
/* End Button */
"\UF72B" = "moveToEndOfLine:";
/* Shift + Home Button */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:";
/* Shift + End Button */
"$\UF72B" = "moveToEndOfLineAndModifySelection:";
/* Ctrl + Home Button */
"^\UF729" = "moveToBeginningOfDocument:";
/* Ctrl + End Button */
"^\UF72B" = "moveToEndOfDocument:";
 /* Shift + Ctrl + Home Button */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:";
/* Shift + Ctrl + End Button*/
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:";
}

Restart the computer.

External keyboard vs. ZSH

ZSH is default shell in Catalina, so put this into ~/.zshrc:

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

Now Home and End keys work.

iTerm 2

Go to Preferences - Keys and remove Home and End bindings if it scrolls to the top and bottom.