51

I freshly installed vim (Vi IMproved 8.1) as a text editor on my MacOS 10.14.5 with Homebrew. Each time that I run vim I get this error message:

Warning: Failed to set locale category LC_NUMERIC to en_CH.
Warning: Failed to set locale category LC_TIME to en_CH.
Warning: Failed to set locale category LC_COLLATE to en_CH.
Warning: Failed to set locale category LC_MONETARY to en_CH.
Warning: Failed to set locale category LC_MESSAGES to en_CH.

I have to click ENTER and it works but I would like to get rid of that error message.

I saw a similar message on that link

How can I get rid of this error message?

1
  • That's a recurrent problem also for me, having a German laptop and using an English layout. In my case was failing with en_DE. Exporting in .bash_profile/.zshrc as answered by @ecjb is the correct solution 👍 Jan 16, 2020 at 20:55

6 Answers 6

109

First, access your .bash_profile file by typing the following (using vim as text editor):

vim ~/.bash_profile

Inside the file .bash_profile, insert the following line:

export LC_ALL=en_US.UTF-8

Note, however, that newer versions of macOS ship with zsh instead of bash as the default shell. If this is the case with your Mac, you will have to edit ~/.zshrc instead of ~/.bash_profile.

Restart the Terminal or source ~/.zshrc or source ~/.bash_profile and launch vim again: the error message should have disappeared.

Thanks @geoyws - George Yong and pkropachev Pavel Kropachev for their answer found there, thanks @bk2204 for the hints in the other answer

2
  • For UK you can also use export LC_ALL=en_GB.UTF-8 Aug 28, 2019 at 8:08
  • Thanks, it helped me to fix gtypist, but I used export instead LC_ALL=en_US
    – Martiuh
    Mar 7, 2021 at 0:29
21

In Short: your macOS/Unix/Linux doesn't have the default configuration of locales and you should connect it when your bash restarted. Therefore the solution is to update config files and reload it (In my example the language would be English and the default encoding would be UTF-8):

If you use oh-my-zsh:

vim ~/.zshrc
export LC_ALL=en_US.UTF-8

If you use fish-shell:

vim ~/.config/fish/config.fish
set -x LC_ALL en_US.UTF-8

else (default):

vim ~/.bash_profile 
#OR (vim  ~/.bashrc) 
export LC_ALL=en_US.UTF-8
10

if you use zsh, you could

vim ~/.zshrc

and uncomment next line:

export LC_ALL=en_US.UTF-8
5

if you use fish, you could

vim ~/.config/fish/config.fish
set -x LC_ALL en_US.UTF-8
1
  • 2
    I use fish shell, and this saved me.
    – vikbert
    Sep 10, 2019 at 19:30
4

Somehow your locale is set to "en_CH". This locale is for English as spoken in Switzerland, but on your system, that isn't a valid locale. Generally, locales also contain a character set to use, such as the "UTF-8" in "en_US.UTF-8", which is also absent here.

It's likely that something in your shell configuration is setting these values, because macOS typically does not set these specific values; instead, it sets the LANG environment variable, and it always uses UTF-8 locales. You should check either your .bashrc and .bash_profile settings or possibly your .zshenv, .zshrc, and .zprofile settings and change any LANG, LC_ALL, or other LC_* variable you may have set.

As a note, I'm not aware of any system that has an en_CH locale; typically there will only be locales for languages that are commonly spoken in the country or region (often, but not always, official languages). For example, while there are certainly many speakers of French in the United States, systems typically do not provide an fr_US.UTF-8 locale, because there are not enough speakers to have established norms for localization. You may need to pick another English locale, such as "en_GB.UTF-8" or "en_US.UTF-8" that is close enough for your needs, or set individual "LC" variables depending on which settings you want to pick and chooise.

3
  • Many thanks for your answer @bk2204. So I tried to implement to use the informations in your answer but could not solve the problem. I updated the question accordingly. Do you have any other idea?
    – ecjb
    Jun 23, 2019 at 13:46
  • You can try finding the place the environment variable is set by looking at this answer and changing it accordingly.
    – bk2204
    Jun 23, 2019 at 17:09
  • Just to clarify, re: "typically there will only be locales for languages that are commonly spoken in the country or region": in macOS (and I reckon Windows too), you can set the system language to English and the region (for things like date & number formatting) to something completely unrelated. It seem macOS then sets the locale using both those things. For instance, my system language is English, my region is Brazil and my LC ends up being en_BR... Which also doesn't exist officially.
    – rafasoares
    Mar 2, 2020 at 21:51
0

Alternatively if you can't create your specific locale (e.g. with rootless MacOS*) set an already installed locale.

vim ~/.bash_profile
export LC_ALL=C

I found that the locale C was available on all systems I accessed, including ones via SSH. You can list available locales via locale -a.

*And don't want to go the route of messing with SIP

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.