Anyone remember how to use vi keystrokes on the command line?
Asked by
andrew (
16562)
June 25th, 2008
I remember people in college writing commands in bash using vi keystrokes. Anyone remember how do to this?
Observing members:
0
Composing members:
0
12 Answers
@stocky: I know how to use vi, I just want to be able to type ^ and go to the front of my prompt on the command line.
Oh i didnt read your question right sorry, I have never heard of that before, but now i want to, If i find anything interesting ill get back to ya
$ set -o vi
to get to vi mode
For the record, set -o vi works in the Korn shell (ksh), but not so much in the others.
Bash, in my experience, usually already has the arrow keys enabled for access to the command history. So, Up Arrow in bash is like hitting Ctrl-K in ksh (after enabling with set -o vi).
—
Anyways, the short of it is to first realize what shell you’re in. Sounds like @Andrew’s in bash.
I’ll poke around some more (I prefer ksh most of the time) and see if I can get definitive on this for bash.
[Note to self: I’ve really gotta get better with bash.]
Fundamental moving around in bash:
● ^w erase word
● ^u erase from here to beginning of the line (I use this ALL the time.)
● ^a move the cursor to the beginning of the line
● ^e move the curor to the end of the line
- more very interesting info at Deadman
—————————
And I also found where you can filter the history, to prevent the repeated presentation of dupes and whatnot…
● export HISTIGNORE=”&:ls:[bf]g:exit”
- more here
BTW… I would say that those bash shortcuts are not consistent with vi usage.
In vi:
● ^w move forward one word
● ^u undo last change
● ^a insert text after cursor
● ^e goto end of current or next word
So, to be clear, the phrasing of the Question is flawed… but I think we all got the gist of it. ;-)
————
For this last quip, special thanks to the Mug of vi on my desk.
Crap. Crap. Crap. Crap. Crap.
Okay… EVERYTHING I posted about getting around in bash above is flawed b/c those jackholes at deadman .org neglected to use the proper capitalization on their web page.
I suggest going with @stocky’s excellent cheat sheet.
—
@Fluther mods: You would make me so happy if you’d simply remove all my dumbass posts here. Thx!
@robmandu: set -o vi works perfectly in bash. (Thanks Stocky!)
You’re right, of course. Glad that works in bash! And besides ksh, it also works in zsh.
I’ve now gotten around to confirming that it does not work in C Shell (csh), Bourne Shell (sh), and Advanced C Shell (tcsh). Maybe there’s another way to enable vi-access to history in those?
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.