![](/img/trans.png)
[英]Is there a shortcut to format multiple lines of code into one line in VS Studio Code
[英]How to create shortcut for one line code in vs?
我想為可視代碼中的一行代碼創建一個快捷鍵。 例如,我想在代碼編輯器中使用“F4”鍵粘貼“ <p class='example _class'>
”此代碼或使用“F6”鍵粘貼“ <a href= ''>
”。 基本上我想為某行代碼創建快捷方式,這樣我就不需要一次又一次地復制這些行來在我的項目中重復這一行。
經過一番研究,我得到了答案,在 keybindings.json 文件上粘貼以下代碼:
{
"key": "F4",
"command": "type",
"args": {
"text": "<p class=\"example _class\">"
},
"when": "editorTextFocus"
},
我認為 json 代碼不需要任何解釋。 這幾乎是自我解釋。
如果您插入帶有鍵綁定的片段,則不必 select 並替換 class 名稱但使其成為占位符,使用TAB從制表位移動到制表位
{
"key": "F4",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "<p class=\"${1:example _class}\">$0</p>"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.