13

I'm using zsh on Gentoo x64, and when I type sudo vim /path/to/file from my home folder, zsh asks:

zsh: correct 'vim' to '.vim' [nyae]?

I want to run vim not my .vim folder. How do I fix this?

My guess is that setopt autocd is causing this. Odd thing is, if I don't add sudo, zsh doesn't ask to correct anything.

2 Answers 2

16

OK, I got this. The problem isn't autocd, it's correctall. vim as a command (vim file) doesn't trigger any correction*, but vim in sudo vim is an argument, zsh sees that it's close to the name of a folder in the current directory, and asks if you want to change to that, as files and folders are more common arguments. So the solution is unsetopt correctall (or setopt nocorrectall). As illustration; note I have a .zsh folder:

% unsetopt correctall
% setopt autocd correct 
% vim zsh
% sudo vim zsh
% setopt correctall
% vim zsh
zsh: correct 'zsh' to '.zsh' [nyae]? 
% sudo vim zsh
zsh: correct 'zsh' to '.zsh' [nyae]? 
zsh: correct 'vim' to '.vim' [nyae]? 
%

*: Or shouldn't, I have had zsh ask if it should correct command to _command on a couple commands for some reason. Perhaps because it checks aliases and gives them higher priority.

1
  • Ah, that makes sense. I kinda like having correctall on, because I can't type, and I like how it'll correct ks to ls. Wonder if there's a way to change how zsh checks for "corrections".
    – gen_Eric
    Mar 18, 2012 at 3:13
8

try alias sudo='nocorrect sudo'.

1
  • 2
    nocorrect, eh? Does that just ignore corrections for just that command? I'll have to test this out later.
    – gen_Eric
    Oct 15, 2012 at 14:02

You must log in to answer this question.

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