【问题标题】:Cannot get Control Arrow keys working in Vim through tmux无法通过 tmux 使控制箭头键在 Vim 中工作
【发布时间】:2016-11-03 03:33:03
【问题描述】:

我已经尝试解决这个问题两周了,但没有运气。

我在 OSX 上使用 Iterm2,使用 tmux 作为会话管理器。我在.vimrc 中有以下两个绑定的 VIM 设置

"_____Easy change tab left and right____
 nnoremap <C-Left> :tabprevious<CR>
 nnoremap <C-Right> :tabnext<CR>
 nnoremap <C-h> :tabprevious<CR>
 nnoremap <C-l> :tabnext<CR>

现在奇怪的部分是 ctrl h 和 l 快捷键完美地工作,而左箭头显示。

E349: No identifier under cursor

这似乎与应该发生的事情无关(它在 TMUX 之外完美运行!),但使用 :map 检查我的映射不会显示任何冲突的映射。但我就是想不通。任何帮助都将不胜感激。下面是我的 tux.conf 文件。由于这在 tmux 之外完美工作,我不相信 vimrc 应该与此有任何关系。

我感觉它的 Iterm2 向终端发送了奇怪的东西,而 tmux 误解了它们,但我不知道如何解决它。

tmux.conf

#set -g default-terminal "xterm-256color"
set -sg escape-time 0

# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

# split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

# reload config file (change file location to your the tmux.conf you want to use)
bind r source-file ~/.tmux.conf

# switch panes using Alt-arrow without prefix
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

# Enable mouse mode (tmux 2.1 and above)
set -g mouse on

# don't rename windows automatically
set-option -g allow-rename off

# Use Alt-arrow keys without prefix key to switch panes
bind -n M-S-Left previous-window
bind -n M-S-Right next-window

# Dont clear screen after other program is on
set-window-option -g alternate-screen on
#set-window-option -g xterm-keys on

【问题讨论】:

    标签: macos vim terminal tmux


    【解决方案1】:

    如果您取消注释这些行:

    #set -g default-terminal "xterm-256color"
    #set-window-option -g xterm-keys on
    

    那么tmux

    • TERM 环境变量设置为定义这些键的终端描述,并且
    • 发送 vim 期望的 xterm 样式控制箭头键。

    如果没有这两个更改,TERM 将设置为 screen(未定义键),tmux 将为控制箭头键发送不同的序列(恰好不在 任一终端描述)。

    【讨论】:

    • 非常感谢您,这非常有效!我想在弄乱它时,我已经分别而不是同时尝试了这两个选项。解释也很简洁明了!
    【解决方案2】:

    一个相关的问题是您无法在 OSX 终端使用 tmux 中的元箭头键调整窗格大小。解决方案是选择“使用选项作为元键”并删除键盘部分中与选项箭头对应的行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 2020-05-25
      • 1970-01-01
      • 2020-02-08
      • 1970-01-01
      相关资源
      最近更新 更多