General Question

andrew's avatar

Anyone remember how to use vi keystrokes on the command line?

Asked by andrew (16380points) 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

andrew's avatar

@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.

Stocky's avatar

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

Stocky's avatar

$ set -o vi

to get to vi mode

robmandu's avatar

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.

robmandu's avatar

[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

robmandu's avatar

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.

robmandu's avatar

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!

andrew's avatar

@robmandu: set -o vi works perfectly in bash. (Thanks Stocky!)

robmandu's avatar

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




to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
Knowledge Networking @ Fluther