bash設置vi為默認的編輯模式
編輯 /etc/inputrc 文件,設置全局readline配置,加入以下指令:
www.2cto.com
# I like vi mode,設置默認的編輯模式為vi
set editing-mode vi
# emacs mode settings,emacs模式配置指令
$if mode=emacs
# ...
# vi mode settings,vi模式配置指令
$else
# Ctrl+l : clear screen ,清屏
"\C-l": clear-screen
# Ctrl+p : previous-history,前一條歷史命令
"\C-p": previous-history
# Ctrl+n : next-history,後一條歷史命令
"\C-n": next-history
# Ctrl+e : press esc,ESC鍵,你懂的
"\C-e": "\e"
$endif
說明:
/etc/inputrc 文件是 libreadline 的全局配置文件,個人的配置文件為 ~/.inputrc
www.2cto.com
關於libreadline 的介紹如下:
The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are typed in. Both Emacs and vi editing modes are available. The Readline library includes additional functions to maintain a list of previously-entered command lines, to recall and perhaps reedit those lines, and perform csh-like history expansion on previous commands.
The history facilites are also placed into a separate library, the History library, as part of the build process. The History library may be used without Readline in applications which desire its capabilities.
Readline is free software, distributed under the terms of the GNU General Public License, version 3. This means that if you want to use Readline in a program that you release or distribute to anyone, the program must be free software and have a GPL-compatible license. If you would like advice on making your license GPL-compatible, contact
[email protected].
bash就是通過readline library 來提供命令行的方便快捷的編輯功能,包括各種用於命令編輯的快捷鍵,命令歷史操作等功能。