If you are new to vim
, these are a few vim shortcuts to get you started with vim on vscode.
Modes
<Esc>
: normal modei
,a
: insert before/after the cursorI
,A
: insert beginning/end of the lineo
,O
: insert new line bellow/obove linev
,V
: character/line level visual mode
Movement
h
,j
,k
,l
: left/down/up/rightw
,e
: beginning/end of the next wordb
,ge
: beginning/end of the previous0
,$
: beginning/end of the linegg
,G
: beginning/end of the file*
,#
: next/previous occurrence of word under the cursor%
: matching character of the character under the cursor
Edit
x
,s
: delete character and (go to insert mode)r
,R
: replace character/textdw
,cw
,yw
: delete/change/copy word (after cursor)dd
,cc
,yy
: delete/change/copy lineD
,C
,Y
: delete/change/copy from cursor to end of linep
: paste
Indent
>>
,<<
: (un)indent line (normal mode)>
,<
: (un)indent selected text (visual mode)
Search
/{keyword}
: search for the next keywordn
,N
: next/previous occurrence
repeat
.
: repeat previous command{n}{key}
: repeatkey
,n
times{n}gg
: go to linen
VSCode Settings
I found the following settings necessary to make vim efficient in vscode.
settings.json
Add below settings to your settings.json
file.
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{
"vim.whichwrap": "b,s,l,h", // allows to go to next/previous line with movement keys
"vim.leader": " ", // setting space to leader key
"vim.visualModeKeyBindingsNonRecursive": [
// pressing ctrl + [j/k] in visual mode, moves the selection down/up
{
"before": [
"C-j"
],
"commands": [
"editor.action.moveLinesDownAction"
],
},
{
"before": [
"C-k"
],
"commands": [
"editor.action.moveLinesUpAction"
],
},
],
"vim.insertModeKeyBindingsNonRecursive": [
// pressing ctrl + [h/j/k/l] in insert mode, moves the cursor
{
"before": [
"C-h"
],
"after": [
"Left"
]
},
{
"before": [
"C-j"
],
"after": [
"Down"
]
},
{
"before": [
"C-k"
],
"after": [
"Up"
]
},
{
"before": [
"C-l"
],
"after": [
"Right"
]
}
]
}
keybindings.json
Add below settings to your keybindings.json
file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[
// pressing ctrl + [j/k] in suggestions or quick actions moves selection down/up
{
"key": "ctrl+j",
"command": "selectNextSuggestion",
"when": "suggestWidgetVisible"
},
{
"key": "ctrl+k",
"command": "selectPrevSuggestion",
"when": "suggestWidgetVisible"
},
{
"key": "ctrl+j",
"command": "workbench.action.quickOpenSelectNext",
"when": "inQuickOpen"
},
{
"key": "ctrl+k",
"command": "workbench.action.quickOpenSelectPrevious",
"when": "inQuickOpen"
},
]