1

Why is my locale setting replaced when I run an external command with :!cmd ?

And which configurations should I check to find the cause of this problem? I've checked configs for my shell (zsh): .zshenv, .zshrc; my configs for neovim; my config for KDE. But I still don't understand why nvim seems to reset locale to en from en_GB

Within vim, running :!locale gives me this output:

locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en
LC_CTYPE="en"
LC_NUMERIC="en"
LC_TIME="en"
LC_COLLATE="en"
LC_MONETARY="en"
LC_MESSAGES="en"
LC_PAPER="en"
LC_NAME="en"
LC_ADDRESS="en"
LC_TELEPHONE="en"
LC_MEASUREMENT="en"
LC_IDENTIFICATION="en"
LC_ALL=

In zsh I get:

[I] ➜ locale
LANG=en_GB.utf8
LC_CTYPE="en_GB.utf8"
LC_NUMERIC="en_GB.utf8"
LC_TIME="en_GB.utf8"
LC_COLLATE="en_GB.utf8"
LC_MONETARY="en_GB.utf8"
LC_MESSAGES="en_GB.utf8"
LC_PAPER="en_GB.utf8"
LC_NAME="en_GB.utf8"
LC_ADDRESS="en_GB.utf8"
LC_TELEPHONE="en_GB.utf8"
LC_MEASUREMENT="en_GB.utf8"
LC_IDENTIFICATION="en_GB.utf8"
LC_ALL=

UPDATE.

Inside nvim: :!echo $SHELL gets "/bin/zsh", :set shell: "shell=/bin/zsh".

In .zprofile and in .zshenv there is nothing. In .zshrc no changes to locale, LANG.

UPDATE 2

The problem is with hledger not being invoked correctly (with 'en' locale).

3 Answers 3

3

I believe Vim should not modify your current locale except for LC_NUMERIC, LC_CTYPE and possibly LC_MESSAGES. The reason being, that LC_NUMERIC is needed for handling floating point numbers and LC_CTYPE is needed for handling character classes and similar things for multibyte characters.

You can query the output of the locale inside your vim using the :lang command. The difference to using the :!locale command is, that in the later form, this will be run through another shell layer (which may or may not change the locale in the initialization scripts).

However, I believe Vim only sets LC_CTYPE and LC_NUMERIC to a default of C which should always be available on a POSIX like system. (There was once a bug, that the locale has been reset by the time the gtk/gnome libraries have been initialized, but that has been fixed long ago, and this should not apply to neovim).

LC_MESSAGES, LC_CTYPE and LC_TIME can also be set using the :lang [messages|ctype|time] value command and can be queried using the v:lang (LC_MESSAGES), v:ctype (LC_CTYPE) and v:time (LC_TIME) internal variables.

1
  • Right, :lang outputs correct values (en_GB). Then it is some another shell layer. :!echo $SHELL outputs "zsh". I will update the question with my dotfiles
    – Artyom
    Commented Nov 28, 2019 at 14:49
0

Vim is probably running the external program under a non-login shell, and your configuration is setting the locale correctly only for login shells.

I have no experience with zsh, but under bash it would be checking if the locale is correctly set in ~/.bash_profile and not only on ~/.bashrc.

1
  • It is zsh. No changes to locale in dot files.
    – Artyom
    Commented Nov 28, 2019 at 14:55
0

Carefully read what is inside your vim configuration. It turned out I was setting let $LANG='en' in my vimrc in part I took from https://github.com/amix/vimrc/blob/master/vimrcs/basic.vim .

Your Answer

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

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