]> granicus.if.org Git - vim/commitdiff
patch 8.2.2912: MS-Windows: most users expect using Unicode v8.2.2912
authorK.Takata <kentkt@csc.jp>
Sun, 30 May 2021 16:04:19 +0000 (18:04 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 30 May 2021 16:04:19 +0000 (18:04 +0200)
Problem:    MS-Windows: most users expect using Unicode.
Solution:   Default 'encoding' to utf-8 on MS-Windows. (Ken Takata,
            closes #3907)

runtime/doc/options.txt
src/mbyte.c
src/option.c
src/option.h
src/testdir/test_writefile.vim
src/version.c

index 4fbc014d32345bdb5412fb588817952cfd871f06..2f69049fcf922a777edb667ef37dde4c07d6fc74 100644 (file)
@@ -2828,7 +2828,8 @@ A jump table for the options with a short description can be found at |Q_op|.
        |setcellwidths()| function to change the behavior.
 
                                        *'encoding'* *'enc'* *E543*
-'encoding' 'enc'       string (default: "latin1" or value from $LANG)
+'encoding' 'enc'       string (default for MS-Windows: "utf-8",
+                               otherwise: value from $LANG or "latin1")
                        global
        Sets the character encoding used inside Vim.  It applies to text in
        the buffers, registers, Strings in expressions, text stored in the
index e3d64ba01b511e42ec438e6f7083a69b3f1d4038..f3fdc32e8e83c8be40ecc6446e84d20d7f095921 100644 (file)
@@ -4456,7 +4456,7 @@ enc_canonize(char_u *enc)
        // Use the default encoding as it's found by set_init_1().
        r = get_encoding_default();
        if (r == NULL)
-           r = (char_u *)"latin1";
+           r = (char_u *)ENC_DFLT;
        return vim_strsave(r);
     }
 
index 7c783757b2d4a1d05b138d4c5d97d47d0980c521..6ca424e12ea5019bfcfa31dc29d92b88b6e96319 100644 (file)
@@ -430,14 +430,21 @@ set_init_1(int clean_arg)
 #  endif
 # endif
 
+# ifdef MSWIN
+    // MS-Windows has builtin support for conversion to and from Unicode, using
+    // "utf-8" for 'encoding' should work best for most users.
+    p = vim_strsave((char_u *)ENC_DFLT);
+# else
     // enc_locale() will try to find the encoding of the current locale.
+    // This works best for properly configured systems, old and new.
     p = enc_locale();
+# endif
     if (p != NULL)
     {
        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 encoding.
        save_enc = p_enc;
        p_enc = p;
        if (STRCMP(p_enc, "gb18030") == 0)
index 30053cc6c27c8e12f44a4da1954feb4a6c13d3e9..7be729a85a1e077aceccc0227215a727fc8a6e73 100644 (file)
@@ -127,7 +127,11 @@ typedef enum {
 #define ENC_UCSBOM     "ucs-bom"       // check for BOM at start of file
 
 // default value for 'encoding'
-#define ENC_DFLT       "latin1"
+#ifdef MSWIN
+# define ENC_DFLT      "utf-8"
+#else
+# define ENC_DFLT      "latin1"
+#endif
 
 // end-of-line style
 #define EOL_UNKNOWN    -1      // not defined yet
index e94071fd7defb9f7e99c14d1909c234a84e1df93..9200f2b4b8dcc77fd7e3da255384a75b7932896e 100644 (file)
@@ -501,7 +501,7 @@ func Test_write_file_encoding()
   CheckMSWindows
   let save_encoding = &encoding
   let save_fileencodings = &fileencodings
-  set encoding& fileencodings&
+  set encoding=latin1 fileencodings&
   let text =<< trim END
     1 utf-8 text: Для Vim version 6.2.  Последнее изменение: 1970 Jan 01
     2 cp1251 text: Äëÿ Vim version 6.2.  Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
index 0a82a96f672389f55e06d746c4da432da7ff8120..d651bdaf2fd9c4af349ec6cba5ff5c7903a63f51 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2912,
 /**/
     2911,
 /**/