Essential Keybindings For Bash, Fish and Zsh

preview_player
Показать описание
One of the most useful features of the Bash shell (Fish and Zsh too!) is the built-in keybindings that can greatly speed up your terminal workflow.

By default, your shell uses Emacs-style keybindings, but you can change to Vim-like bindings if you prefer. The following are the commands to change to Vi-bindings (and back to Emacs-bindings).

BASH: set -o vi (set -o emacs)
ZSH : bindkey -v (bindkey -e)
FISH : fish_vi_key_bindings (fish_default_key_bindings)

The following commands were shown in this video. Listed are the Emacs-bindings followed by the Vim-bindings in parentheses:

CTRL-a (0 or ^) jump to beginning of line
CTRL-e ($) jump to end of line

CTRL-f (h) move forward one char
CTRL-b (l) move backward one char

ALT-f (w) move forward one word
ALT-b (b) move backward one word
2w, 2b...in Vi-mode

CTRL-k (d$) delete from this point to the end of the line
CTRL-u (d0) delete from beginning of the line to this point
CTRL-y (u) undo

CTRL-w (db) delete a word backwards
ALT-d (dw) delete a word forwards

Alt-. to past last command argument
Or just type !!, !$ in the command line

CTRL-p (k) move to prev command in history
CTRL-n (j) move to next command in history

CTRL-l to clear terminal
CTRL-d to exit the shell

WANT TO SUPPORT THE CHANNEL?

DONATE CRYPTO:
💰 Bitcoin: 1Mp6ebz5bNcjNFW7XWHVht36SkiLoxPKoX
🐶 Dogecoin: D5fpRD1JRoBFPDXSBocRTp8W9uKzfwLFAu
📕 LBC: bMfA2c3zmcLxPCpyPcrykLvMhZ7A5mQuhJ

DT ON THE WEB:

FREE AND OPEN SOURCE SOFTWARE THAT I USE:

Your support is very much appreciated. Thanks, guys!
Рекомендации по теме
Комментарии
Автор

I was a Windows user 2 weeks ago; now an Arch user & if it wasn't for your vidz & the wiki... I'd probably still be using Windows. Merci 😌

pizzapizza
Автор

Instead of configuring vi mode in Bash you could configure for many programs at once using .inputrc, it's a configuration file for the GNU readline library which is used for text prompts in many CLI tools, not just Bash but also Python interactive shell, etc. There are a bunch of config options but the basic one is "set editing-mode vi" in .inputrc which applies it to all programs at once! (Zsh does not use .inputrc and I don't think Fish does either, but Bash definitely does)

gardenapple
Автор

I know and use some of these key bindings for many years. I still learnt new and useful ones from your short video.

marot
Автор

CTRL-y is not really an undo. It's more like a paste command (which it is in Emacs).
And CTRL-w, ALT-d, CTRL-k, and CTRL-u are more like cut commands.
So you can actually move an argument or word around using these commands.
For example, if you have
$ echo word1 word2
and you press "CTRL-w ALT-b CTRL-y <Space> " you will get
$ echo word2 word1

Yimyim
Автор

O-M-F-G. Thanks, just thanks! I never questioned if there were keybindings...

ProCoder
Автор

I've been using a lot of emacs bindings without knowing their origin. It is very nice to know such things and also be aware of options (like `set -o vi`) in order to change them. This will permanently influence how I work with the shell, thank you very much.

Also I'm checking out the emacs video right now^^

PhyFlame
Автор

1. In macOS Terminal, in the options->Profile tab, enable the checkbox "Use Option as Meta key" to have this keybindings.
2. I just want to thank you for this content and channel, I though I knew how to use the terminal until I saw your content, which is like a glass of water in a desert.

RodrigoPolo
Автор

In vi mode use '_' character in normal mode to get the last parameter of the last command. You can also use the numbers before to get the argument of the specific number.

michakozio
Автор

Great episode, I'm trying to use these more lately, great time savers.
Ty

dragonsage
Автор

A long time ago (though still in this galaxy), I used emacs. These days I'm a vim addict. But I tried vim keybindings for bash and ended up going back to the standard emacs ones.

Chalisque
Автор

Thank you for covering this. I learned that stuff in school, but I had forgotten so much of it. And, being a Windows user mainly, kindof dumbs me down. I just use arrow keys & only few extras.

PoeLemic
Автор

Good one, as always 🙂

Hey, DT! Recently, I find myself using a lot of regex in my nvim workflow (%s/...). Would you consider making a video on the topic?

marioschroers
Автор

Thank you. Good info. Relearned a forgotten.

muddyexport
Автор

"set -o vi" was the solution to all my miseries and it's been so many years I didn't know that.

vanshajdhar
Автор

For my keybindings, I've got home and end to go to the start and end of a line, Ctrl+{LArrow, RArrow} to navigate by words, Ctrl+Del to delete forward and Alt+Backspace to delete backwards. Though, I really don't do much line editing. I tend to just add to my .bashrc anything I keep typing repeatedly and occasionally if I need something temporarily I'll just create a function at the terminal. Sometimes I'll make a .sh file if I don't want it polluting the .bashrc but I need it multiple times, like starting up qemu instances.

anon_y_mousse
Автор

Great channel. Thanks so much for sharing all the valuable information and experience 👍👍👍

stefosters
Автор

just a note ^ brings you to the start of text, 0 brings you to the actual start of the line regardless of leading whitespace or tabs

cathalogrady
Автор

Oh no I am used to emacs standards, very useful to know!

syrefaen
Автор

Well hot damn, I've been working in the shell for more than a decade and didn't know that I could change to vi bindings, what an oversight.

Also, just to take advantage of shells and fish in particular being discussed: don't be surprised if you change to fish and "!!" or "!$" don't work, that's apparently by design – a design I very much disagree with and why "plugin-bang-bang" is the first thing I install alongside fish. Call me oldskool, but "sudo !!" will probably forever be more ingrained in my mind rather than "[UP]->Ctrl+A->sudo "

LordHonkInc
Автор

As always writing a comment to support the channel

burning_KFC
join shbcf.ru