Search code examples
htmlvisual-studio-codeediting

VS Code editor: how select everything until next tag - or next occurent of <


There are keyboard shortcuts to select everything between matching brackets and to grow and shrink your selecting, however sometimes there is another markup inside. Is there a way to select everything from coursor to beginning of the next element? For example the cursor sits after the

tag. When pressing shortcut I want to:

<p>Select only this text<span>and not this</span>, also not this.</p>

Thank you


Solution

  • You can use the extension Select By.

    In your settings.json

      "selectby.regexes": {
        "till-angle-bracket": {
          "forward": "<",
          "forwardInclude": false
        }
      }
    

    You can use the command Select text range based on regex and select till-angle-bracket from the list

    or you can add a keybinding

      {
        "key": "ctrl+shift+y", // or any other key-combo
        "when": "editorTextFocus",
        "command": "selectby.regex",
        "args": ["till-angle-bracket"]
      }