如何改变历史的bash完成,完成什么已就行了? [英] How do I change bash history completion to complete what's already on the line?
问题描述
我发现了一个命令,几个月前,使我的bash历史自动完成对什么是已经上线的时候pressing向上箭头:
I found a command a couple of months ago that made my bash history auto-complete on what's already on the line when pressing the up arrow:
$ vim fi
preSS <大骨节病>↑骨节病>
$ vim file.py
我想设置此我的新电脑,因为它保持一个大的历史时,节省了大量的时间。问题是,我不能为我的生活记得有人提到,通过无休止的bash引用和教程阅读遗憾的是没有帮助的。
I'd like to set this up on my new computer, because it saves a lot of time when keeping a big history. The problem is that I can't for the life of me remember where it was mentioned and reading through endless bash references and tutorials unfortunately didn't help either.
有谁知道命令?
推荐答案
大概就像
# ~/.inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward
或等同地,
# ~/.bashrc
if [[ $- == *i* ]]
then
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
fi
(if语句检查交互模式)
(the if statement checks for interactive mode)
通常情况下,上下绑定到Readline的功能 previous史
和下的历史
分别。我preFER到PgUp键/ PgDn键绑定到这些功能,而不是取代上/下的正常运行。
Normally, Up and Down are bound to the Readline functions previous-history
and next-history
respectively. I prefer to bind PgUp/PgDn to these functions, instead of displacing the normal operation of Up/Down.
# ~/.inputrc
"\e[5~": history-search-backward
"\e[6~": history-search-forward
修改后〜/ .inputrc文件
,重新启动您的外壳,或使用<大骨节病>控制骨节病> + <大骨节病> X 骨节病>,<大骨节病>按Ctrl 骨节病> + <大骨节病>研究骨节病>告诉它重读〜/ .inputrc文件
。
After you modify ~/.inputrc
, restart your shell or use Ctrl+X, Ctrl+R to tell it to re-read ~/.inputrc
.
顺便说一句,如果你正在寻找相关文件:
By the way, if you're looking for relevant documentation:
Bash使用的shell提示符和历史GNU readline库。
这篇关于如何改变历史的bash完成,完成什么已就行了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!