Introduction
Learn how to use Vi mode on the command line in Bash.
Vim lovers rejoice.
Did you know you can use Vim mode on ...
For further actions, you may consider blocking this person and/or reporting abuse
Good little description.
BUT
There is ONE thing. This is NOT VIM mode. It's VI mode.
For instance you cant press escape and do
ciw
to change inner word. That works in vim but not in vi.You are correct.
Nice article!
You can do the same if you use Zsh. I've written an article how to configure Zsh without oh-my-zsh, and I speak about Zsh vi mode too: thevaluable.dev/zsh-install-config...
Mathhieu, thank you for sharing! The article you wrote is well written and packed full of information. I saw the Vi mode part. The changing cursor depending on the Vi mode is a great idea. I see we have some of the same Git aliases. Check out my configuration articles for my .bashrc and my .vimrc.
Bashrc Customization Guide – How to Add Aliases, Use Functions, and More
freecodecamp.org/news/bashrc-custo...
Vimrc Configuration Guide - How to Customize Your Vim Code Editor with Mappings, Vimscript, Status Line, and More
freecodecamp.org/news/vimrc-config...
For users who have built years of muscle memory using emacs-y shortcuts in bash, like
ctrl-a
,ctrl-e
,ctrl-k
,ctrl-u
,ctrl-w
,alt-f
,alt-b
... and so on, you can have best of the both worlds by using the shortcutctrl-x ctrl-e
which will edit current bash readline in$EDITOR
.You can see a demo of it in this blog post: dev.to/chhajedji/bash-edit-command...
"There is no up and down on the command line so j and k don't do anything."
well they do cycle throw the history for me [bash version 5.0.17]
Thank you.
j
andk
do indeed move through the command history. I have updated the article to include the new information.I use this a lot in my .bashrc
and this to run the second to last command
Now I can use the
j
andk
keys.Thank you sir, I have updated the article to fix the issue.
I have a question tho, what does command mode do, it doesn't seem to do anything and I can't quit it.
Thanks for leaving a comment.
Command mode allows you to move the cursor on the command line with the movement keys. Press
a
,A
,i
, orI
to exit command mode.We use CTRL+L to clear the screen. How to do it here?
While in command mode you should be able to just use ^L to clear the screen. (This is what worked for me on WSL Ubuntu 22.04.1 with bash version 5.1.16.
@smeagol correct. CTRL+L works to clear the screen.
For anyone wondering how to copy an entire line just do y$ or y^.
yy
to copy full line,p
for pasteNice article...
But I can't seem to be able to yank and paste between different terminals....each one seems to have it's own clipboard.
Anyway to fix/change this?
@kesnar I believe to copy and paste between terminals you have to highlight your text with the cursor, then click
CTRL+SHIFT+c
to copy andCTRL+SHIFT+v
to paste. You might even need to hold down the SHIFT key while you highlight your text.I never knew the search function existed, love it, thank you very much, what a time saver.