Visual Studio Code Extensions - Variable-print Plugin

01/01/2025, Wed
Categories: #editor

One plugin for Multiple Programming Languages

To quickly look at the output of a variable, you can use the print or console statement in your programming language of choice. Most of the language packages you add with the vscode extensions do not have a shortcut hotkey combination to quickly print or log out a variable. A good majority of the extensions also caters to the more common programming languages such as JavaScript or Python.

It would be most beneficial to have a general logger where you can activate the statement with a use of a shortcut key combination if you tend to work with multiple languages. There are a couple of general print loggers on the vscode extension marketplace, but the variable-print plugin stood out in that it was the one that offered the option of adding new languages to support custom print statements.

The default hotkey combination was

ctrl+alt+p

but you will need to test out shortcut combination to see if it works. It tends to be the case that the default hotkey combination doesn't work because it is highly likely have another plugin or shortcut has already taken this.

For my setup, I changed it to

ctrl+shift+alt+p

In your settings.json file, add the following block to modify the output. The following block is taken from the default configuration, but you can also define print output formats for new languages if you don't find it in the keys of this JSON block.

This is how my configuration looks like:

"variable-print.customPrintStatements": {
    "r": "print($v)",
    "rust": "println!(\"row: $row - col: $col $v -> {}\", &$v);",
    "go": "fmt.Printf(\"row: $row - col: $col $v -> %#v\",$v)",
    "h|c|cpp": "printf(\"row: $row - col: $col $v -> %s\\n\", $v);",
    "javascript|typescript": "console.log($v);",
    "python": "print(f\"$v\", $v)",
    "java": "System.out.println($v);",
    "ruby": "puts \"row: $row - col: $col $v -> #{$v}\"",
    "php": "var_dump($v);",
    "lua": "print(\"row: $row - col: $col $v ->(\",type($v),\")\",$v)",
    "kotlin": "println(\"row: $row - col: $col $v -> \"+$v)",
    "csharp": "Console.WriteLine(\"row: $row - col: $col $v -> {0}\", $v);",
    "swift": "print(\"row: $row - col: $col $v -> \\($v)\")",
    "dart": "print(\"row: $row - col: $col $$v -> $v ${$$v.runtimeType}\");",
    "perl": "say \"row: $row - col: $col $v -> $$v\";",
    "julia": "println(\"row: $row - col: $col $v ->\", $v)",
    "haskell": "putStrLn(\"row: $row - col: $col $v ->\" ++ $v)",
    "zig": "std.debug.print(\"row: $row - col: $col $v -> {}\", .{$v});",
    "v": "print($v)"
}

Note that you can also define multiple languages in the same key separated by the pipe character if you know that they share the same print statement format.