Before, I had this working well using Karabiner (if I remember correctly). But after a reinstall of macOS, I couldn't get this working anymore. Even restoring the Karabiner configuration (in
~/.config/karabiner) from a backup didn't work. Too much time spent in trying to configure Karabiner Elements, trying several of the "complex modifications" offered on the site, didn't result in something that worked for most applications.
I finally stumbled upon an alternative key mapping tool in a Karabiner-Elements issue comment. While ⌘英かな is a Japanese application, it is simple enough to set up the required key mappings. Mapping Home/End to Ctrl+Q/E (A/E on my Belgian Azerty keyboard), Home/End key behavior can be fixed for most apps.
For some applications, the key mapping doesn't fix things. For these, you should disable the remapping:
For some of these, you can improve Home/End behavior by configuring custom keybindings. Create/edit
/* Remap Home / End to be correct :-) */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */