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?

weisbrja
  • 121
  • 1
  • 10
  • Related: [How to make the zsh “correct” functionality remember my spell-correction decisions](https://unix.stackexchange.com/q/193552) – Devon Apr 19 '21 at 07:37

1 Answers1

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
Marlon Richert
  • 3,715
  • 5
  • 30