xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

macOS Terminal vim UTF-8 bug All In One

macOS Terminal vim UTF-8 bug All In One

vim 中文乱码 bug / Raspberry Pi

Raspberry Pi .bashrc

$ sudo vim .bashrc 
$ cat .bashrc 
# fix: vim 无法显示 👻 emoji & 中文 bug
export LC_ALL="zh_CN.UTF-8"
echo "fix vim bug ✅"

# bash alias
alias vcmt='vcgencmd measure_temp'
$ vcmt
-bash: vcmt:未找到命令

$ source ~/.bashrc
fix vim bug ✅

$ vcmt
temp=51.5'C

errors

vim ❌

image

cat ✅

image

solutions ✅

更新 macOS 系统即可

macOS 12.1 ❌ => macOS 13.4

image

macOS 系统更新 bug

$ ls -al | grep ".vimrc"

$  cat .vimrc
set encoding=utf-8
set langmenu=zh_CN.UTF-8
language message zh_CN.UTF-8

$  rm -rf .vimrc
# raspberrypi
$ ssh pi@raspberrypi.local

pi@raspberrypi:~ $ cd Desktop/
pi@raspberrypi:~/Desktop $ cat ./stm32.py
#!/usr/bin/env python3
# coding: utf8
# 3V3 (17) BCM GPIO 供电不好使
$ vim ./stm32.py
$ ls -alth

image

image

Raspberry Pi 需要安装中文语言包

vim Unicode error (Chinese / Emoji)

$ cat SanDisk-64GB-TaiWan.md
SanDisk 64GB SD Card

emoji bug ✅
zh_CN bug 汉字
$ vim SanDisk-64GB-TaiWan.md

eric@rpi4b:~/Desktop $ vim SanDisk-64GB-TaiWan.md 
eric@rpi4b:~/Desktop $ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE=UTF-8
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=
eric@rpi4b:~/Desktop $ export LC_CTYPE="zh_CN.UTF-8"
-bash: warning: setlocale: LC_CTYPE: cannot change locale (zh_CN.UTF-8): No such file or directory
eric@rpi4b:~/Desktop $ export LC_ALL="zh_CN.UTF-8"
-bash: warning: setlocale: LC_ALL: cannot change locale (zh_CN.UTF-8): No such file or directory
eric@rpi4b:~/Desktop $ 

https://www.cnblogs.com/xgqfrms/p/17448587.html#5183832

solution ✅

需要手动开启 zh_CN

$ cat /etc/locale.gen | grep zh_CN
# zh_CN GB2312
# zh_CN.GB18030 GB18030
# zh_CN.GBK GBK
# zh_CN.UTF-8 UTF-8

$ sudo vim /etc/locale.gen
# 去掉注释 ✅
zh_CN.UTF-8 UTF-8

# 生成中文语言包 ✅
$ sudo locale-gen
Generating locales (this might take a while)...
  zh_CN.UTF-8... done
Generation complete.

$ locale
LANG=zh_CN.UTF-8
LANGUAGE="zh_CN.UTF-8"
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=zh_CN.UTF-8

How to fix Linux locale error All In One

如何修复 Linux 语言环境错误

# fix: vim 中文乱码 bug ✅
$ export LC_ALL="zh_CN.UTF-8"

https://www.cnblogs.com/xgqfrms/p/17448587.html

demos

not work at all ❌

$  cat ~/.vimrc
cat: /Users/xgqfrms-mbp/.vimrc: No such file or directory

$ vim ~/.vimrc
$  cat ~/.vimrc
set enc=utf8

$ vim ~/.vimrc
$ cat ~/.vimrc
set fileencodings=ucs-bom,utf-8,utf-16,gbk,big5,gb18030,latin1

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

VIM 文件编码识别与乱码处理

在 Vim 中,有四个编码有关的选项:fileencodings、fileencoding、encoding 和 termencoding

在实际使用中,任何一个选项出现错误,都会导致出现乱码
因此,每一个 Vim 用户都应该明确这四个选项的含义作用

set encoding=utf-8
set langmenu=zh_CN.UTF-8
language message zh_CN.UTF-8

https://edyfox.codecarver.org/html/vim_fileencodings_detection.html

refs

How to fix macOS Terminal UTF-8 encoding error ❌

https://www.cnblogs.com/xgqfrms/p/17434878.html#5180312



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-05-15 14:56  xgqfrms  阅读(30)  评论(9编辑  收藏  举报