tags:

views:

15

answers:

1

One of my problems when creating a portable .vimrc is with locales. Let's say I always want to use English language for messages. Depending on OS and Vim version, the command needed may be lang messages en, lang messages en_US, lang messages English_US, etc. Now, I can do this:

try
  lang messages en
catch
  try
    lang messages en_US
  catch
    try
      lang messages English_US
    catch
      ...
    endtry
  endtry
endtry

but is there a simpler way?

+3  A: 

According to the vim help, you can use let $LANG="en", so at least the following works (note that --cmd is executed before vimrc):

vim --cmd 'let $LANG="en"'

, but this produces the following error:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "",
        LC_ALL = (unset),
        LANG = "en"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

, so this works only for english language (since C locale is english).

You can also use execute:

for s:lang in ["en", "en_US", "en_US.UTF-8", "English_US"]
    try
        execute 'language messages '.s:lang
        break
    catch /^Vim(language):E197:/
        " Do nothing
    endtry
endfor
unlet s:lang
ZyX
I like this clever use of `break`!
Benoit