当前位置: 首页 > 工具软件 > tmux-yank > 使用案例 >

[20150427]tmux与INPUTRC定义冲突.txt

岳允晨
2023-12-01

[20150427]tmux与INPUTRC定义冲突.txt

--我前一阵子发现在tmux里面一些按键与INPUTRC冲突.

我的/etc/inputrc定义如下:

"\e[1~": beginning-of-line    # home
"\e[2~": yank-last-arg        # insert
"\e[3~": delete-char          # delete
"\e[4~": end-of-line          # end
"\e[5~": backward-kill-word   # page up
"\e[6~": kill-word            # page down

#set bell-style visible
set bell-style none
set meta-flag On
set convert-meta Off
set input-meta on
set output-meta On
set horizontal-scroll-mode On
set show-all-if-ambiguous On

# (F1 .. F5) are "\e[[A" ... "\e[[E"
#"\e[[B":  "select * from v$system_event ;"  # F2

"\e[[A": backward-word                     # F1
"\e[[B": forward-word                      # F2

"\e[[C": backward-kill-line                # F3
"\e[[D": kill-line                         # F4

"\e[[E": yank                              # F5
"\e[17~": undo                              # F6

"\e[18~": history-search-forward            # F7
"\e[19~": history-search-backward           # F8

"\e[20~": character-search                  # F9
"\e[21~": character-search-backward         # F10

"\e[23~": "\eb'\ef'"                        # F11
"\e[24~": kill-whole-line                   # F12

"\e[5C": forward-word
"\e[5D": backward-word
"\e[1;5C": forward-word
"\e[1;5D": backward-word

--不过我发现在tmux下无法使用F1,F2,F3,F4.

--进入tmux后执行:
#  infocmp
#       Reconstructed via infocmp from file: /usr/share/terminfo/s/screen
screen|VT 100/ANSI X3.64 virtual terminal,
        am, km, mir, msgr, xenl,
        colors#8, cols#80, it#8, lines#24, ncv#3, pairs#64,
        acsc=++\,\,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l,
        clear=\E[H\E[J, cnorm=\E[34h\E[?25h, cr=^M,
        csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
        cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
        cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\EM,
        cvvis=\E[34l, dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM,
        dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K, enacs=\E(B\E)0,
        flash=\Eg, home=\E[H, ht=^I, hts=\EH, ich=\E[%p1%d@,
        il=\E[%p1%dL, il1=\E[L, ind=^J, is2=\E)0, kbs=^H, kcbt=\E[Z,
        kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
        kdch1=\E[3~, kend=\E[4~, kf1=\EOP, kf10=\E[21~,
        kf11=\E[23~, kf12=\E[24~, kf2=\EOQ, kf3=\EOR, kf4=\EOS,
        kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
        khome=\E[1~, kich1=\E[2~, kmous=\E[M, knp=\E[6~, kpp=\E[5~,
        nel=\EE, op=\E[39;49m, rc=\E8, rev=\E[7m, ri=\EM, rmacs=^O,
        rmcup=\E[?1049l, rmir=\E[4l, rmkx=\E[?1l\E>, rmso=\E[23m,
        rmul=\E[24m, rs2=\Ec\E[?1000l\E[?25h, sc=\E7,
        setab=\E[4%p1%dm, setaf=\E[3%p1%dm,
        sgr=\E[0%?%p6%t;1%;%?%p1%t;3%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;,
        sgr0=\E[m, smacs=^N, smcup=\E[?1049h, smir=\E[4h,
        smkx=\E[?1h\E=, smso=\E[3m, smul=\E[4m, tbc=\E[3g,

--才发现进入TERM不再是linux,而是变成了screen.这样一些按键的定义被重新修改.
--对比发现:
#  infocmp  screen linux | grep kf[123456]:
        kf1: '\EOP', '\E[[A'.
        kf2: '\EOQ', '\E[[B'.
        kf3: '\EOR', '\E[[C'.
        kf4: '\EOS', '\E[[D'.
        kf5: '\E[15~', '\E[[E'.

--可以发现F1,F2,F3,F4,F5的定义与原来不一致,这样导致无法使用.为此我建立新的inputrc文件.内容如下:
# cat /etc/tmux.inputrc
"\e[1~": beginning-of-line    # home
"\e[2~": yank-last-arg        # insert
"\e[3~": delete-char          # delete
"\e[4~": end-of-line          # end
"\e[5~": backward-kill-word   # page up
"\e[6~": kill-word            # page down

#set bell-style visible
set bell-style none
set meta-flag On
set convert-meta Off
set input-meta on
set output-meta On
set horizontal-scroll-mode On
set show-all-if-ambiguous On

# (F1 .. F5) are "\e[[A" ... "\e[[E"
#"\e[[B":  "select * from v$system_event ;"  # F2

"\eOP": backward-word                     # F1
"\eOQ": forward-word                      # F2

"\eOR": backward-kill-line                # F3
"\eOS": kill-line                         # F4

"\e[15~": yank                              # F5
"\e[17~": undo                              # F6

"\e[18~": history-search-forward            # F7
"\e[19~": history-search-backward           # F8

"\e[20~": character-search                  # F9
"\e[21~": character-search-backward         # F10

"\e[23~": "\eb'\ef'"                        # F11
"\e[24~": kill-whole-line                   # F12

--如何显示进入tmux是指定INPUTRC=/etc/tmux.inputrc呢? 很简单,修改.bashrc文件加入如下:

if [[ '' = "$TMUX" ]]
then
    export INPUTRC=/etc/inputrc
else
    export INPUTRC=/etc/tmux.inputrc
fi

--这样就可以正常实现功能键在两种模式下正常使用了.

 类似资料: