From 57811dec95dba83fa9ed50e32bdad138dd586720 Mon Sep 17 00:00:00 2001 From: Floris van Liere Date: Sat, 7 Mar 2015 14:06:37 +0100 Subject: [PATCH] set_init_1: mb_init() on fallback encoding (utf8) #2106 Explanation: Running `:set encoding=utf-8` _after_ startup correctly initializes multibyte; but mb_init() was _not_ called during startup if locale detection (enc_locale()) failed. This wasn't a problem in Vim because the Vim default encoding (latin1) does not require mb_init(). But Nvim defaults to utf8, so mb_init() is required. closes #1271 closes #1672 --- src/nvim/option.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nvim/option.c b/src/nvim/option.c index 9571398ed1..3d596f81cc 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1989,7 +1989,7 @@ void set_init_1(void) char_u *save_enc; /* Try setting 'encoding' and check if the value is valid. - * If not, go back to the default "latin1". */ + * If not, go back to the default "utf-8". */ save_enc = p_enc; p_enc = p; if (STRCMP(p_enc, "gb18030") == 0) { @@ -2029,8 +2029,13 @@ void set_init_1(void) } else { free(p_enc); + // mb_init() failed; fallback to utf8 and try again. p_enc = save_enc; + mb_init(); } + } else { + // enc_locale() failed; initialize the default (utf8). + mb_init(); } /* Set the default for 'helplang'. */