使用 .tmux.conf 配置打开 tmux 时出现问题

Problem in opening tmux with .tmux.conf configuration

我在学习 tmux 时向我的主目录添加了一个 .tmux.conf 配置文件,它开始显示类似

的内容
/home/ghost/.tmux.conf:5: unknown command:

我的 .tmux.conf 文件:

# Send Prefix
set-option -g prefix C-a
unbind-key C-a
bind-key C-a send-prefix

# Use Alt-arrow keys to switch panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Shift arrow to switch windows
bind -n S-Left previous-window
bind -n S-Right next-window

# Mouse mode
setw -g mouse on

# Set easier window split keys
bind-key v split-window -h
bind-key h split-window -v

# Easy config reload
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded."

根据互联网上的一些可用解决方案,我使用了 cat -A .tmux.conf 并且它显示:

# Send Prefix^M$
set-option -g prefix C-a^M$
unbind-key C-a^M$
bind-key C-a send-prefix^M$
^M$
# Use Alt-arrow keys to switch panes^M$
bind -n M-Left select-pane -L^M$
bind -n M-Right select-pane -R^M$
bind -n M-Up select-pane -U^M$
bind -n M-Down select-pane -D^M$
^M$
# Shift arrow to switch windows^M$
bind -n S-Left previous-window^M$
bind -n S-Right next-window^M$
^M$
# Mouse mode^M$
setw -g mouse on^M$
^M$
# Set easier window split keys^M$
bind-key v split-window -h^M$
bind-key h split-window -v^M$
^M$
# Easy config reload^M$
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded."^M$

在 linux 的 Windows 子系统中,它还显示了与 ^M 字符相关的内容:

我附上我的 .vimrc 文件图片:

这可能是由于 ^M 字符,因为我是 linux、vim 和 tmux 的初学者,所以请指导我。

如果需要任何其他文件,请告诉我。

WSL 中的 Windows 主机和 Linux 是两个独立且基本上不兼容的系统,应该尽可能少地交互。 Linux 端的任何内容都应在 Linux 中使用 Linux 工具严格处理,Windows 端的任何内容均应在 Windows 中使用 Windows工具。

在这种情况下,您在 Windows 文本编辑器中从 Linux 一侧编辑文件,其效果是用 Windows 行结束符编写文件,CR+LF(由 cat -A 显示为 ^M$),而 Linux 工具通常需要不同的行结尾:LF(由 [= 显示13=] 作为 $).

您可以使用以下命令修复 Linux 中的行尾

$ dos2unix /home/ghost/.tmux.conf
$ dos2unix /home/ghost/.vimrc

你可以通过更好的卫生来防止进一步的错误:Windows 用于 Windows 东西的工具,Linux 用于 Linux 东西的工具.

将 WSL 视为第二台笔记本电脑、远程服务器或类似的东西,而不是一些花哨的 Windows 实用程序。