刪除鍵在命令行上不起作用
*注意:我在 SuperUser 上問過同樣的問題,但沒有得到任何回應。我現在意識到這是一個更適合這個特定問題的論壇。
在 ksh shell 中, Delete 鍵在命令行上**無法正常工作。**當我按 Delete 時,我得到一個 ~。
我如何:
- *將“刪除游標處的字元”*的功能綁定 到刪除鍵盤按鈕?(Control-D 的行為就像我希望刪除按鈕能夠工作一樣,而我嘗試使用別名的嘗試沒有成功,而且很可能是幼稚的。)
- *將“移動到第一行”*的功能綁定到首頁鍵盤按鈕?(控制 A 現在執行此操作,但我希望 Home 執行此操作。)
- 將“移至行尾”的功能綁定到結束鍵盤按鈕?(Control E 現在執行此操作,但我希望 end 執行此操作。)
最終(?)更新
我偶然發現了一些有用的東西,但我不明白為什麼。這有效:
bind '^[[3'=prefix-2 bind '^[[3~'=delete-char-forward
根據http://www.qnx.com/developers/docs/6.3.2/neutrino/utilities/k/ksh.html#bind,
prefix-2 Key binding: ^X, ^[[ Introduces a 2-character command sequence.
所以我**更新的問題是為什麼我需要為此使用
prefix-2
?**請幫我翻譯一下,這樣我就可以理解了,這樣我就不必再為此困擾大家了。舊東西緊隨其後
更新
原來QNX中的ESC是
^[
. 使用該命令bind '^[[3~'='delete-char-backward'
,我可以讓游標用~
. 這至少是一些進步——我現在知道如何為 shell 拼寫Delete Key。我在網上看到的大多數東西都說刪除鍵是^?
,但這似乎對我不起作用。另外,我應該提到我正在通過 PuTTy 訪問它。我不明白,因為Control D做了我想要刪除鍵做的事情。我嘗試
eot-or-delete
再次綁定它無濟於事。這應該很簡單吧?
更新 2:
bind | grep prefix ^X = prefix-2 ^[ = prefix-1 ÿ = prefix-3 ^[O = prefix-2 ^[[ = prefix-2 bind | grep '[^ -~]' ÿ = prefix-3 à = beginning-of-line à¡ = up-history ठ= backward-char ঠ= forward-char ਠ= end-of-line à© = down-history ଠ= delete-char-forward à´ = backward-word ච= forward-word
更新 3:我的更多設置
環境設置
echo $ENV /etc/kshrc
BIND 完成輸出
bind ^A = beginning-of-line ^B = backward-char ^C = abort ^D = eot-or-delete ^E = end-of-line ^F = forward-char ^G = abort ^H = delete-char-backward ^I = complete ^J = newline ^K = kill-to-eol ^L = redraw ^M = newline ^N = down-history ^O = newline-and-next ^P = up-history ^R = search-history ^T = transpose-chars ^U = kill-line ^V = version ^W = kill-region ^X = prefix-2 ^Y = yank ^[ = prefix-1 ^\ = no-op ^] = search-character-forward ^^ = quote ^_ = eot ^? = delete-char-backward ÿ = prefix-3 ^[^H = delete-word-backward ^[^X = complete-file ^[^[ = complete ^[^] = search-character-backward ^[ = set-mark-command ^[# = comment ^[* = expand-file ^[. = prev-hist-word ^[0 = set-arg ^[1 = set-arg ^[2 = set-arg ^[3 = set-arg ^[4 = set-arg ^[5 = set-arg ^[6 = set-arg ^[7 = set-arg ^[8 = set-arg ^[9 = set-arg ^[< = beginning-of-history ^[= = complete-list ^[> = end-of-history ^[? = list ^[C = capitalize-word ^[L = downcase-word ^[O = prefix-2 ^[U = upcase-word ^[[ = prefix-2 ^[_ = prev-hist-word ^[b = backward-word ^[c = capitalize-word ^[d = delete-word-forward ^[f = forward-word ^[g = goto-history ^[h = delete-word-backward ^[l = downcase-word ^[u = upcase-word ^[y = yank-pop ^[^? = delete-word-backward ^X^X = exchange-point-and-mark ^X^Y = list-file ^X^[ = complete-command ^X? = list-command ^XA = up-history ^XB = down-history ^XC = forward-char ^XD = backward-char ^XH = beginning-of-line ^XP = delete-char-forward ^XY = end-of-line ^Xc = forward-word ^Xd = backward-word ^Xw = end-of-line à = beginning-of-line à¡ = up-history ठ= backward-char ঠ= forward-char ਠ= end-of-line à© = down-history ଠ= delete-char-forward à´ = backward-word ච= forward-word
/etc/kshrc
/etc # cat kshrc case $- in *i*) export SHELL_COLOR_BLUE="print -n \\033[0;34m" export SHELL_COLOR_GREEN="print -n \\033[0;32m" export SHELL_COLOR_RED="print -n \\033[0;31m" export SHELL_COLOR_LIGHTGRAY="print -n \\033[0;37m" export SHELL_COLOR_YELLOW="print -n \\033[1;33m" export COLOR_BLACK="\\033[0;30m" export COLOR_BLUE="\\033[0;34m" export COLOR_GREEN="\\033[0;32m" export COLOR_CYAN="\\033[0;36m" export COLOR_RED="\\033[0;31m" export COLOR_PURPLE="\\033[0;35m" export COLOR_BROWN="\\033[0;33m" export COLOR_LIGHTGRAY="\\033[0;37m" export COLOR_DARKGRAY="\\033[1;30m" export COLOR_LIGHTBLUE="\\033[1;34m" export COLOR_LIGHTGREEN="\\033[1;32m" export COLOR_LIGHTCYAN="\\033[1;36m" export COLOR_LIGHTRED="\\033[1;31m" export COLOR_LIGHTPURPLE="\\033[1;35m" export COLOR_YELLOW="\\033[1;33m" export COLOR_WHITE="\\033[1;37m" if [[ `id -u` -eq 0 ]]; then export PS1=`$SHELL_COLOR_RED`'$(hostname -s):'`$SHELL_COLOR_YELLOW`'$(pwd) # '`$SHELL_COLOR_LIGHTGRAY` else export PS1=`$SHELL_COLOR_BLUE`'$(hostname -s):'`$SHELL_COLOR_GREEN`'$(pwd) $ '`$SHELL_COLOR_LIGHTGRAY` fi esac
膩子設置:
可能重要也可能不重要但可以提供背景的註釋:
外殼是“PD KSH v5.2.14 99/07/13.2”。是的,我沒有升級的選擇……它是一個嵌入式系統。“獲得現代外殼”不是一個可行的答案。作業系統是 QNX Neutrino 6.4.1。
綁定顯示如下:
bind | grep del ^D = eot-or-delete ^H = delete-char-backward ^? = delete-char-backward ^[^H = delete-word-backward ^[d = delete-word-forward ^[h = delete-word-backward ^[^? = delete-word-backward ^XP = delete-char-forward ଠ= delete-char-forward
infocmp 顯示以下內容:
infocmp # Reconstructed via infocmp from file: /usr/lib/terminfo/x/xterm xterm|vs100|xterm terminal emulator, am, km, mir, msgr, xenl, xon, cols#80, it#8, lines#65, vt@, acsc=Oa``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, bel=^G, blink=@, bold=\E[1m, clear=\E[H\E[2J, cr=^M, csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=\E[B, cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A, dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K$<3>, enacs=\E(B\E)0, home=\E[H, ht=^I, hts=\EH, ich=\E[%p1%d@, ich1=\E[2~, il=\E[%p1%dL, il1=\E[L, ind=^J, is1=\E=\E[?1l, kBEG=\ENn, kCPY=\ENs, kCRT=\ENt, kDL=\ENv, kEXT=\ENw, kFND=\ENx, kHLP=\ENy, kOPT=\ENz, ka3=\EOs, kb2=\EOr, kbs=^H, kc1=\EOq, kcan=\EOm, kclo=\ENc, kclr=\ENa, kcmd=\EOu, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, kdch1=\E[P, kend=\E[9, kf1=\E[11~, kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, kf2=\E[12~, kf3=\E[13~, kf4=\E[14~, kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, kfnd=\ENf, khlp=\ENh, khome=\E[8, khts=\ENb, kich1=\E[2~, kmov=\ENi, kmrk=\ENm, kmsg=\ENe, knp=\E[6~, kopn=\ENo, kopt=\ENk, kpp=\E[5~, kref=\ENl, kres=\ENp, krfr=\ENg, krpl=\ENr, krst=\ENj, ksav=\ENq, kslt=\EOM, ktbc=\ENd, kund=\ENu, rc=\E8, rev=\E[7m, ri=\EM, rmacs=^O, rmam=\E[?7l, rmkx=\E>, rmso=\E[m, rs1=\E>\E[1;3;4;5;6l\E[?7h\E[m\E[r\E[2J\E[H, rs2=@, sc=\E7, setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m, setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m, sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m, sgr0=\E[m, smacs=^N, smam=\E[?7h, smkx=\E=, smso=\E[7m, tbc=\E[3g,
stty 顯示如下:
stty Name: /dev/ttyp0 Type: pseudo Opens: 2 +edit +echok +echonl +osflow intr=^C quit=^\ erase=^? kill=^U eof=^D start=^Q stop=^S susp=^Z lnext=^V min=01 time=00 pr1=^[ pr2=5B left=44 right=43 up=41 down=42 ins=40 del=50 home=48 end=59
對於 Google 員工:
唷。對於應該如此簡單的事情,這很難。
簡短的解決方案是使用以下設置刪除鍵(在
kshrc
或任何地方),bind '^[[3'=prefix-2 bind '^[[3~'=delete-char-forward
並將您的 PuTTy 終端設置設置為
rxvt
而不是Standard
.真正幫助我完成這項工作的事情是: http: //www.mail-archive.com/misc@openbsd.org/msg81796.html
ksh 用 home 鍵和 end 鍵做了一些傻事。基本上,我無法讓它同時區分 Home、End 和 Delete。無論最後綁定的是什麼,所有三個鍵都可以。更改 PuTTy 為這些密鑰發送的內容非常有幫助。
注意:有些人建議如果您想查看按下某個鍵時 shell 得到的程式碼,請鍵入
cat
,按輸入鍵,然後按下該鍵。對於我的外殼,這不起作用。我得到~
了所有的控制鍵。我所做的是按Esc
一次,然後按 鍵。控制程式碼將顯示然後顯示。使用該控制程式碼,bind
一切就緒。