Bash Vi Command Line Editing Mode
catonmat.net
catonmat.net
set editing-mode vi
in .inputrc will enable it everywhere.http://www.opengroup.org/onlinepubs/000095399/utilities/sh.h...
Interesting note about emacs mode though:
In early proposals, the KornShell-derived emacs mode of command line editing was included, even though the emacs editor itself was not. The community of emacs proponents was adamant that the full emacs editor not be standardized because they were concerned that an attempt to standardize this very powerful environment would encourage vendors to ship strictly conforming versions lacking the extensibility required by the community. The author of the original emacs program also expressed his desire to omit the program. Furthermore, there were a number of historical systems that did not include emacs, or included it without supporting it, but there were very few that did not include and support vi. The shell emacs command line editing mode was finally omitted because it became apparent that the KornShell version and the editor being distributed with the GNU system had diverged in some respects. The author of emacs requested that the POSIX emacs mode either be deleted or have a significant number of unspecified conditions. Although the KornShell author agreed to consider changes to bring the shell into alignment, the standard developers decided to defer specification at that time. At the time, it was assumed that convergence on an acceptable definition would occur for a subsequent draft, but that has not happened, and there appears to be no impetus to do so. In any case, implementations are free to offer additional command line editing modes based on the exact models of editors their users are most comfortable with.
#It starts in insert mode
export VIMODE=INS
function zle-keymap-select {
VIMODE="${${KEYMAP/vicmd/CMD}/(main|viins)/INS}"
zle reset-prompt
}
zle -N zle-keymap-select
bindkey -v
I use Oh My Zsh, but as far as I know this should work without it too.Wish HN had a notify-on-reply system like Reddit's orangered. Would you see this? Would you not? Would I miss eternal gratefulness from a fellow HN citizen? Oh, how I wish I knew the answer!
I've been using Vim as my primary editor/IDE for three years now, and I still can't get used to vi mode on the command line, and keep going back to emacs mode because it functions exactly like you would expect it to.
In bash type Ctrl-x-e
In zsh I press Ctrl-z, which does what I want because I have this in my .zshrc:
setopt hist_ignore_space # trick so that history doesn't get polluted
function edithist() {
local tmp=${TMPPREFIX}${$}hist
read -Erz >| "$tmp"
"$EDITOR" "$tmp"
print -Rz - "$(<$tmp)"
rm "$tmp"
}
bindkey -e '\M-q' push-input # replaces push-line in 3.0.x
bindkey -e -s '\C-z' '\M-q edithist\n'
The zsh version leaves you editing the command line after exiting the editor. The bash version executes the command after exiting the editor.However, some months ago I started to work in an environment full of Solaris 8 machines with ksh as their default shell in vi mode for some reason. It's configured that way for every machine and we have to constantly log in and out of them to do our jobs, and it's always been that way so I simply didn't ask for it to change. After all I was also the new guy.
After a few weeks I got so tired of trying to use emacs commands in vi mode shells while at work, and vi commands while in emacs mode at home that I changed to vi mode at home. And I've been happy since then. It's not that hard. You get used to it quickly, especially if you use vi or Vim a lot like I do.