文章目录
需满足操作:
- 上下移动
- 按照 word 移动
- 选中增删改
- 查找字符/变量
- 移动、增加、复制、删除 行
- 选中多个相同的变量/字符
- 屏幕移动
- 增加多个光标
- 快速注释
10.mark后的快速跳转
上下左右移动
Command | Description |
---|---|
🔢 h | left (also: CTRL-H, BS, or Left key) |
🔢 l | right (also: Space or Right key) |
0 | to first character in the line (also: Home key) |
^ | to first non-blank character in the line |
🔢 $ | to the last character in the line (N-1 lines lower) (also: End key) |
gm | to middle of the screen line |
🔢 | | to column N (default: 1) |
🔢 f{char} | to the Nth occurrence of {char} to the right |
🔢 k | up N lines (also: CTRL-P and Up) |
🔢 j | down N lines (also: CTRL-J, CTRL-N, NL, and Down) |
🔢 - | up N lines, on the first non-blank character |
🔢 + | down N lines, on the first non-blank character (also: CTRL-M and CR) |
🔢 _ | down N-1 lines, on the first non-blank character |
🔢 G | goto line N (default: last line), on the first non-blank character |
🔢 gg | goto line N (default: first line), on the first non-blank character |
按照word移动
Command | Description |
---|---|
🔢 w | N words forward |
🔢 W | N blank-separated WORDs forward |
🔢 e | N words forward to the end of the Nth word |
🔢 E | N words forward to the end of the Nth blank-separated WORD |
🔢 b | N words backward |
🔢 B | N blank-separated WORDs backward |
🔢 ) | N sentences forward |
🔢 ( | N sentences backward |
🔢 } | N paragraphs forward |
🔢 { | N paragraphs backward |
选中增删改
进入 insert mode 后就和之前的模式一样,快捷键有些是和原理的 vscode 一致,有些不一致。
visual mode
Command | Description |
---|---|
v | start highlighting characters or stop highlighting |
V | start highlighting linewise or stop highlighting |
CTRL-V | start highlighting blockwise or stop highlighting |
o | exchange cursor position with start of highlighting |
删除
Command | Description |
---|---|
🔢 x | delete N characters under and after the cursor |
🔢 Del | delete N characters under and after the cursor |
🔢 X | delete N characters before the cursor |
🔢 d{motion} | delete the text that is moved over with {motion} |
{visual}d | delete the highlighted text |
🔢 dd | delete N lines |
🔢 D | delete to the end of the line (and N-1 more lines) |
(change = delete text and enter Insert mode) | |
🔢 c{motion} | change the text that is moved over with {motion} |
{visual}c | change the highlighted text |
🔢 cc | change N lines |
🔢 S | change N lines |
🔢 C | change to the end of the line (and N-1 more lines) |
🔢 s | hhchange N characters |
复制
Command | Description |
---|---|
"{char} | use register {char} for the next delete, yank, or put |
"* | use register * to access system clipboard |
:reg | show the contents of all registers |
:reg | {arg} show the contents of registers mentioned in {arg} |
🔢 y{motion} | yank the text moved over with {motion} into a register |
{visual}y | yank the highlighted text into a register |
🔢 yy | yank N lines into a register |
🔢 Y | yank N lines into a register |
🔢 p | put a register after the cursor position (N times) |
🔢 P | put a register before the cursor position (N times) |
🔢 ]p | like p, but adjust indent to current line |
🔢 [p | like P, but adjust indent to current line |
🔢 gp | like p, but leave cursor after the new text |
🔢 gP | like P, but leave cursor after the new text |
增加
Command | Description |
---|---|
🔢 a | append text after the cursor (N times) |
🔢 A | append text at the end of the line (N times) |
🔢 i | insert text before the cursor (N times) (also: Insert) |
🔢 I | insert text before the first non-blank in the line (N times) |
🔢 gI | insert text in column 1 (N times) |
gi | insert at the end of the last change |
🔢 o | open a new line below the current line, append text (N times) |
🔢 O | open a new line above the current line, append text (N times) |
查找字符/变量
Command | Description |
---|---|
🔢 /{pattern}[/[offset]] | search forward for the Nth occurrence of {pattern} Currently we only support JavaScript Regex but not Vim’s in-house Regex engine. |
🔢 ?{pattern}[?[offset]] | search backward for the Nth occurrence of {pattern} Currently we only support JavaScript Regex but not Vim’s in-house Regex engine. |
🔢 / | repeat last search, in the forward direction {count} is not supported. |
🔢 ? | repeat last search, in the backward direction {count} is not supported. |
🔢 n | repeat last search |
🔢 N | repeat last search, in opposite direction |
# or * | 你还可以搜索整词,将光标移动到这个词语上,然后按向前搜索,或者#向后搜索。想要查找下一个匹配,再按或者#。 |
移动、增加、复制、删除 行
复制行
insert mode
alt + shift up/down
删除行
dd
移动行
insert mode
alt + up/down
选中多个相同的变量/字符
CRTL +D选中目标
shift + c /d 等 修改、删除目标
此时再按 v,可退出 visual 模式,再按 a/i插入光标
cursor 即可编辑全部目标
屏幕移动
Command | Description |
---|---|
🔢 CTRL-E | window N lines downwards (default: 1) |
🔢 CTRL-D | window N lines Downwards (default: 1/2 window) |
🔢 CTRL-Y | window N lines upwards (default: 1) |
🔢 CTRL-U | window N lines Upwards (default: 1/2 window) |
zz | 将当前行移动到屏幕中央 |
增加多个光标
in Visual block mode:
Command | Description |
---|---|
I | insert the same text in front of all the selected lines |
A | append the same text after all the selected lines |
normal mode
alt + command + up / down(必须在 normal model,insert 和 visual 都不行)
then i or a
快速注释
command + /
切换 file
CTRL + TAB
CTRL + 12345
vscode 快捷键
CTRL + B 打开边栏
参考:https://github.com/VSCodeVim/Vim/blob/HEAD/ROADMAP.md
mark 跳转
m ——创建标记
’ ——移动到标记的文本行首
` ——移动到标记的光标位置
:marks ——列示所有标记
:delmarks ——删除指定标记
:delmarks! ——删除所有标记
宏的使用-复制p到下一行
宏录制的基本概念
宏(Macro)是Vim中的一组预先录制的命令序列,用户可以通过按下某个按键来重复执行这些命令。宏录制是将一系列的编辑操作记录下来,以便在后续的编辑过程中快速重放。
宏录制的步骤
录制宏的基本步骤如下:
- 进入正常模式。
- 按下 q 键开始录制宏。
- 按下一个字母键(如 a)来命名宏。
- 执行一系列编辑操作,这些操作将被记录下来。
- 按下 q键结束录制。
例如:
qa " 开始录制宏,宏的名称为 'a'
iHello " 进入插入模式并输入 'Hello'
<ESC> " 返回正常模式
A World! " 移动到行尾并追加 ' World!'
<ESC> " 返回正常模式
q " 结束录制
执行宏
执行宏的方法是按下 @ 键,然后输入宏的名称。例如,执行上述宏可以使用以下命令:
@a " 执行宏 'a'
多次执行宏
要多次执行宏,可以使用 @@ 命令,这将重复上一次执行的宏,或使用计数前缀来指定执行次数。例如,执行宏 a 五次:
5@a " 执行宏 'a' 五次
更多见详细内容