The linux terminal can display Chinese, but cannot input Chinese.

The linux terminal can display Chinese, but cannot input Chinese.

First of all, the terminal can display Chinese, which means that the system has a Chinese language pack. The methods of installing the Chinese language pack and setting the default language on the Internet will not work on such a system. Next, try this method, which is very simple.

The first method: modify the .inputrc file in the user directory to allow 8bit input

Yes, the solution is to modify the .inputrc file in the user directory to allow 8bit input

The inputrc file handles keymaps for specific cases, and this file is used as a startup file by Readline, the input-related library used by Bash and most other shells.
Most people don't need a custom keymap, so modify or create a global /etc/inputrc file that applies to all logged in users. If you need to override the default settings for a user, you can create an .inputrc file in the user's home directory that contains the custom keymap.

There may be no .inputrc file in the current user directory, if not, create a new one

root@orangepi:~# vim .inputrc 

set meta-flag on
set convert-meta off
set input-meta on
set output-meta on

Add the above four lines to the .inputrc file.
I don't know why it source .inputrcdoesn't work here, but it doesn't matter. Reopen a terminal and you will find that you can enter Chinese happily.

Second method (deprecated)

As a quick note, the following command will create a global /etc/inputrc file that applies to all logged in users, but this is generally not recommended: the following is
a basic global inputrc file, and comments for those options are also included in the file. Note that comments cannot be placed on the same line as commands .

cat > /etc/inputrc << "EOF"
# 开始 /etc/inputrc

# 允许命令行提示符转到下一行
set horizontal-scroll-mode Off

# 允许 8bit 输入
set meta-flag On
set input-meta On

# 禁止第8位(最高位)剔除
set convert-meta Off

# 允许显示第8位(最高位)
set output-meta On

# bell-style的取值范围是:none, visible, audible
set bell-style none

#####################################################################
# 下面将包含在第一个参数中的转义序列值映射到 readline 的特定功能

"/eOd": backward-word
"/eOc": forward-word

# for linux console
"/e[1~": beginning-of-line
"/e[4~": end-of-line
"/e[5~": beginning-of-history
"/e[6~": end-of-history
"/e[3~": delete-char
"/e[2~": quoted-insert

# for xterm
"/eOH": beginning-of-line
"/eOF": end-of-line

# for Konsole
"/e[H": beginning-of-line
"/e[F": end-of-line

# 结束 /etc/inputrc
EOF

Set meta-flagon to allow Chinese input from the terminal, otherwise the terminal will filter out the highest bit of each byte;
convert-meta off is set not to convert Chinese characters into escape sequences, because Chinese is represented by two bytes, and the highest bit of the first byte starts with 1, which may be the same as an escape character; output-meta on allows direct output of Chinese to the terminal; input-meta on allows direct input of Chinese to the terminal; set completion-ignore-case on can be set in e When cho A is pressed, readline can fill it out
for
you
;

Summarize

Of course, it is also possible to modify the global /etc/inputrc file that applies to all logged-in users, but this is generally not recommended.

For more information on how to edit the inputrc file, run info bash to see the Readline Init File section of bash's info page, or run info readline to see readline's own info page.

As for source .inputrcwhy it doesn't work, or if there is any solution, if anyone knows, please leave a message and let me know, thank you in advance.

Guess you like

Origin blog.csdn.net/Running_free/article/details/103886283