首页 > 解决方案 > vscodevim中是否有进入插入模式/普通模式或其他模式的命令?

问题描述

我正在尝试在 VSCode 中创建一个非常简单的代码段,并且我正在使用 vim 扩展。插入代码段后,我成功进入了 insertMode。之后我什么都写不出来了。

这是我的python.json文件:

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

这是我的 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
                }
            ],
        }
    ],

我知道我可以为片段写参数,但更多的是为了学习如何使用 vim 扩展,因为我想创建另一个使用 vim 的扩展。

这是我第一个问题的结尾,但我还有第二个问题:

当我使用这个键绑定时,我希望代码缩进。例如(“|”代表光标位置):

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

应用快捷方式

这就是我要的:

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

这就是我得到的:

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

标签: visual-studio-codevscodevim

解决方案


Q1:

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

还有一个命令extension.vim_insert可能有用。像这样输入单词"t","y","p","e"可能是不好的做法,只需制作自定义 vscode 片段即可

Q2:

正确的方法是保持光标打开line 2并按下o键,自动缩进到您想要的位置。您很少会处于光标位于line 3.

光标可能会出现的地方。

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

之后o

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

推荐阅读