Generally Fn-Left and Fn-Right on a Macbook will produce the same keycodes as the standalone “Home” and “End” keys would on a full-sized keyboard, so they shouldn’t need to be mapped separately.
On the other hand, inside a terminal the “Home” and “End” keys produce a sequence of bytes rather than a single code (just like every special key), so a “describe key” function wouldn’t be much help: if Kakoune doesn’t recognise the special sequence, it would just tell you that you’d pressed the key corresponding to the first byte of the sequence (probably Esc) and then subsequent bytes would dismiss the message. I know, that’s a dumb way to handle key-codes, but terminal input is kinda dumb.
Basically, there’s two parts of the configuration that need to agree: iTerm needs to know what bytes to send, and Kakoune needs to know what bytes to expect for each key.
I believe iTerm lets you configure what bytes to send for each special key, but I’m going to assume it has sensible defaults. If you want to see for yourself what bytes a key sends and can’t find it in the configuration, the easiest way is to open a new terminal and run the
cat command with no arguments, and just press the key you’re interested in. For example, on the Linux computer I’m using now, when I run
cat and press Home:
…so for me, Home is the same as pressing Esc[H. Note that Esc is written as
^[ for historical reasons.
Kakoune sets its expectations from the
$TERM environment variable, which names what terminal variant you’re using. Again, on my computer:
$ echo $TERM
That terminal name is looked up in a database that describes what bytes are sent for the various keys the terminal supports. You can look up that database yourself with the
tput command. Because it prints the raw output to the terminal, we’ll need to pipe it through
cat -v to turn control-characters into visible ones.
$ tput home | cat -v
Unsurprisingly, the “home” field for my terminal contains the bytes my terminal sends when I press “Home”. If you’re interested,
infocmp -1x should list all the fields for your terminal, and
man 5 terminfo should explain what all the cryptic names mean.
tput home | cat -v produces different output than typing Fn-Left into
cat directly, you probably need to change
$TERM to something appropriate for your terminal. I believe iTerm has a config option for what
$TERM is set to for each new terminal. In your case, you probably want the first one from this list that works: