Skip to content

Instantly share code, notes, and snippets.

@mkfares
Last active March 10, 2025 15:30
Show Gist options
  • Save mkfares/e23eb57d943145eb543d97ac7ef05732 to your computer and use it in GitHub Desktop.
Save mkfares/e23eb57d943145eb543d97ac7ef05732 to your computer and use it in GitHub Desktop.
Common zsh Keyboard Shortcuts on macOS Catalina

Common zsh Keyboard Shortcuts on macOS

Navigation

CTRL + A : Move the cursor to the beginning of the line
CTRL + E : Move the cursor to the end of the line
OPTION + Left Arrow : Move the cursor one word backward
OPTION + Right arrow : Move the cursor one word forward
Left Arrow : Move the cursor one character backward
Right Arrow : Move the cursor one character forward

Deletion

CTRL + U : Delete the current line
CTRL + K : Delete from the cursor to the end of the line
ESC + Backspace : Delete one word backward
CTRL + W : Delete one word backward
CTRL + D : Delete one character forward
Fn + Backspace : Delete one character forward
Backspace : Delete one character backward
CTRL + L : Clear the screen

Undo

CTRL + _ : Undo the last change

Process and Shell

CTRL + C : Terminate the running foreground process
CTRL + Z : Suspend the running foreground process
CTRL + D : Exit current shell

History

Up Arrow : Recall the previous command in history
Down Arrow : Recall the next command in history
CTRL + R : Search the command history
CTRL + G : Escape from command search mode
!! : Execute the last typed command
!pw : Execute the last command in history that begins with pw

Auto-completion

TAB : Auto-complete the typed command
TAB TAB : Show list of commands
TAB TAB TAB ... : Cycle through matched commands

List all Keyboard Shortcuts

% bindkey

@elcolie
Copy link

elcolie commented Oct 10, 2020

bindkey 👍

@mBillan
Copy link

mBillan commented Jan 31, 2022

That was helpful 👍 thanks

@joelz
Copy link

joelz commented Feb 10, 2022

That was helpful 👍 thanks

@wtmpx
Copy link

wtmpx commented Mar 17, 2022

< filename ; will display "filename" file ; less-than sign "<" call less command.

@kmbenjel
Copy link

kmbenjel commented Jun 7, 2022

Thanks

@adam-kral
Copy link

adam-kral commented Sep 26, 2022

For changing behavior of ctrl-u to delete not the entire line but just up to the cursor use this: https://super-unix.com/unixlinux/ctrl-u-deletes-whole-line-regardless-of-cursor-position/

@Alireza-Safdari-Khosroshahi

Thanks

@weberc2-tempus
Copy link

weberc2-tempus commented Jun 12, 2024

CTRL + A : Move the cursor to the beginning of the line
CTRL + E : Move the cursor to the end of the line
OPTION + Left Arrow : Move the cursor one word backward
OPTION + Right arrow : Move the cursor one word forward

None of these work for me by default. Tried on both Terminal.app and VS Code's builtin terminal. OPTION + Left Arrow does move the cursor back one word, but it puts it in some edit mode such that if I subsequently press the right arrow key it will delete everything after the cursor (other keys do strange things in this mode as well, for example, pressing e in this mode will jump to either the end of the line or the end of the character). OPTION + Right Arrow doesn't move the cursor and puts zsh into the weird mode. Bash works properly on both terminal emulators. I have not added any keybindings.

CTRL + A just drops ^A characters into the terminal.

When I run cat and then do Option + Left Arrow followed by Option + Right Arrow it prints ^[b^[f.

@eqdw
Copy link

eqdw commented Dec 5, 2024

Hopefully this thread isn't dead

CTRL + A just drops ^A characters into the terminal.

I have had my zsh set up for a year now such that ^A / ^E behave as the OSX cursor control bindings. But something has happened to my work machine terminal environment that broke a bunch of stuff, and when I fixed it all, I now have the behaviour you're reporting.

ISTG there was some kind of zsh option I had previously set to make it behave the OSX way, but for the life of me I don't remember/can't find it. Does anyone know what it is?

@kmbenjel
Copy link

kmbenjel commented Dec 5, 2024 via email

@eqdw
Copy link

eqdw commented Dec 5, 2024

UPDATE: I figured it out.

I had bindkey -v in my zshrc. Removing that has restored osx keybinding behaviour

@kmbenjel
Copy link

kmbenjel commented Dec 5, 2024 via email

@johnthompson365
Copy link

Really useful thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment