Skip to content

Keyboard Shortcuts ​

Note

Not all of the following shortcut keys are universally compatible with every variant of Unix and Linux. Some of these shortcut keys are designed for use in a terminal environment, while others are for use in a desktop environment.

Terminal environment ​

Moving the cursor ​

shortcut keysintroduction
Ctrl+BMoves the cursor backward one character.
Ctrl+FMoves the cursor forward one character.
Esc+BMoves the cursor backward one word.
Esc+FMoves the cursor forward one word.
Ctrl+AMoves the cursor to the beginning of the line.
Ctrl+EMoves the cursor to the end of the line.

Edit ​

shortcut keysintroduction
Ctrl+HErase one character. Similar to pressing backspace.
Ctrl+DLogs out of the current session.
Ctrl+UErases the line forward from the cursor.
Ctrl+KErases the line backward from the cursor.
Ctrl+W删除当前光标到临近左边单词结束
Esc+D删除当前光标到临近右边单词开始, 改键为 alt+d.
Esc+.粘帖最后一次命令最后的参数(通常用于 mkdir long-dir 后, cd 配合着 alt+.
Ctrl+L相当于 clear 命令
Cmd+R换到新屏,不会像 clear 一样创建一个空屏

Other ​

shortcutkeysintroduction
Ctrl+PPaste previous line(s).
Ctrl+NPaste next line(s).
Ecs+P上一条命令(例如输入 ls, 然后按 Esc+P , 就会找到历史记录下的 ls 命令)
Ecs+N下一条命令
Ctrl+RAllows you to search for a previously used command or switch.
Ctrl+SStops all output on-screen (XOFF).
Ctrl+QTurns all output stopped on-screen back on (XON). Also, closes an application window.
Ctrl+CCancels the currently running command.
Ctrl+ZCancels the current operation, moves back a directory or takes the current operation and moves it to the background. See bg command for additional information about background.

vim 快捷键 ​

一般模式 ​

shortcut keysintroduction
%括号上跳转
zz当前行置为屏幕中央
zttop 当前行
zbbottom 当前行
w向前移动一个词 (上一个字母和数字组成的词之后)
dw向前删除一个词
W向前移动一个词 (以空格分隔的词)
[num]w向前移动[num]个词
b向后移动一个词 (下一个字母和数字组成的词之前)
db向后删除一个词
B向后移动一个词 (以空格分隔的词)
[num]b向后移动[num]个词
h光标左移
j光标下移
k光标上移
l光标右移
0移动光标到当前行首
^移动光标到当前行首非空字符处
$移动光标到当前行尾
gg移动光标到首行
G移动光标到尾行
[num]G光标移动到第[num]行
Ctrl+d屏幕向后移动半页
Ctrl+u屏幕向前移动半页
Ctrl+b屏幕向后移动一页
Ctrl+f屏幕向前移动一页
x向后删除一个字符
X向前删除一个字符
d0删除至行首
d$删除至行末
D删除至行末
d(删除至句头
d)删除至句尾
dgg删至文件开头
dG删至文件末尾
[num]x向后删除[num]个字符
[num]dd向下删除剪切[num]行
[num]yy向下复制[num]行
["x]yy复制当前行至寄存器 x
[num]p粘贴刚删除或复制剪切的文本[num]次
[num]P向上粘贴刚删除或复制剪切的文本[num]次
["x]p在当前行之后粘贴寄存器 x 中的内容
u撤销 undo 操作
Ctrl+r反撤销 undo
ZZ退出 Vim,如果文件被改动过,保存改动内容
ZQ与 :q! 相同,退出 Vim,不保存文件改动
V进入逐行可视模式,实现删除或复制剪切
v进入逐字可视模式,实现删除或复制剪切
Ctrl+v块模式
Shift+v行模式
?search_test检索文档,在光标前面的部分搜索 search_text

编辑模式 ​

shortcut keysintroduction
r替换字符
R覆写模式
i光标处 insert
I光标行首 insert
a光标后 insert
A光标行尾 insert
o当前行的下一行 insert
O当前行的上一行 insert

命令模式 ​

shortcut keysintroduction
:set [no]nu显示[取消]行号
:set ff[=unix]查看[修改格式为 unix]文件格式
:set [no]paste设置[取消]paste 模式来复制粘贴
:r <filename>在光标下方插入文件 <filename> 的内容
:reg显示寄存器的内容
:%s/original/replacement检索第一个 “original” 字符串并将其替换成 “replacement”
:%s/original/replacement/g检索并将所有的 “original” 替换为 “replacement”
:%s/original/replacement/gc检索出所有的 “original” 字符串,但在替换成 “replacement” 前,先询问是否替换
:n1, n2/word1/word2/g在 n1-n2 行之间查找 word1 并替换为 word2,不加 g 只替换每行的第一个 word1
:x保存退出