Home Minimum Viable Vim in VSCode
Post
Cancel

Minimum Viable Vim in VSCode

If you are new to vim, these are a few vim shortcuts to get you started with vim on vscode.

Modes

  • <Esc>: normal mode
  • i, a: insert before/after the cursor
  • I, A: insert beginning/end of the line
  • o, O: insert new line bellow/obove line
  • v, V: character/line level visual mode

Movement

  • h, j, k, l: left/down/up/right
  • w, e: beginning/end of the next word
  • b, ge: beginning/end of the previous
  • 0, $: beginning/end of the line
  • gg, 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/text
  • dw, cw, yw: delete/change/copy word (after cursor)
  • dd, cc, yy: delete/change/copy line
  • D, C, Y: delete/change/copy from cursor to end of line
  • p: paste

Indent

  • >>, <<: (un)indent line (normal mode)
  • >, <: (un)indent selected text (visual mode)
  • /{keyword}: search for the next keyword
  • n, N: next/previous occurrence

repeat

  • .: repeat previous command
  • {n}{key}: repeat key, n times
  • {n}gg: go to line n

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"
    },
]
This post is licensed under CC BY 4.0 by the author.