Lesson 12 of 26
Vim Shortcuts in Bash and ZSH
In this lesson
Roy shows that Bash and Zsh can use vi key bindings to edit the command line, turned on with set -o vi, which can also go in the shell's rc file. After pressing Escape on a long command line he uses b, cw, dd, p, Shift-P and undo to move, change, delete and paste text.
Transcript
[00:06] (external link, opens in new tab) One of the coolest things you can actually do with vi is to understand that its bindings appear almost everywhere. You can even have your bash or zshell in my case to use vim command vim shortcuts. So to set it you would do and this works both in bash or in zshell you would say set minus o and then vi and from this moment on and of course you can put this in your like bash rc file or zshell rc file you you can actually edit your command lines this way.
[00:39] (external link, opens in new tab) If this is a really long command line and I press escape, let me just show you the shortcuts here. I can actually press B to go back. I can press CW. Let's say CW to change a word here. Changed. I can press escape again. I can press DD to delete the whole line. I can press P to paste the line just above.
[01:11] (external link, opens in new tab) I can press undo to undo. I can press shift P to paste the line right here and etc etc. So vi is really really useful in many many places and this is just this small tip has changed my life. Well well as far as you can change your life if you're a geek like me when working with command lines.