>'set -o vi' in bash lets me search my command history with the same keys as moving around vi
+10
I love 'set -o vi' and have been using it for ages, since ksh in fact. It makes editing commands and then re-issuing them so fast in Unix, if you're even just okay at vi - don't even need to know vim. Used to immediately put it into the .kshrc on any new Unix system I started working on (along with some other commonly used productivity settings, of course).
A fact that some might not know about 'set -o vi' is that once it is set (a one-time task per login shell, or put it in your login shell's profile file, then it is one-time, period), and you are now editing a command at the command prompt (using vi features), you can just press v to open up vi with a temp file containing that command, edit it using the full-screen view and power of vi, then save the file and it runs automatically.
This is particularly useful for multi-line shell commands like a for or while loop, or a long command pipeline.
And while in that vi session, if you decide you do not want to run the command right now, you can always save it to a different, persistent file name (with :w filename), and exit the temp file without saving it.
Then the command will not run, but you've saved it in a permanent file, and can do anything with it, now or later.This is useful if you realize in the middle of editing it, that you want to look up some command syntax (to add to the file), or polish the code some, etc., but maybe not right now, because you want to finish your current task first (which the original command sequence was a part of). You can just edit that permanent file at your leisure later, polish and test it, then use it regularly as needed.
> you can just press v to open up vi with a temp file containing that command, edit it using the full-screen view and power of vi, then save the file and it runs automatically.
FWIW you can do this with ctrl-x ctrl-e in normal (emacs-like mode) and it will open up your $EDITOR. Example:
> EDITOR=nano # or EDITOR=vi, EDITOR=emacs, etc
> echo [ctrl-x ctrl-e]
* edit command by adding foo and save*
> echo foo
Thanks, good to know. I don't use emacs, but thinking of trying it out after these years of not using it. In the initial years I did not have access to it on the Unix machines I worked on, only had vi, and later I read that it needed a lot more keystrokes than vi, also the high use of Ctrl key, which is in an awkward position (though I know it can be swapped with say Caps Lock through software). That may be why I did not get into using it, though I have read that it is extremely powerful because it is programmable in Elisp. (I've read Steven Levy's book and some other stuff about GNU, rms, etc., including the book Free as in Freedom about him and GNU. Good read.) I love programmable tools and prefer them to the non-programmable kind, but have kind of made an exception of sorts in the case of editors - I know vim too is programmable but having looked briefly at its syntax, don't like it much. So I guess I may get into emacs after all, but somewhat slowly.
+10
I love 'set -o vi' and have been using it for ages, since ksh in fact. It makes editing commands and then re-issuing them so fast in Unix, if you're even just okay at vi - don't even need to know vim. Used to immediately put it into the .kshrc on any new Unix system I started working on (along with some other commonly used productivity settings, of course).
A fact that some might not know about 'set -o vi' is that once it is set (a one-time task per login shell, or put it in your login shell's profile file, then it is one-time, period), and you are now editing a command at the command prompt (using vi features), you can just press v to open up vi with a temp file containing that command, edit it using the full-screen view and power of vi, then save the file and it runs automatically.
This is particularly useful for multi-line shell commands like a for or while loop, or a long command pipeline.
And while in that vi session, if you decide you do not want to run the command right now, you can always save it to a different, persistent file name (with :w filename), and exit the temp file without saving it.
Then the command will not run, but you've saved it in a permanent file, and can do anything with it, now or later.This is useful if you realize in the middle of editing it, that you want to look up some command syntax (to add to the file), or polish the code some, etc., but maybe not right now, because you want to finish your current task first (which the original command sequence was a part of). You can just edit that permanent file at your leisure later, polish and test it, then use it regularly as needed.
Edited for formatting and grammar.