Подтвердить что ты не робот

Как сделать поведение форвардного слова zsh таким же, как в bash/emacs

jsh forward-word немного отличается от bash/emacs, и я хотел бы изменить это.

Вместо описания всех различий позвольте мне просто показать вам пошаговое поведение bash. Я обозначил курсор как символ "^".

foo bar --non-needed-param --needed-param^

М-Ь

foo bar --non-needed-param --needed-^param

М-Ь

foo bar --non-needed-param --^needed-param

М-Ь

foo bar --non-needed-^param --needed-param

М-Ь

foo bar --non-^needed-param --needed-param

М-Ь

foo bar --^non-needed-param --needed-param

М-Ь

foo ^bar --non-needed-param --needed-param

М-ф

foo bar^ --non-needed-param --needed-param

М-д

foo bar^-needed-param --needed-param

М-д

foo bar^-param --needed-param

М-д

foo bar^ --needed-param

Этот алгоритм является гибким для перемещения по словам, удаляя части из них для меня. Также это в emacs, поэтому я привык к этому. Я бы тоже хотел увидеть это в zsh. Спасибо.

4b9b3361

Ответ 1

У меня это в моем .zshrc для этой цели:

# Bash-like navigation
autoload -U select-word-style
select-word-style bash

Изменить: Ах, я помню, чего не хватало, чтобы все работало так, как я хотел. Я также перезаписал forward-word-match, поместив следующий контент в $ZDOTDIR/functions/forward-word-match (предполагая, что ваш каталог $ZDOTDIR/functions находится в $fpath, иначе поместите его в один или измените массив $fpath):

emulate -L zsh
setopt extendedglob

autoload match-words-by-style

local curcontext=":zle:$WIDGET" word
local -a matched_words
integer count=${NUMERIC:-1}

if (( count < 0 )); then
    (( NUMERIC = -count ))
    zle ${WIDGET/forward/backward}
    return
fi

while (( count-- )); do

    match-words-by-style

    # For some reason forward-word doesn't work like the other word
    # commands; it skips whitespace only after any matched word
    # characters.

    if [[ -n $matched_words[4] ]]; then
        # just skip the whitespace and the following word
  word=$matched_words[4]$matched_words[5]
    else
        # skip the word but not the trailing whitespace
  word=$matched_words[5]
    fi

    if [[ -n $word ]]; then
  (( CURSOR += ${#word} ))
    else
  return 1
    fi
done

return 0