前言:

💡 在组长的推荐下尝试了一把vim,一开始点进Linux vi/vim | 菜鸟教程 (runoob.com)入门时,看着键盘图看得头皮发麻,各种快捷键用的速度还不如鼠标老老实实一下一下点击,但用了两个星期以后大呼过瘾,甚至觉得这个教程里快捷键有些不够,便去找了一下官方文档,

vscode配置vim:

配置过程分两步

1.在vscode的插件市场中下载vim插件

Untitled

2.在头部导航栏中点击文件,按 文件/首选项/设置 的顺序来到设置页,然后拖动滚动条跑到页面最底部,点击 ‘在settings.json中编辑’

3.在settings.json最外部的{}中的最后一个元素后加上以下代码,然后保存,则完成配置,可以使用了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"vim.easymotion": true,
"vim.incsearch": true,
"vim.useSystemClipboard": true,
"vim.useCtrlKeys": true,
"vim.hlsearch": true,
"vim.insertModeKeyBindings": [
{
"before": ["j", "j"],
"after": ["<Esc>"]
}
],
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["<leader>", "d"],
"after": ["d", "d"]
},
{
"before": ["<C-n>"],
"commands": [":nohl"]
},
{
"before": ["K"],
"commands": ["lineBreakInsert"],
"silent": true
}
],
"vim.leader": "<space>",
"vim.handleKeys": {
"<C-a>": false,
"<C-f>": false,
"<C-c>": false,
},
"vue.splitEditors.layout.left": [


"script",
"scriptSetup",
"styles"
]

vim快捷键

以下内容为Linux vi/vim | 菜鸟教程 (runoob.com)没有讲到,而我看官方文档后觉得比较常用的快捷键。新手入门还请先从菜鸟教程学习基础。

标记与跳转

快捷键 作用
m{a-zA-Z} mark current position with mark {a-zA-Z}
`{a-z} go to mark {a-z} within current file
‘. go to the position of the last change in this file
‘“ go to the position when last editing this file
:marks print the active marks
🔢 % goto line N percentage down in the file; N must be given, otherwise it is the % command

查找

快捷键 作用
* search forward for the identifier under the cursor
g* like “*”, but also find partial matches
gd goto local declaration of identifier under the cursor
gD goto global declaration of identifier under the cursor

光标移动

快捷键 作用
% find the next brace, bracket, comment, or “#if”/ “#else”/“#endif” in this line and go to its match
‘> go to the end of the (previous) Visual area
‘< go to the start of the (previous) Visual area
f{char} to the Nth occurrence of {char} to the right
F{char} to the Nth occurrence of {char} to the left
t{char} till before the Nth occurrence of {char} to the right
T{char} till before the Nth occurrence of {char} to the left

普通模式的插入

快捷键 作用
K 上方插入一空行而不进入输入模式
cc 删除该行至行首且切换为输入模式

控制滚动条

快捷键 作用
🔢 CTRL-E window N lines downwards (default: 1)
🔢 CTRL-Y window N lines upwards (default: 1)
🔢 CTRL-D window N lines Downwards (default: 1/2 window)
🔢 CTRL-U window N lines Upwards (default: 1/2 window)
zt redraw, current line at top of window
z. or zz redraw, current line at center of window
zb redraw, current line at bottom of window
🔢 zh scroll screen N characters to the right
🔢 zl scroll screen N characters to the left
🔢 zH scroll screen half a screenwidth to the right
🔢 zL scroll screen half a screenwidth to the left

视图模式( CTRL-V )命令

快捷键 作用
aw Select a word(不包括符号)
aW Select a word(包括符号)
ap Select “a paragraph”(上下两个空行之间,)
a[]<>’’{}”” 选择对应的一整个块
i[]<>’’{}”” 选择块中的内容
at Select “a tag block”
it Select “inner tag block” (from to )
I insert the same text in front of all the selected lines
A append the same text after all the selected lines
c Change each of the selected lines with the entered text

插入模式(ii)命令

快捷键 作用
CTRL-W delete word before the cursor
CTRL-E insert the character from below the cursor
CTRL-Y insert the character from above the cursor
CTRL-A inser previously inserted text
CTRL-@ insert previously inserted text and stop Insert mode
CTRL-U delete all entered characters in the current line before the cursor

普通模式的命令

快捷键 作用
q{a-Z} record typed characters into register {a-z}
q stop recording
🔢 @{a-z} execute the contents of register {a-z} (N times)
🔢 @@ repeat previous @{a-z} (N times)
“{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}

基本命令

快捷键 作用
gp like p, but leave cursor after the new text
🔢 CTRL-A add N to the number at or after the cursor
🔢 CTRL-X subtract N from the number at or after the cursor