Skip to content

Instantly share code, notes, and snippets.

@2KAbhishek
Last active April 17, 2024 14:47
Show Gist options
  • Star 104 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save 2KAbhishek/9c6d607e160b0439a186d4fbd1bd81df to your computer and use it in GitHub Desktop.
Save 2KAbhishek/9c6d607e160b0439a186d4fbd1bd81df to your computer and use it in GitHub Desktop.
Keyboard shortcuts for bash/zsh

Shell Keybindings

Navigation 🚀

Alt + f/b - Move cursor to previous/next word

Ctrl + a/e - Move cursor to beginning/end of command

Ctrl + xx - Toggle between the start of line and current cursor position


Editing ✏️

Ctrl + x,e - Open command in editor

Ctrl + k - Cut till end

Ctrl + u - Delete whole line (zsh)/ cut until beginning (bash)

Alt + w - Delete until beginning (zsh)

Alt + l/u - Lowercase/Uppercase word

Alt + c - Capitalize Word

Ctrl + w - Cut previous word

Alt + Del - Delete previous word

Alt + d - Delete next word

Alt +. or !$ - Previous commands last arguement

!* - All arguments of previous command

Alt + t - Swap current word with previous

Ctrl + t - Swap the last two characters before the cursor (typo).

Esc + t - Swap the last two words before the cursor

Ctrl + y - Paste

Ctrl + _ - Undo

Alt + r - Cancel the changes, revert


Process 📊

Ctrl + l - Clear screen

Ctrl + c - Interrupt/Kill

Ctrl + d - Close Current Shell

Ctrl + z - Background/Foreground job


History ⏳

Ctrl + r - History search

Ctrl + s - Go back to the next most recent command

^abc­^­def - Run previous command, replacing abc with def


Modes 🕹️

Ctrl +x,v - vi mode (zsh)

set -o vi - Vi mode

@cybera3s
Copy link

cybera3s commented Aug 1, 2022

Perfect

@julioflima
Copy link

Ctrl + r - History search

Is awesome, I'm trying to let this fixed, like autocomplete, every time that I type something.

@2KAbhishek
Copy link
Author

You can use oh-my-zsh with the fzf plugin, here's what mine looks like, link: https://github.com/2kabhishek/Dotfiles

screenshot_1609_1

@gt-novelt
Copy link

Very nice

I would add Ctrl+p Previous command

@eclectic-coding
Copy link

FWIW, Shift+G will return you to the bottom of the shell output. Especially helpful in server logs, in my case, rails server

@stobix
Copy link

stobix commented Jun 22, 2023

I'd like to add how to get to the previous COMMAND .
Sure,
Ctrl+a takes me to the beginning of the line,
Ctrl+p takes me to the previous line,
but having a 100 line long command, none of the above helps me much in getting to the previous command easily.
It seems like:
ESC+< goes back to the actual beginning of the command buffer for zsh (or the first line of history if already at start of command), and ESC+> likewise goes to the end.
So to get to the previous command in a 100-line command case, use ESC+<, Ctrl+p instead of 100 x Ctrl+p
Feel free to verify that the same holds true for bash, anyone. :)

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