简体   繁体   English

VS 代码 - 键绑定 - *type* 命令的 cursor position

[英]VS Code - Key bindings - cursor position for *type* command

I am using VS Code Version: 1.40.0.我正在使用 VS 代码版本:1.40.0。

for quicken up my development I would need to set my own keybinding for entering a certain text (" {|print_x} ") into the code.为了加快我的开发速度,我需要设置自己的键绑定,以便在代码中输入特定文本(“ {|print_x} ”)。 I managed to do that, but even better would be if the type cursor would jump right after " { " as soon as I'd paste the text.我设法做到了,但如果我粘贴文本后 cursor 类型会在“ { ”之后立即跳转,那就更好了。

So: { here type curosor |print_x} .所以: {这里输入 curosor |print_x}

Code in keybindings.json : keybindings.json中的代码:

 { 
    "key": "shift+alt+y", 
    "command": "type",
    "args": { "text": "{|print_x}", },
    "when": "editorTextFocus" 
}

I thought using an array like that might work, but unfortunately text argument needs to be string.我认为使用这样的数组可能会起作用,但不幸的是text参数需要是字符串。

   "args": { "text": [ "{" , "|print_x}" ], }

Is there a way to do it?有没有办法做到这一点? If so, I would be very thankful.如果是这样,我将非常感谢。

Just use this form instead:只需使用此表单即可:

 { 
    "key": "shift+alt+y",
    "command":  "editor.action.insertSnippet",
    "args": {
      "snippet": "{$1print_x}"
    },
    "when": "editorTextFocus" 
  }

Because this uses the insertSnippet command, you can now use tabstops or variable transforms right in a keybinding without a separate snippet.因为这使用了insertSnippet命令,所以您现在可以直接在键绑定中使用制表位或变量转换,而无需单独的片段。 So the cursor will go to where he $1 is.所以 cursor 将 go 到他$1所在的位置。

insertSnippet can do what the type command does and gives you tabstops. insertSnippet可以做type命令所做的事情并为您提供制表位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 VS Code 中更改 cursor 类型 - Change cursor type in VS Code VS 代码 cursor 在标签后的错误 position - VS Code cursor in wrong position after tab 找不到丢失的 VS Code 1.43 键绑定,以将光标键替换为文件浏览器的 h、j、k、l(此处包含的大多数其他键) - Can't find missing VS Code 1.43 key bindings to replace cursor keys with h,j,k,l for the file explorer (most others included here) VS Code - 键绑定 - 我自己的块注释 - VS Code - Key Bindings - my own Block comment 使 Visual Studio 使用 VS 代码快捷键/键绑定 - Make Visual Studio use VS code shortcut keys / key bindings 在创建新的键绑定后,vscode(Visual Studio 代码)中的多个键绑定光标右被禁用 - multiple key bindings in vscode (visual studio code) cursor right disabled after creation on new keybinding VS 代码跳转到一个符号,但 cursor 运动立即将焦点带回原始 cursor position - VS Code jump to a symbol but a cursor movement immediately brings focus back to original cursor position 如何阻止VS代码强制我使用大括号,否则光标位置变得疯狂(PHP,或全局应用) - How to stop VS Code forcing me to use braces, otherwise the cursor position goes crazy (PHP, or apply it globally) VS Code 光标跳到底部 - VS Code cursor jumping to bottom 将 VS Code 光标保持在屏幕上 - Keep VS Code cursor on screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM