Home
and End
do nothing in iTerm2, nor do ⌘← and ⌘→.
However, Ctrl-A
and Ctrl-E
do work.
Can Home
and End
do this?
Preferences->Keys_Key Bindings in iTerm2 do not offer a "Start of Line" or "End of Line option.
Home
and End
do nothing in iTerm2, nor do ⌘← and ⌘→.
However, Ctrl-A
and Ctrl-E
do work.
Can Home
and End
do this?
Preferences->Keys_Key Bindings in iTerm2 do not offer a "Start of Line" or "End of Line option.
^ ControlA and ^ ControlE are keybinding in Bash and ZSH, not in iTerm (or Terminal).
If you want custom bindings within iTerm, you will need to bind the actual keyboard sequence in the keybinding. "Start of Line" and "End of Line" are descriptors, not the actual key strokes.
So, to do this you'd need to send ^ ControlA for Home via their Hex Codes. In this case, the codes would be 0x01
for "start of text" (^A) and 0x05
for "ENQ" (^E).
In the image below, you can add a new binding in Preferences → Keys → Key Bindings
+
to add a new bindingThe accepted solution proposed by Allan is not optimal, as this keybinding affects *ALL* applications that are executed on the terminal and this key remapping would mean that some applications won't work as expected:
For example, if you use 'vi' then the keys 'Home' and 'End' no longer work after this key binding (those keys work ok if you don't do the proposed key binding)
A better solution is to do the key mapping on the shell itself:
In zsh (the default shell being used by macos nowadays), just add this in ~/.zshrc:
bindkey '\e[H' beginning-of-line
bindkey '\e[F' end-of-line
and Home and End keys will work ok in both the command line and vi
\e[D
for beginning of line? Atleast in my iTerm, pressing Option and CursorLeft seem to produce escape-D
Commented
Aug 16, 2023 at 9:23
For me the best answer was a combination of the above:
Home
and End
. This will cause Home
(fn
+left arrow
in mac) & End
(fn
+right arrow
in mac) to work normally as in linux and not as Scroll to Top
or Scroll to Bottom
respectively.This allows to jump to start or end of line in all cases using Home
& End
keys, including in 'vi'
bindkey
solution above
Commented
Apr 5 at 0:47