Visual Studio Code中实现移到行尾加分号或逗号并换行

最近因项目需要,IDE由Visual Studio 2022换成了Visual Studio Code,语言也由C#换成了Dart。总体感觉在逐渐适应中,不过还是有些小细节不吐不快。

比如在编码过程中,在下面这种情况,我们按下【tab】后,光标会自动移到行尾,我们直接回车就可以完成本行代码输入。

不愧是老牌IDE,对于这种录入小细节的便捷性处理还是很贴心的。

然而,在Visual Studio Code中,当录入代码时的光标还在小括号内,如果要想快速完成输入。要按下【end】+";",或者【end】+","才可以。如图:

我们希望按下快捷键,让光标自动移动到行尾,自动录入分号或逗号。

解决方案:

1.打开插件面板,找到multi-command,并安装。

2.按下【ctrl】+【shift】+P,输入keyboard,点击下面菜单:

3.在kedbindings.json的[]中输入

复制代码
{  
  "key": "ctrl+;",  
  "command": "extension.multiCommand.execute",  
  "args": {  
    "sequence": [  
      {  
        "command": "cursorEnd"  
      },  
      {  
        "command": "type",  
        "args": {  
          "text": ";"  
        }  
      },  
      {  
        "command": "editor.action.insertLineAfter"  
      }  
    ]  
  },  
  "when": "editorTextFocus"  
},  
{  
  "key": "ctrl+,",  
  "command": "extension.multiCommand.execute",  
  "args": {  
    "sequence": [  
      {  
        "command": "cursorEnd"  
      },  
      {  
        "command": "type",  
        "args": {  
          "text": ","  
        }  
      },  
      {  
        "command": "editor.action.insertLineAfter"  
      }  
    ]  
  },  
  "when": "editorTextFocus"  
}

4.【ctrl】+";"或【ctrl】+",",即可实现自动输入逗号或分号并回车。

相关推荐
时空自由民.1 天前
vim入门配置教程
编辑器·vim·excel
zh_xuan1 天前
解决VS Code 控制台中文乱码
c++·vscode·乱码
周末也要写八哥1 天前
Eclipse 2024全流程网盘下载与安装配置教程详解
java·ide·eclipse
猿儿本无心1 天前
快速搭建Python项目(Vscode+uv+FastAPI)
vscode·python·uv
ChampaignWolf1 天前
在 Eclipse 中使用 Tabnine
java·ide·eclipse
π同学1 天前
ESP-IDF+vscode开发ESP32第十二讲——event
vscode·esp32·事件循环库event
诗水人间1 天前
VsCode 中使用Copilot调用Deepseek V4模型
ide·vscode·copilot
梦想家加一1 天前
vscode为什么下载了汉化插件却不生效
ide·vscode·编辑器
神码编程1 天前
【Unity】MiniGame编辑器小游戏(十五)中国象棋局域网对战【Chinese Chess】(上)
unity·编辑器·游戏引擎·小游戏
NiceCloud喜云1 天前
Claude API 流式输出(SSE)实战:从打字机效果到工具调用全流程
java·前端·ide·人工智能·chrome·intellij-idea·状态模式