基本上可利用 readline的功能達到 readline的介紹 請"man bash" 或是"info readline" bind -P 可列出現有的readline binding function bind -B List current readline variable names and values. 可先由bind -P 來參考並學習他們binding的設定,以協助自行設定 而個人的設定檔是位於 ~/.inputrc中,若沒有請自行建立。記得做任何修改後,鍵入C-x C-r 讓readline重新讀取該設定檔 比如說 以下設定可以輸入ctrl-x l 即可以執行 "ls -l" "\C-xl": "\C-e\C-u ls -l \C-M" 加入\C-e\C-u 是可以讓目前的輸入清空 最後的 C-M 就等於是enter的意思 若你的keymap與我們不一樣,可以自行修改 所以你可以將要經常輸入的指令 加入~/.inputrc中隨時都可以加入移除 尤其是一些較長的指令時 我個人是蠻喜歡使用F9~F12這個區段 僅供您參考 像我常常用C-z 暫停某些程序 (比如修改script時,存檔後,跳出來測試,而不用結束編輯程式) 而為了方便再跳回 我就將 C-xz設成 fg 則可以很方便的切換shell跟當前的process "\C-xz": "\C-e\C-u fg \C-M" 另外比較特別但不常用的功能是在readline中 還可以加入like C prepocessor的條件式判斷 可以根據 mode(vi | emacs) term application 的不同來做不同的特定 比如以下的設定可以讓bash 可以藉由C-x q來將前一個word用括號包起來 $if Bash # Quote the current or previous word "\C-xq": "\eb\"\ef\"" $endif 其中 \eb \ef 都是bash 預設的功能 向是\eb是往後跳一個word -->即是alt-b 基本上readline是蠻好用的功能,希望這篇文章能對你有幫助 --- bind readline-command Display current readline key and function bindings, bind a key sequence to a readline function or macro, or set a readline variable. Each non-option argument is a command as it would appear in .inputrc, but each binding or command must be passed as a separate argument; e.g., ’"\C-x\C-r": re-read-init-file’. Options, if supplied, have the following meanings: -m keymap Use keymap as the keymap to be affected by the subsequent bindings. Acceptable keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, and vi-insert. vi is equivalent to vi-command; emacs is equivalent to emacs-standard. -l List the names of all readline functions. -p Display readline function names and bindings in such a way that they can be re-read. -P List current readline function names and bindings. -v Display readline variable names and values in such a way that they can be re-read. -V List current readline variable names and values. -s Display readline key sequences bound to macros and the strings they output in such a way that they can be re-read. -S Display readline key sequences bound to macros and the strings they output. -f filename Read key bindings from filename. -q function Query about which keys invoke the named function. -u function Unbind all keys bound to the named function. -r keyseq Remove any current binding for keyseq. -x keyseq:shell-command Cause shell-command to be executed whenever keyseq is entered. The return value is 0 unless an unrecognized option is given or an error occurred.