question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable matching curly braces inside of quotation marks in an f-string

See original GitHub issue

Typically VS Code supplies a matching pair of parentheses, braces, and brackets when you type an opening character. But when you are inside of quotation marks, VS Code apparently gives up on this behavior, assuming that you are writing free text and not code. So you don’t get a closing brace automatically; you have to type it yourself. This is sub-optimal in Python when writing f-strings. In Python, you will often need to write matching braces inside of quotation marks, like so:

print(f"Let's talk about {some_variable}.")

When you type the opening brace inside the quotation marks, VS Code does not supply the closing brace—again, because VS Code apparently assumes you aren’t writing code. I would like VS Code to be able to detect when we are inside an f-string and, if we are, to automatically supply matching braces.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:18
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
belmer01commented, Sep 30, 2021

I think I might have found a workaround for this. Change the Auto Closing Brackets setting to always.

image

4reactions
silkfirecommented, Mar 21, 2022

If you don’t want this setting to mess up the configuration you have for your other languages, you can set it up to only be effective when working with Python files:

"[python]": {
    "editor.autoClosingBrackets": "always",

    "editor.tabSize": 4,
    "files.insertFinalNewline": true,

   ...
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I print curly-brace characters in a string while using ...
You can avoid having to double the curly brackets by using f-strings ONLY for the parts of the string where you want the...
Read more >
Python f Strings: The Ultimate Guide - Career Karma
Notice that we used single quotes (') inside our f string (which is denoted using curly braces), and double quotes (“”) to represent...
Read more >
How to print literal curly brace { or } in f-string and format string
A single opening curly bracket '{' marks a replacement field, which starts with a Python expression. This trick also apply to format string:...
Read more >
Python f-strings: Everything you need to know! - Datagy
They're called f-strings given that they are generated by placing an “f” in front of the quotation marks. What makes f-strings special is...
Read more >
Smart Keys | IntelliJ IDEA Documentation - JetBrains
Use this page to enable or disable specific smart keys and to define ... pressing Tab when typing inside brackets/quotes will move the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found