Jump to a closing Bracket, Parenthesis or Tag in VS Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
6 min

banner

# Table of Contents

  1. Jump to a closing Bracket or Parenthesis in VS Code
  2. Jump to a closing Tag in VS Code
  3. Select everything between brackets in VS Code

# Jump to a closing Bracket or Parenthesis in VS Code

To jump to a closing bracket or parenthesis:

  1. Select the bracket or parentheses.
  2. On Windows and Linux press Ctrl + Shift + \.
  3. On macOS press Cmd + Shift + \.

go to matching bracket or parenthesis

The command enables you to go to the matching (opening or closing) square bracket, curly brace or parenthesis.

If your cursor isn't on a specific bracket or parenthesis, VS Code tries to find the nearest bracket or parenthesis.

The keyboard shortcut might not work if your keyboard isn't English.

For example, on Windows:

  • for Spanish keyboards, press: Ctrl + Shift + |.
  • for German keyboards, press: Ctrl + Shift + ^.

# Finding the keyboard shortcut in your case

The easiest way for you to find the keyboard shortcut is to:

  1. Place your cursor on the bracket.

  2. Press:

  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Go to Bracket and view the keyboard shortcut.

type go to bracket

For example, the screenshot shows that the short is Ctrl + Shift + \ in my case.

You can also run the command using the Command Palette:

  1. Place your cursor on the bracket.

  2. Press:

  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Go to Bracket and select the option.

go to bracket command palette

Note: if you need to go to a matching tag in an HTML or a JSX file, type go to matching pair and select Emmet: Go to Matching Pair instead.

# Setting a custom keyboard shortcut for the "Go to bracket" command

If you need to set a custom keyboard shortcut for the "Go to bracket" command:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Search for jumpToBracket and double-click on the option.

double click go to bracket

  1. Specify your preferred key combination and hit Enter.

For example, you can you something like Ctrl + Shift + 4 or Cmd + Shift + 4 on macOS.

# Jump to a closing Tag in VS Code

To jump to a closing tag in VS Code:

  1. Place your cursor on the tag.
  2. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type go to matching pair and select Emmet: Go to Matching pair.

go to matching tag

Here is a short clip that demonstrates the process:

go to matching tag

The command can be used to jump to a matching tag in an HTML or JSX file.

Note: if you use VIM, use the Shift + 5 key combination to jump to a matching tag.

If you encounter issues when using Emmet, check out my other article: Emmet not working in Visual Studio Code issue [Solved].

# Setting a Keyboard shortcut to jump to a closing tag

By default, the Emmet: Go to Matching pair command doesn't have a keyboard shortcut.

If you need to set a custom keyboard shortcut for the command:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Search for go to matching pair and double-click on the option.

set keyboard shortcut for jump to closing tag

You can also select the row and click on the plus icon to add a keyboard shortcut.

  1. Specify your preferred key combination and hit Enter.

For example, I use Ctrl + Shift + 3.

set custom keyboard shortcut to go to matching tag

Now you can use the key combination to go to the matching tag.

using custom shortcut to go to matching tag

If your cursor isn't positioned on a specific tag, VS Code finds the nearest tag.

# Select everything between brackets in VS Code

If you need to select everything between brackets:

  1. Select the bracket.
  2. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Select to Bracket and click on the option.

click select to bracket

Here is a short clip that demonstrates the process.

select to bracket

# Setting a keyboard shortcut for the "Select to Bracket" command

By default, the Select to Bracket action doesn't have a keyboard shortcut set.

If you need to set a keyboard shortcut:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Search for select to bracket and double-click on the option.

search select to bracket

You can also add a keyboard shortcut by left-clicking the row and clicking on the plus icon.

  1. Specify your preferred key combination and hit Enter.

I'll use a keyboard shortcut of Ctrl + Shift + 3 for the example.

set custom shortcut for select to bracket

Now you can use the keyboard shortcut to select the code between the brackets or parentheses (depending on where your cursor is placed).

# Select everything between brackets or quotes using Expand and Shrink selection

You can also use the expand and shrink selection commands to select everything between brackets or quotes.

On Windows and Linux, the keyboard shortcuts are:

  • Shift + Alt + Right arrow key to expand the selection.
  • Shift + Alt + Left arrow key to shrink the selection.

On macOS, the keyboard shortcuts are:

  • Ctrl + Shift + Right arrow key to expand the selection.
  • Ctrl + Shift + Left arrow key to shrink the selection.

expand shrink selection

If you need to find the keyboard shortcuts for the command or run them manually:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type expand selection and view the keyboard shortcut or run the command.

expand selection command

  1. Type shrink selection and view the keyboard shortcut or run the command.

shrink selection command

# Changing your keyboard shortcuts for the expand and shrink selection commands

If you need to set custom keyboard shortcuts for the expand and shrink selection commands:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Search for expand selection and double-click on the option.

change expand selection keyboard shortcut

  1. Double-click on the row, specify your preferred key combination and press Enter.

  2. Search for shrink selection and double-click on the option.

change shrink selection keyboard shortcut

  1. Double-click on the row, specify your preferred key combination and press Enter.

I've also written an article on how to wrap text with tags in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.