You are not logged in.
I randomly discovered this when reading documentation about GNU Screen, and thought it was awesome! By default bash (and I believe other shells too) use some emacs like commands for movement: <code>CONTROL-A</code> to move the cursor to the begining of the line, and <code>CONTROL-E</code> to move the cursor to the end of the line, etc.
You can change that behavior to more closely mimic the movements and commands in Vi by issuing the command:
$ set -o vi
If you just want to see what your current settings are, leave off the <code>vi</code> part.
$ set -o
allexport off
braceexpand on
emacs off
errexit off
hashall on
histexpand on
history on
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
noexec off
noglob off
nolog off
notify off
nounset off
onecmd off
physical off
posix off
privileged off
verbose off
vi on
xtrace off
Then you can hit the <code><ESCAPE></code> key to enter the command-editing mode. Then try out using the "<code>h j k l</code>" movement keys to navigation through the command history. You can also use other Vi movement commands to edit the line. If you want to go back to typing, use the typical "<code>i I a A</code>" keys to either Insert or Append as expected. To make this change permanent, just add the "<code>set -o vi</code>" command in your <code>~/.bashrc</code> file.
Anyway, after messing around with it for a bit, I think it will make my command-line usage much more efficient. Hope this appeals to somebody else out there...
Offline
That is awesome! I will try when i get home
Offline
I also forgot, you can use Vi commands to skip to items from your history as well. If you view your history:
$ history
...
377 ps aux | grep firefox
378 sudo pacman -Syu
379 exit
380 startx
381 startx
382 sudo pacman -Syu
383 less /etc/ntp.conf
384 sudo vim /etc/pacman.conf
385 sudo pacman -Syu
...and say you want to run "<code>ps aux | grep firefox</code>", you can just type <code><ESCAPE></code> to enter command-editing mode, put in the line number you want: <code>377</code>, and then hit '<code>G</code>' to go there. There are all sorts of cool things I'm figuring out...
Offline
Other handy things you can do:
- Esc '/' text <Enter> to search back in your command history for text.
- 'n' to continue searching backward
- 'N' to search forward
And my favorite: once you have the command line you want through the above or with the "Esc linenumber 'G'" technique you can then either edit the line in-place or enter 'v' to invoke a full 'vi' session on that line - great for long multipart commands!
Offline
For zsh, the `vicmd` option does the same thing.
Offline
One question. Although I'm enjoying the vi style on the bash shell, I have become quite used to using "ctrl-L" to clear the screen. That only works in the vi shell if you are in command mode. If you are in insert mode, it simply prints "^L" to the screen. Is it possible to make ctrl-L clear the screen in insert mode?
I tried the following in my ~/.bashrc with no luck:
alias ^L='/usr/bin/clear'
Offline