Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSC: How to auto close curly brackets in f-strings

Hi I want to ask if it's possible to enable auto closing curly brackets in f-strings in Visual Studio Code. In Python you use often f-strings and therefore you need curly brackets.

print(f"Hello {name}!")

I already found something but I don't know if that feature is already implemented and if not if I can implement it with external plugins?: https://github.com/microsoft/vscode-python/issues/13673

like image 432
puncher Avatar asked Sep 15 '25 21:09

puncher


2 Answers

Use the "Always" Auto Closing Brackets setting, but limit it to Python in your settings.json:

"[python]": {
    "editor.autoClosingBrackets": "always"
}
like image 76
SiJiL Avatar answered Sep 19 '25 11:09

SiJiL


VS Code has this auto closing brackets feature built-in in the editor. It's just disabled by default if you use it inside a string. To make it always close the brackets, Go to File > Preferences > Text Editor > Auto Closing Brackets then change the value from 'languageDefined' to 'Always'. The Option.

like image 32
ccrsxx Avatar answered Sep 19 '25 11:09

ccrsxx