Bash 和 Zsh 开启 vi-mode
Bash 和 Zsh 开启 vi-mode
bash 有两种操作模式,分别是 emacs 和 vi 。
在 bash 中
set -o vi # 临时开启 vi 模式
vi ~/.bashrc # 在其中写入 `set -o vi`
source ~/.bashrc # 刷新配置
在 zsh 中
vi ~/.zshr # 在 plugins 数组中添加 vi-mode
source ~/.bashrc # 刷新配置
vi 编辑模式快捷键
http://www.catonmat.net/download/bash-vi-editing-mode-cheat-sheet.txt
http://mywiki.wooledge.org/set-o-vi-emacs
进入命令行模式:
ESC | 进入命令行模式
进入输入模式:
i | 在光标前插入
a | 光标后插入
I | 在行的开头插入
A | 在行的结尾插入
c<mov. comm> | Change text of a movement command <mov. comm> (见下文).
C | 剪切到行尾 (同 c$)
cc 或 S | 剪切整行 (同 0c$)
s | 删除光标处文本,并进入插入模式。 (同 c[SPACE])
r | 修改光标处文本 (没有离开命令样式)
R | 进入替换模式
v | 先执行命令,再使用编辑编辑命令。使用 $VISUAL 或 $EDITOR 变量定义编辑器, 编辑器默认 vi 。
移动 (命令模式下):
h | 按字左移
l | 按字右移
w | 按词右移
b | 按词左移
W | 以空白字符按词右移(比如 ab a-b , W 不会移动到 - 上,而 w 会)
B | 以空白字符按词左移
e | 移动光标到词尾部
E | 以空白符移动光标到词尾
0 | 移动光标到行首
^ | 移动光标到行首不是空白符
$ | 移动光标到行尾
% | 移动到左括号或右括号
字符查找 (也是移动命令):
fc | 右移到字符 c .
Fc | 左移到字符 c .
tc | 右移到字符 c 的左边
Tc | 左移到字符 c 的右边
; | 重做查找
, | 反方向重做查找
| | 移到第 n 列 (如 3| 移到第 3 列)
删除命令:
x | 删除当前光标所在字符.
X | 删除光标前的一个字符.
d<mov. comm> | Delete text of a movement command <mov. comm> (see above).
D | 删除到行尾 (同 d$).
dd | 删除行 (同 0d$).
CTRL-w | 向左删除单词 (编辑模式下)
CTRL-u | 删除到进入编辑模式时光标位置
撤销、重做、复制、粘贴:
u | 单步撤销
U | 撤销所有
. | 重做
y<mov. comm> | Yank a movement into buffer (copy).
yy | Yank the whole line.
p | 在光标处粘贴
P | 在光标前粘贴
历史记录:
k | 上一条命令
j | 下一条命令
G | 回来当前命令
/string 或 CTRL-r | 搜索历史命令(/string 用于命令模式下, ctrl-r 用于输入模式下)
?string 或 CTRL-s | 搜索历史命令(Note that on most machines Ctrl-s STOPS the terminal | output, change it with `stty' (Ctrl-q to resume)).
n | 下一条历史匹配
N | 上一条历史匹配
自动完成:
TAB 或 = 或 | 列出所有可能(TAB 用于输入模式)
CTRL-i |
* | Insert all possible completions.
其他:
~ | 切换当前光标处文本的大小写,并右移光标
# | 注释当前命令并把其放入历史
_ | Inserts the n-th word of the previous command in the current line.
0, 1, 2, ... | Sets the numeric argument.
CTRL-v | Insert a character literally (quoted insert).
CTRL-r | Transpose (exchange) two characters.
快捷键2
http://mywiki.wooledge.org/set-o-vi-emacs?action=raw
```
== Emacs and Vi modes in Bash ==
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.
=== Emacs Mode ===
$ 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.=== Vi Mode ===
$ set -o vi
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
CategoryShell
Bash 和 Zsh 开启 vi-mode的更多相关文章
- shell自动补全功能:bash和zsh
首要一点:shell有多种,比如bash.zsh.csh.ksh.sh.tcsh等 因此,制作自动补全功能时,要先搞清楚,你使用的是哪种shell,各个shell制作方法是不同的,网上大部分介绍的是关 ...
- Mac zsh切换bash bash切换zsh
切换bash ————>>>chsh -s /bin/bash 切换zsh ------->>>chsh -s /bin/zsh
- zsh切换bash bash切换zsh
切换bash(需要sudo) chsh -s /bin/bash 切换zsh(不需要sudo) chsh -s /bin/zsh 注意:如果输入命令和密码后提示:no change made. 请加上 ...
- 〖Linux〗在tmux同时使用bash和zsh
个人有两份tmux配置文件: ~/.tmux.conf # 使用zsh,主要是日常使用,zsh太好使用了 ~/.tmux.conf.bash # 使用bash,主要是Android编译使用 按照tmu ...
- sublime开启vi编辑器功能,与vi常用快捷键
sublime开启vi编辑器 install package -> vintageES 设置里面 ignored_packages 里面的vintage去掉 VI命令 游标控制 h 游标向左移 ...
- bash和zsh切换
zsh切换bash bash切换zsh 切换bash chsh -s /bin/bash 切换zsh chsh -s /bin/zsh
- MAC bash和zsh切换
bash和zsh切换 切换到bash chsh -s /bin/bash 切换到zsh chsh -s /bin/zsh 记得输入切换命令后,要重新打开终端terminal才生效哦!大功告成!
- 转载:(Mac)在bash和zsh配置环境变量path的几种方法
参考文献 老习惯,列出本文参考或引用或转载的文档和博客,致以崇高的敬意,感兴趣的可以去看看 1.http://postgresapp.com/ 2.http://postgresapp.com/doc ...
- linux、mac的bash和zsh如何切换
1.hostname 192-23-2-2 修改主机名字 2.chsh -s /bin/bash和chsh -s /bin/zsh可以永久切换,也就是一登录进来的就是相应的界面 bash/zsh命令是 ...
随机推荐
- 20165305 苏振龙《Java程序设计》第四周课上测试补做
第一次测试 第二次测试 第三次测试 上传代码 第四次测试 总结 之前我一直在git bash进行程序设计,但是对于我来说操作起来有点困难,所以我改用了虚拟机,之后之前一直困扰我的问题在虚拟机下就没有了 ...
- hive的find_in_set函数
集合查找函数: find_in_set语法: find_in_set(string str, string strList) 返回值: int说明: 返回str在strlist第一次出现的位置,str ...
- flask 表单
表单 在Web程序中,表单时和用户交互最常见的方式之一.用户注册.登录.撰写文章.编辑设置,无一不用到表单.不过,表单的处理不简单.要创建表单,验证用户输入的内容,向用户显示错误提示,还要获取并保存数 ...
- C# 制作软件启动界面
制作一个软件的启动界面 1.新建一个工程,将默认生成界面作为启动界面. 2.添加一个Label和ProgressBar还有Timer控件 注意:在ProgressBar控件中需要设置它的style ...
- Linux基础命令---显示文本look
look 显示文件中以特定字符串开始的行.在look执行二进制搜索时,必须对文件中的行进行排序.如果未指定文件,则使用文件“/usr/share/dict/words“,只比较字母数字字符,忽略字母字 ...
- [转载]Oracle中的NVL函数
Oracle中函数以前介绍的字符串处理,日期函数,数学函数,以及转换函数等等,还有一类函数是通用函数.主要有:NVL,NVL2,NULLIF,COALESCE,这几个函数用在各个类型上都可以. 下面简 ...
- 关于spark进行实时日志解析,保存hbase与mysql
进行地域分析 rowkey=中国_上海_201901016 value=访问次数 areaStartAmt.foreachRDD(rdd => { rdd.foreachPartition(pa ...
- 理解Sql Server 事务隔离层级(Transaction Isolation Level)
关于Sql Server 事务隔离级别,百度百科是这样描述的 隔离级别:一个事务必须与由其他事务进行的资源或数据更改相隔离的程度.隔离级别从允许的并发副作用(例如,脏读或虚拟读取)的角度进行描述. 隔 ...
- Always an integer UVALive - 4119
题目很简单,就是求表达式(P/D)的结果是不是整数.其中P是一个整系数的多项式,D是一个正整数. 把1-k(最高次)+1都试一次就好了.结论可以总结归纳得到.(k取 0, 1, 2 .... 的情况推 ...
- Centos部署flask项目
必备: Python2.7(ok) MySQL(ok) git supervisor virtualenv Gunicorn 阿里云服务器(最便宜的就好) 域名(国内万网,国外goDaddy) 我的P ...