Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:38:20+00:00 2026-06-05T08:38:20+00:00

zsh forward-word acts a bit different from bash/emacs, and I’d like to change that.

  • 0

zsh forward-word acts a bit different from bash/emacs, and I’d like to change that.

Instead of description of all differences, let me just show you step by step behaviour of bash. I marked cursor as “^” symbol.

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

M-b

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

M-b

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

M-b

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

M-b

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

M-b

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

M-b

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

M-f

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

M-d

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

M-d

foo bar^-param --needed-param

M-d

foo bar^ --needed-param

This algorithm is both flexible for moving through words, removing parts of them for me. Also it’s in emacs, so I’m used to it. I’d like to see it in zsh too. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:38:21+00:00Added an answer on June 5, 2026 at 8:38 am

    I have this in my .zshrc for exactly that purpose:

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

    Edit: Ah, I remember what was missing in order to get everything working as I wanted to. I also overwrote forward-word-match by putting the following content into $ZDOTDIR/functions/forward-word-match (assuming your $ZDOTDIR/functions directory is in $fpath; otherwise put it into one or modify the $fpath array as well):

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like the change my zsh prompt style for every virtualenv instances that
I want to write a Zsh function that looks like: smartwatch [WATCH_FILE] [COMMAND_TO_RUN] [COMMAND_ARGS]
In zsh , how can I set up the line editor such that backward-kill-word
In zsh, I have a function called g which acts like this: with no
If (in zsh) I have an array that contains something like this: echo ${fsizes[@]}
I need to change the following Bash code to Zsh TODO_OPTIONS=--timeout --summary cd ()
I want to adjust zsh so that I can tab complete: myprog <tab> using
http://min.us/muKpIB16z Is that zsh? Could somebody share the PS1 code to everyone :P? Thank
I'm on OSX and want to switch back to my original zsh config from
I am usually using zsh, which provides the chpwd() hook. That is: If the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.