我使用 VSCode Neovim 插件,我想使用“Ctrl+S”键“保存此文件,然后切换到正常模式”,这会在视觉上将光标样式从“细”更改为“实”。
我的 vim/nvim 配置文件是:
"--- ctrl + s saving
noremap <silent> <C-S> :update<CR>
vnoremap <silent> <C-S> <C-C>:update<CR>
inoremap <silent> <C-S> <C-O>:update<CR><ESC>
但是在VSCode中,编辑一些文字,然后按“Ctrl+S”只是保存文件,并没有切换到正常模式。即
<C-O>:update<CR><ESC>
未执行。我怎样才能让它执行呢?
尝试过的解决方案: 在 VSCode 中,保存时退出 Vim 插入模式
settings.json
:
"macros": {
"saveAndExitVimInsertMode": [
"workbench.action.files.save",
"extension.neovim.escape"
]
}
keybindings.json
:
{
"key": "ctrl+s",
//"command": "workbench.action.files.save"
"command": "macros.saveAndExitVimInsertMode"
},
但还是不行。
通过
setttings.json
中的以下配置解决:
"macros": {
"saveAndExitVimInsertMode": [
"workbench.action.files.save",
//"extension.nvim_escape" // not working
"vscode-neovim.escape" // working
]
},
参考:https://github.com/vscode-neovim/vscode-neovim/issues/74#issuecomment-563214553
另一个不错的解决方案是使用多命令扩展:
{
"key": "ctrl+s",
"command": "extension.multiCommand.execute",
"when": "editorTextFocus && neovim.init && neovim.mode == 'insert'",
"args": {
"sequence": ["workbench.action.files.save", "vscode-neovim.escape"]
}
}
这样,只有在实际处于插入模式时才发送转义信号。