1

I'm trying to create a very simple snippet in VSCode and I'm using vim extension. I succeed to enter insertMode after inserting my snippet. I'm not able to write anything after that.

This is my python.json file:

"Print": {
    "prefix": "print",
    "body": [
        "print($1)$0"
    ],
    "description": "Print statement"
}

This is my settings.json:

    "vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": ["<leader>", "i", "p"],
            "commands": [
                {
                    "command": "editor.action.insertSnippet",
                    "args": {
                        "langId": "python",
                        "name": "Print"
                    }
                },
                {
                    "command": // COMMAND to enter insert mode here
                },
                {
                    "command": // COMMAND to type something (eg: `type` but I'm not sure I can use it with vim)
                },
                {
                    "command": // COMMAND to quit insert mode here
                }
            ],
        }
    ],

I know I could write arguments to the snippet but it's more for the sake of learning how to play with vim extension as I'd like to create another extension that uses vim one.

This is the end of my first question but I've got a second one:

When I use this keybinding, I want the code to be indented. For example ("|" represents cursor position):

def my_function():
    a = "super string"
|

Applying shortcut

This is what I want:

def my_function():
    a = "super string"
    print(|)

This is what I get:

def my_function():
    a = "super string"
print(|)

1 Answers1

0

Q1:

"vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": ["<leader>", "i", "p"],
            "commands": [
                {
                    "command": "editor.action.insertSnippet",
                    "args": {
                        "langId": "python",
                        "name": "Print"
                    }
                },
            ],
            "after": ["i","t","y","p","e","<ESC>"]
        }
    ],

There is also a command extension.vim_insert might be useful. Typing out words like this "t","y","p","e" is probably bad practice, just make custom vscode snippets instead.

Q2:

The correct method is to keep the cursor on line 2 and hit the o key, auto-indenting to where you want to be. Rarely will you be in a position where the cursor is on the first character of line 3.

Places where the cursor is likely going to be.

def my_function():
    |a = "|super |string"|

After o.

def my_function():
    a = "super string"
    |
Anthony Raimondo
  • 1,621
  • 2
  • 24
  • 40