在 zsh 中使用来自旧 .inputrc 的自定义命令?

Tyr*_*rop 6 zsh

.inputrc当我使用 bash 时,我曾经有这个,但它在 ZSH 中不起作用,因为 ZSH 不读取 .inputrc (AFAIK):

$if Bash
  # Meta+O can be made to load the previous 
  # command and position the cursor for typing an option
  "\eo": "\C-p\C-a\ef "
Run Code Online (Sandbox Code Playgroud)

这是我在 bash 时代最怀念的一件事。有没有办法将此命令移植到 ZSH?我尝试了一些绑定键恶作剧,但收效甚微。

pet*_*eth 12

没错,zsh它有自己的行编辑器 ( ZLE) 而不会读取readline's .inputrc

尝试:

# define widget function
function cursor-after-first-word {
    zle up-history
    zle beginning-of-line
    zle forward-word
    RBUFFER=" $RBUFFER"
}

# create widget from function
zle -N cursor-after-first-word

# bind widget to ESC-o
bindkey '^[o' cursor-after-first-word
Run Code Online (Sandbox Code Playgroud)

看看man zshzle还有什么可能。

  • 使用 `emacs-forward-word` 而不是 `forward-word` 会更好地匹配 `forward-word` 在 *bash*(和 Emacs)中的工作方式。或者提问者可能想重新定义 Mf 并使用直接翻译:`bindkey '^[f' emacs-forward-word; bindkey -s '^[o' '^p^a^[f '` (3认同)