简体   繁体   English

如何在Visual Studio代码中选择div的内部

[英]How do I select the insides of div in Visual Studio Code

For example. 例如。 I have 我有

<div class="wrap>
 <div class="fu">
  bar
 </div>
</div>

How do I select with all it's contents with a shortcut key? 如何使用快捷键选择所有内容?

Notepad++ had this feature. Notepad ++有这个功能。 When div contents get really long, it's annoying to scroll or collapse-select. 当div内容变得非常长时,滚动或折叠选择会很烦人。

You can select it with an Emmet command, if you have your cursor somewhere inside the first tag, just use Emmet: Balance (outward) and Emmet: Balance (inward) . 您可以使用Emmet命令选择它,如果您将光标放在第一个标签内的某个位置,只需使用Emmet: Balance (outward)Emmet: Balance (inward) If you are doing a lot of HTML, you can check for more Emmet commands if you simply type Emmet: in the command palette. 如果您正在执行大量HTML,则只需在命令选项板中键入Emmet:即可检查更多Emmet命令。

Because it's mentioned in the other answer: 因为它在另一个答案中提到:

What the "expand-region" plugin does, is somewhat supported by default, see this answer in another thread 默认情况下,“扩展区域”插件的功能有所支持,请参阅另一个主题中的答案

This does not support shrinking/growing the selection around HTML-tags, but you can easily setup your shortcuts to use Emmet in HTML files and the aforementioned commands in every other file – on the same shortcut. 支持收缩/成长各地HTML标签的选择,但你可以轻松地设置你的快捷方式在所有其他文件中使用埃米特在HTML文件和上述命令-在同一个快捷方式。 Syntax for setting this is up looks like this (feel free to replace ctrl+up / ctrl+down to whatever you prefer): 用于设置此语法的语法如下所示(可随意将ctrl+up / ctrl+down替换为您喜欢的任何内容):

{
    "key": "ctrl+up",
    "command": "editor.action.smartSelect.grow",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+up",
    "command": "editor.emmet.action.balanceOut",
    "when": "editorTextFocus && editorLangId == html && editorHasSelection"
},
{
    "key": "ctrl+down",
    "command": "editor.action.smartSelect.shrink",
    "when": "editorTextFocus"
},
{
    "key": "ctrl-down",
    "command": "editor.emmet.action.balanceIn",
    "when": "editorTextFocus && editorLangId == html"
},

Just for clarification, the editorHasSelection part allows to expand inside strings on the first key press (eg for selecting/editing tag attributes). 只是为了澄清, editorHasSelection部分允许在第一次按键时扩展内部字符串(例如,用于选择/编辑标签属性)。

As far as I know this is still not supported out of the box for HTML. 据我所知,HTML仍然不支持开箱即用。

You could install extension expand-region , set it up as stated on the page and then use Ctrl + W (or any other shortcut you choose) to select the content of the element. 您可以安装扩展扩展区域 ,按照页面上的说明进行设置,然后使用Ctrl + W (或您选择的任何其他快捷方式)来选择元素的内容。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM