Skip to content

Fixing Word Navigation in ZSH

Tags: development, productivity • Categories: Learning

Table of Contents

Moving to zsh from bash has been a great quality of life improvement. However, there is one thing that has driven me nuts that I have not been able to figure out: customizing the word boundary definition.

I’m using zsh 5.9 and have a lot of plugins.

  • forward-word ,backward-word , and the kill variants were the main widgets that I use. I used bindkey to determine these functions.
  • After some investigation, it seems like these widgets are controlled via zstyle ':zle:*' configuration. You can dump configuration via zstyle -L
  • You can determine what underlying zsh function is used by a widget via zle -lL. If you want to view the source of a widget function use which
  • After some digging, I found select-word-style which seemed to be what I was looking for, but didn’t work.
  • After some grepping around I discovered word-style which solved the issue for me if I set it to unspecified. Based on the documentation, I shouldn’t need to do this, but this is what worked for me.
  • I looked into the autocomplete, syntax highlighter, and substring history plugins but removing them did not fix the issue.

Here’s my final configuration which fixed the issue for me:

WORDCHARS='*?_-.[]~=&;!#$%^(){}<>/ '$'\n'
autoload -Uz select-word-style
select-word-style normal
zstyle ':zle:*' word-style unspecified