1

For some reason, I can't get the keybinding to invoke Vim (my editor) to work with Esc+v zsh when using iTerm.

I've gone back to a minimalist .zshrc file, to ensure it's not a plugin issue:

# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:/Users/user/go/bin:$PATH

export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/kubebuilder/bin

export EDITOR="/usr/bin/vi"

# Path to your oh-my-zsh installation.
export ZSH="/Users/user/.oh-my-zsh"

ZSH_THEME="gnzh"

source $ZSH/oh-my-zsh.sh

set -o vi

But when on the command line, I can't seem to use Esc+v to open the editor and I'm not sure why.

If I change my shell to bash, it works fine so it seems to be an issue with zsh.

Have also tried bindkey -v to no avail.

| improve this question | | | | |
  • Esc+V starts a sort of visual highlight mode (similar to how the same key sequence works in Vim). Press y to yank and then p to paste. Or d to delete etc. – Kusalananda Dec 4 '19 at 18:45
4

Directly copy-pasted from the zshcontrib(1) manpage (or info zsh edit-command-line):

autoload edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
| improve this answer | | | | |
2

I can't seem to use Esc + v to open the editor and I'm not sure why.

It's because the GNU Readline edit-and-execute-command function is a Bourne Again shell thing, not a Z shell thing. ZLE has no such thing. (The editline library used by the Almquist shell on FreeBSD has something similar but not identical. It is vi-histedit. So does the FreeBSD '93 Korn shell. As does the Watanabe shell with its vi-edit-and-accept, which is subtly different yet again. But the FreeBSD PD Korn shell does not have any such thing, in contrast. Neither does the Debian Almquist shell.)

You are mistakenly thinking that something that exists in one shell is a universal. It's not. This is the area that very much does vary from shell to shell. ZLE, GNU Readline, Editline, the Watanabe shell, and the '93 Korn shell are all different when it comes to command-line editing.

| improve this answer | | | | |
  • 1
    OpenBSD ksh (PD korn) has this feature. I'd be surprised if it can't be mimicked by zsh. – Kusalananda Dec 4 '19 at 20:10
  • dash supports it if built with --with-libedit. It's not built with a line editor by default on Debian as it is not really meant to be used interactively. – Stéphane Chazelas Dec 5 '19 at 8:00
  • zsh 1.0 was using readline. zle introduced in 2.0 (1991) was initially modeled after tcsh's editor which doesn't have it either. zle's been fully programmable since the late 90s though, so it's trivial to add it as a custom widget. One was added as contrib function in 2000. – Stéphane Chazelas Dec 5 '19 at 9:39
  • ksh's line editor is based on the one written by Pat Sullivan for the Bourne shell earlier. As can be seen in the ksh86 source code, that v command was an extension introduced by ksh. – Stéphane Chazelas Dec 5 '19 at 9:45
  • Note that the vi mode of sh is specified by POSIX and it includes that v command (required to invoke vi), though the line-editor is an optional feature, so it's not completely unreasonable to expect it from a shell that has a sh mode like zsh. – Stéphane Chazelas Dec 5 '19 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.