Linux 查看历史命令或补全文件名set -o vi/emacs
2013-02-28 19:01
288 查看
额,是自己看了别人写的东西的一点总结,可能有理解不当的地方
刚开始接触Linux不久,还是个小笨鸟,用bash的时候可以用tab去补全命令或者是文件名,用向上向下箭头可以翻看历史命令,感觉很方便
最近用到ksh 感觉颇为不爽啊,于是就上网一顿查看,最后翻出了 set -o vi/emacs
set -o vi之后 上滚一条命令是ESC+k 下滚一条命令是ESC+j 自动补全文件名(esc \)。
set -o vi 之后 再查看可以看到 vi 后面是 on 过想关闭 则 set +o vi 对 emac的设置同理
set命令选项
set -o vi 之后就可以进行相应的一些操作了
要想在AIX下使用上次你已经使用过的命令,可以使用以下的方法:
1、在ksh下,运行set -o vi,这个时候整个命令状态就是是VI编辑器了,操作的方法和VI编辑器一摸一样,要重复上次的命令,就在当前状态栏下按ESC,然后输入k,就可以看到下一条命令,按下k就可以查询上一条命令,h可以在当前行向前移动一个字符的位置,l可以在当前行向后移动一个字符的为止,当然这个时候相当于处于vi的状态,所有在vi状态下的对单行操作的命令都可以使用。编辑好之后直接按回车即可。
2、如果不不是在ksh下,那么你可以在命令窗口下运行ksh -o vi,其他的命令和第一种方法一样
3、在ksh的环境变量中设置EDITOR=vi即可,修改的方法即在.profile中直接加入EDITOR=vi;export EDITOR即可。
4、删除历史命令,可以在当前用户的主目录下,查询到一个.sh_history的文件,里面记载了你所有在当前用户输入过的命令。可以将这个文件编辑一下,然后将其中的命令删除掉就可以了。当然你可以将自己喜欢的命令或者比较长的命令放在里面,以后你就直接调用就可以了。当然从这个文件可以看出上面几点讲的采用vi的命令来取得上次的命令,其实ksh是取得这个文件中的信息。
5、以下小技巧:
a、重复上一条命令可以直接在ksh状态下输入r
b、你可以在ksh状态下执行r a=b,意思是先将上一条命令中的a字符用b字符替换,然后运行。
Two options that can be set using the set command that will be of some interest to the common user are "-o vi" and "-o emacs". As with all of the environment modifying commands these can be typed at the command prompt or inserted into the
appropriate file mentioned above.
Set Emacs Mode in Bash
$ set -o emacs
This is usually the default editing mode when in the bash environment and means that you are able to use commands like those in Emacs (defined in the Readline library) to move the cursor, cut and paste text, or undo editing.
. Commands to take advantage of bash's Emacs Mode:
o ctrl-a Move cursor to beginning of line
o ctrl-e Move cursor to end of line
o meta-b Move cursor back one word
o meta-f Move cursor forward one word
o ctrl-w Cut the last word
o ctrl-u Cut everything before the cursor
o ctrl-k Cut everything after the cursor
o ctrl-y Paste the last thing to be cut
o ctrl-_ Undo
o NOTE: ctrl- = hold control, meta- = hold meta (where meta is usually the alt or escape key).
o A combination of ctrl-u to cut the line combined with ctrl-y can be very helpful. If you are in middle of typing a command and need to return to the prompt to retrieve more information you can use ctrl-u to save what you have
typed in and after you retrieve the needed information ctrl-y will recover what was cut.
. Set Vi Mode in Bash
. $ set -o vi
. o Vi mode allows for the use of vi like commands when at the bash prompt. When set to this mode initially you will be in insert mode (be able to type at the prompt unlike when you enter vi). Hitting the escape key takes you
into command mode.
. Commands to take advantage of bash's Vi Mode:
o h Move cursor left
o l Move cursor right
o A Move cursor to end of line and put in insert mode
o 0 (zero) Move cursor to beginning of line (doesn't put in insert mode)
o i Put into insert mode at current position
o a Put into insert mode after current position
o dd Delete line (saved for pasting)
o D Delete text after current cursor position (saved for pasting)
o p Paste text that was deleted
o j Move up through history commands
o k Move down through history commands
o u Undo
刚开始接触Linux不久,还是个小笨鸟,用bash的时候可以用tab去补全命令或者是文件名,用向上向下箭头可以翻看历史命令,感觉很方便
最近用到ksh 感觉颇为不爽啊,于是就上网一顿查看,最后翻出了 set -o vi/emacs
set -o vi之后 上滚一条命令是ESC+k 下滚一条命令是ESC+j 自动补全文件名(esc \)。
set -o可以查看都设置了什么
set -o vi 之后 再查看可以看到 vi 后面是 on 过想关闭 则 set +o vi 对 emac的设置同理
set命令选项
选项名 | 快捷开关 | 含义 |
allexport | -a | 从这个选项中被设置开始就自动标明要输出的新变量或修改过的变量,直至选项被复位 |
braceexpand | -B | 打开花括号扩展,它是一个默认设置 |
emacs | 使用emacs内置编辑器进行命令行编辑,是一个默认设置 | |
errexit | -e | 当命令返回一个非零退出状态(失败)时退出。读取初始化文件时不设置 |
histexpand | -H | 执行历史替换时打开!和!!扩展,是一个默认设置 |
history | 打开命令行历史、默认为打开 | |
ignoreeof | 禁止用EOF(Ctrl+D)键退出shell。必须键入exit才能退出。等价于设置shell变量IGNOREEOF=10 | |
keyword | -k | 将关键字参数放到命令的环境中 |
interactive-comments | 对于交互式shell,把#符后面的文本作为注释 | |
monitor | -m | 设置作业控制 |
noclobber | -C | 防止文件在重定向时被重写 |
noexec | -n | 读命令,但不执行。用来检查脚本的语法。交互式运行时不开启 |
noglob | -d | 禁止用路径名扩展。即关闭通配符 |
notify | -b | 后台作业完成时通知用户 |
nounset | -u | 扩展一个未设置的变量时显示一个错误信息 |
onecmd | -t | 在读取和执行命令后退出 |
physical | -P | 设置时,在键入cd或pwd禁止符号链接。用物理目录代替 |
privileged | -p | 设置后,shell不读取.profile或ENV文件,且不从环境继承shell函数,将自动为setuid脚本开启特权 |
verbose | -v | 为调试打开verbose模式 |
vi | 使用vi内置编辑器进行命令行编辑 | |
xtrace | -x | 为调试打开echo模式 |
要想在AIX下使用上次你已经使用过的命令,可以使用以下的方法:
1、在ksh下,运行set -o vi,这个时候整个命令状态就是是VI编辑器了,操作的方法和VI编辑器一摸一样,要重复上次的命令,就在当前状态栏下按ESC,然后输入k,就可以看到下一条命令,按下k就可以查询上一条命令,h可以在当前行向前移动一个字符的位置,l可以在当前行向后移动一个字符的为止,当然这个时候相当于处于vi的状态,所有在vi状态下的对单行操作的命令都可以使用。编辑好之后直接按回车即可。
2、如果不不是在ksh下,那么你可以在命令窗口下运行ksh -o vi,其他的命令和第一种方法一样
3、在ksh的环境变量中设置EDITOR=vi即可,修改的方法即在.profile中直接加入EDITOR=vi;export EDITOR即可。
4、删除历史命令,可以在当前用户的主目录下,查询到一个.sh_history的文件,里面记载了你所有在当前用户输入过的命令。可以将这个文件编辑一下,然后将其中的命令删除掉就可以了。当然你可以将自己喜欢的命令或者比较长的命令放在里面,以后你就直接调用就可以了。当然从这个文件可以看出上面几点讲的采用vi的命令来取得上次的命令,其实ksh是取得这个文件中的信息。
5、以下小技巧:
a、重复上一条命令可以直接在ksh状态下输入r
b、你可以在ksh状态下执行r a=b,意思是先将上一条命令中的a字符用b字符替换,然后运行。
{Linux} bash的emacs编辑模式快捷键
Modifying the Bash Shell with the set CommandTwo options that can be set using the set command that will be of some interest to the common user are "-o vi" and "-o emacs". As with all of the environment modifying commands these can be typed at the command prompt or inserted into the
appropriate file mentioned above.
Set Emacs Mode in Bash
$ set -o emacs
This is usually the default editing mode when in the bash environment and means that you are able to use commands like those in Emacs (defined in the Readline library) to move the cursor, cut and paste text, or undo editing.
. Commands to take advantage of bash's Emacs Mode:
o ctrl-a Move cursor to beginning of line
o ctrl-e Move cursor to end of line
o meta-b Move cursor back one word
o meta-f Move cursor forward one word
o ctrl-w Cut the last word
o ctrl-u Cut everything before the cursor
o ctrl-k Cut everything after the cursor
o ctrl-y Paste the last thing to be cut
o ctrl-_ Undo
o NOTE: ctrl- = hold control, meta- = hold meta (where meta is usually the alt or escape key).
o A combination of ctrl-u to cut the line combined with ctrl-y can be very helpful. If you are in middle of typing a command and need to return to the prompt to retrieve more information you can use ctrl-u to save what you have
typed in and after you retrieve the needed information ctrl-y will recover what was cut.
. Set Vi Mode in Bash
. $ set -o vi
. o Vi mode allows for the use of vi like commands when at the bash prompt. When set to this mode initially you will be in insert mode (be able to type at the prompt unlike when you enter vi). Hitting the escape key takes you
into command mode.
. Commands to take advantage of bash's Vi Mode:
o h Move cursor left
o l Move cursor right
o A Move cursor to end of line and put in insert mode
o 0 (zero) Move cursor to beginning of line (doesn't put in insert mode)
o i Put into insert mode at current position
o a Put into insert mode after current position
o dd Delete line (saved for pasting)
o D Delete text after current cursor position (saved for pasting)
o p Paste text that was deleted
o j Move up through history commands
o k Move down through history commands
o u Undo
相关文章推荐
- LInux键盘高级操作(剪切、粘贴、历史命令、自动补全、移动光标、修改文本)
- linux 用户管理(3)----查看用户登录时间以及命令历史
- linux查看用户登录时间以及命令历史
- Linux查看历史命令 history
- Linux 查看Shell历史命令方法
- Linux 查看用户执行过的命令,运行特定历史命令
- Linux学习日记--基础命令(2)--文件查看,命令历史,命令展开
- Linux 下 SQL*Plus 上下键不能查看历史命令
- 设置Linux可以查看历史命令的执行时间
- Linux 查看历史命令并执行
- Linux环境下的SQL*PLUS及RMAN中不能使用上下方向键查看命令历史的解决方法
- Linux中查看文本文件内容命令cat/tac/nl/more/less/head/tail/vi总结
- 如何让python idle有命令自动补全和查看历史记录的方法
- linux查看历史命令history
- Linux中查看文本文件内容命令cat/tac/nl/more/less/head/tail/vi总结
- linux svn svn log 文件名来查看历史版本,恢复历史版本用 svn -r版本号 文件名
- Linux笔记(shell基础,历史命令,命令补全/别名,通配符,输出重定向)
- Linux中查看文本文件内容命令cat/tac/nl/more/less/head/tail/vi总结
- linux查看清空历史命令
- linux 文件查找帮助命令 , 查看网络链接信息, 历史命令