9

How do you disable zsh autocorrect entirely?

I am aware of the 'nocorrect' option which only applies to certain commands. But I want it off entirely so that when I type 'lear' instead of 'clear', it won't prompt for a correction.

I should note that 'unsetopt correctall' doesn't seem to do anything for me

collin@mandalay ~
  % unsetopt correctall

collin@mandalay ~
  % lear
zsh: correct 'lear' to 'clear' [nyae]? n
zsh: command not found: lear

7 Answers 7

10

In your .zshrc file:

 #disable auto correct
 unsetopt correct_all

From the manpage of zsh (zshoptions):

   CORRECT (-0)
          Try to correct the spelling of commands.  Note that, when the HASH_LIST_ALL option is not set or when some directories in the  path  are  not readable, this may falsely report spelling errors the first time some commands are used.

   CORRECT_ALL (-O)
          Try to correct the spelling of all arguments in a line.

So the correct option will correct ONLY the commands not the arguments on the line.

The correct_all option will correct commands AND all the arguments on the line.

5
  • This is incorrect. correct_all will disable autocorrect for options only, not for commands themselves. See here for an example: yountlabs.com/automation/disable-autocorrect-in-zsh Commented Dec 7, 2012 at 18:30
  • I improved my answer (forgot to login while editing it).
    – Atropo
    Commented Dec 8, 2012 at 9:07
  • That isn't how it works for me. I am using zsh 4.3.17. See my initial post. 'unsetopt correctall' (correct_all and correctall are equivalent) then typing 'lear' instead of 'clear' results in the auto-correct prompt. Seems the name 'correct_all'is misleading. Based on the description it says "Try to correct the spelling of all arguments in a line' Commented Dec 10, 2012 at 4:09
  • @Collin, load order matters. It worked for me when I moved it to bottom, after oh-my-zsh
    – oma
    Commented Aug 26, 2013 at 19:06
  • I can confirm @CollinPeters experience. unsetopt correct_all, even as the last thing on the zshrc, doesn't get rid of that correction prompt. unsetopt correct does.
    – Sundar R
    Commented Jul 9, 2021 at 17:19
10

Only putting the following lines in .zshrc does not work for me.

unsetopt correct_all
unsetopt correct

It works after I commented out this line :

ENABLE_CORRECTION="true"

Hopes it work for you as well.

1
  • 1
    This should be the accepted answer
    – iFunction
    Commented Jan 8 at 13:36
7

Ahhhh!!... I see that I was supposed to use 'unsetopt correct' instead of correct_all

collin@mandalay ~
  % unsetopt correct

collin@mandalay ~
  % lear
zsh: command not found: lear
1
  • This is the only thing that worked for me on Manjaro. Commented Nov 26, 2021 at 2:20
0

Also, if you cannot modify your .zshrc or .zhsenv (I speak about the .zhsenv because some answers external to this post talk about modifying this file, although seeing the default comments in files it seems that .zshrc is the right one) :

you can modify your .zshrc.user . I put in it :

#Disable autocorrect
unsetopt correct_all
unsetopt correct
DISABLE_CORRECTION="true" 

This is probably redundant (the last line)

0

In the case that you happen to be using the grml configuration (and have somehow forgotten): add the following line to your .zshrc.pre or .zshrc.local:

NOCOR=1

The normal method is, as mentioned by others, to use a unsetopt correct_all and/or unsetopt correct - but this is overridden by the grml config.

0

On MacOS Monterey with zsh 5.8.1, commenting

# ENABLE_CORRECTION="true"
unsetopt correct_all
unsetopt correct

did not change the behaviour. Only worked when setting it to False explicitly:

ENABLE_CORRECTION="false"
unsetopt correct_all
unsetopt correct

Also, do not forget to source file afterwards source ~/.zshrc

0

There's a variable ENABLE_CORRECTION in ~/.oh-my-zsh/lib/correction.zsh.

What helped me was setting this variable to "false" (or anything != "true") before sourcing "oh-my-zsh" in ~/.zshrc:

export ENABLE_CORRECTION="false"
source $ZSH/oh-my-zsh.sh

Also - many answers here recommend to set ENABLE_CORRECTION or DISABLE_CORRECTION without "export". That wouldn't work. Variable must be exported in order for other shell scripts to "see" it unless it's used in the same script only.

You must log in to answer this question.

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