Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I visually replace an expression in VS Code with a symbol?

I am using Visual Studio Code for Python development. A very common expression in python is lambda x: x which can be a little verbose when used 40+ times in a module.

Does VS code allow for this to be replaced with a symbol? eg. replacing lambda with λ?

So code like df.apply(lambda x: x**2) would appear as df.apply(λx: x**2)

To clarify, I DONT want to modify the source code, I just want it to be displayed on my code editor using the shorthand.

like image 340
MYK Avatar asked Apr 29 '26 12:04

MYK


1 Answers

Very late to the party, but I recommend using this extension: prettify-symbols-mode

Adding following config to settings.json worked for me:

"prettifySymbolsMode.substitutions": [{
    "language": "python",
    "revealOn": "active-line",
    "substitutions": [
        { "ugly": "lambda",     "pretty": "λ", "post": "\\s*(?:\\w|_).*?\\s*:" }
    ]
}]
like image 134
LordBertson Avatar answered May 03 '26 08:05

LordBertson