3

How do I tell zsh to correct simple spelling mistakes automatically?

For example: I want lsbkl to automatically be corrected to lsblk, after hitting Enter, without showing zsh: correct 'lsbkl' to 'lsblk' [nyae]?.

Is this possible to achieve?

1

1 Answer 1

3

This will autocorrect the word to the left of the cursor whenever you press Space or Enter:

autocorrect() {
  zle .spell-word
  zle .$WIDGET
}
zle -N accept-line autocorrect
zle -N magic-space autocorrect
bindkey ' ' magic-space
3
  • I don't want to define the corrections by hand though.
    – weisbrja
    Commented Apr 20, 2021 at 8:11
  • @weisbrja I updated my answer with a solution that doesn't require manually defining corrections. Please have a look. Commented Apr 20, 2021 at 10:03
  • Thank you so much. That is literally perfect!
    – weisbrja
    Commented Apr 21, 2021 at 11:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .