Skip to content

Commit f883d90

Browse files
k-takatabrammool
authored andcommitted
patch 8.2.2912: MS-Windows: most users expect using Unicode
Problem: MS-Windows: most users expect using Unicode. Solution: Default 'encoding' to utf-8 on MS-Windows. (Ken Takata, closes #3907)
1 parent e71c0eb commit f883d90

6 files changed

Lines changed: 19 additions & 5 deletions

File tree

runtime/doc/options.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2828,7 +2828,8 @@ A jump table for the options with a short description can be found at |Q_op|.
28282828
|setcellwidths()| function to change the behavior.
28292829

28302830
*'encoding'* *'enc'* *E543*
2831-
'encoding' 'enc' string (default: "latin1" or value from $LANG)
2831+
'encoding' 'enc' string (default for MS-Windows: "utf-8",
2832+
otherwise: value from $LANG or "latin1")
28322833
global
28332834
Sets the character encoding used inside Vim. It applies to text in
28342835
the buffers, registers, Strings in expressions, text stored in the

src/mbyte.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4456,7 +4456,7 @@ enc_canonize(char_u *enc)
44564456
// Use the default encoding as it's found by set_init_1().
44574457
r = get_encoding_default();
44584458
if (r == NULL)
4459-
r = (char_u *)"latin1";
4459+
r = (char_u *)ENC_DFLT;
44604460
return vim_strsave(r);
44614461
}
44624462

src/option.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,21 @@ set_init_1(int clean_arg)
430430
# endif
431431
# endif
432432

433+
# ifdef MSWIN
434+
// MS-Windows has builtin support for conversion to and from Unicode, using
435+
// "utf-8" for 'encoding' should work best for most users.
436+
p = vim_strsave((char_u *)ENC_DFLT);
437+
# else
433438
// enc_locale() will try to find the encoding of the current locale.
439+
// This works best for properly configured systems, old and new.
434440
p = enc_locale();
441+
# endif
435442
if (p != NULL)
436443
{
437444
char_u *save_enc;
438445

439446
// Try setting 'encoding' and check if the value is valid.
440-
// If not, go back to the default "latin1".
447+
// If not, go back to the default encoding.
441448
save_enc = p_enc;
442449
p_enc = p;
443450
if (STRCMP(p_enc, "gb18030") == 0)

src/option.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ typedef enum {
127127
#define ENC_UCSBOM "ucs-bom" // check for BOM at start of file
128128

129129
// default value for 'encoding'
130-
#define ENC_DFLT "latin1"
130+
#ifdef MSWIN
131+
# define ENC_DFLT "utf-8"
132+
#else
133+
# define ENC_DFLT "latin1"
134+
#endif
131135

132136
// end-of-line style
133137
#define EOL_UNKNOWN -1 // not defined yet

src/testdir/test_writefile.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ func Test_write_file_encoding()
501501
CheckMSWindows
502502
let save_encoding = &encoding
503503
let save_fileencodings = &fileencodings
504-
set encoding& fileencodings&
504+
set encoding=latin1 fileencodings&
505505
let text =<< trim END
506506
1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
507507
2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2912,
753755
/**/
754756
2911,
755757
/**/

0 commit comments

Comments
 (0)