Skip to content

ZSH widget: Add partial word accept (Ctrl+Right) #85

@noahgift

Description

@noahgift

Feature Request

Add ability to accept just the next word of a suggestion, not the entire thing.

Current Behavior

Suggestion: git commit -m "fix bug"
Buffer: git

Pressing Tab/Right accepts entire suggestion → git commit -m "fix bug"

Desired Behavior

  • Tab / Right arrow: Accept full suggestion (current)
  • Ctrl+Right: Accept next word only

Example:

  1. Buffer: git | Suggestion: commit -m "fix bug"
  2. Press Ctrl+Right → Buffer: git commit | Suggestion: -m "fix bug"
  3. Press Ctrl+Right → Buffer: git commit -m | Suggestion: "fix bug"

Implementation

_aprender_accept_word() {
    if [[ -n "$POSTDISPLAY" ]]; then
        local suggestion="${POSTDISPLAY# }"
        local next_word="${suggestion%% *}"
        
        BUFFER="${BUFFER}${next_word} "
        CURSOR=${#BUFFER}
        
        # Update POSTDISPLAY with remainder
        local remainder="${suggestion#$next_word}"
        remainder="${remainder# }"
        if [[ -n "$remainder" ]]; then
            POSTDISPLAY=" $remainder"
            region_highlight=("${#BUFFER} $((${#BUFFER} + ${#POSTDISPLAY})) fg=8")
        else
            POSTDISPLAY=""
            region_highlight=()
        fi
        zle redisplay
    else
        zle forward-word
    fi
}

zle -N _aprender_accept_word
bindkey '^[[1;5C' _aprender_accept_word  # Ctrl+Right

Prior Art

  • Fish shell: Alt+Right accepts next word
  • zsh-autosuggestions: Ctrl+Right for partial accept
  • GitHub Copilot CLI: Word-by-word accept

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions