[20150427]tmux與INPUTRC定義衝突.txt

lfree發表於2015-04-28

[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

--這樣就可以正常實現功能鍵在兩種模式下正常使用了.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1608203/,如需轉載,請註明出處,否則將追究法律責任。

相關文章