How do I turn on word wrap for Output View in VS code?
Asked Answered
C

5

18

I'm running my code using the extension "Code Runner" and would like the output to be displayed word-wrapped. Currently when I run it, it displays the output all in a single line even if it's a long line.

I tried the setting "editor.wordWrap": "on".

This is how the output and editor look like:

This is how the output and editor look like:

Crowbar answered 17/1, 2020 at 2:41 Comment(2)
I think it's related more to the console/terminal settings than with VS Code (AFAIK, there is no wrap settings for the Output/Terminal pane). Judging from your screenshot, are you on Ubuntu?Caboodle
yes, i am on ubuntuCrowbar
S
34

Try adding this to your settings:

"[Log]": {
  "editor.wordWrap": "on"
}
Shoshanashoshanna answered 18/1, 2020 at 20:0 Comment(5)
Indeed, this is the correct answer to your question @paula-rodriguesMastoiditis
I have the same issue. This setting (editor.wordwrap) only applies to the editor. It does not affect the output window. I'm compiling some template c++ code and the compiler output goes to that window. It results in incredibly long lines some times.Oho
@Oho make sure you have [Log] in your setting.Shoshanashoshanna
@Diogo-Rocha Yeah, that was it. It was configured not to wrap. Thanks.Oho
Why isn't this in the settings ui (or is it and I can't find it)?Caitlin
C
4

You can instead use the built-in debugger configuration for Python and set in launch configuration to use the "internalConsole"

{
    "name": "run-test-py",
    "type": "python",
    "request": "launch",
    "program": "${workspaceFolder}/myfile.py",
    "console": "internalConsole"
},

so that the output appears in the Debug Console panel. The word wrapping for that panel is controlled by the Debug > Console: Word Wrap setting:

vscode setting

Set it to true:

"debug.console.wordWrap": false,

debug console

Caboodle answered 24/2, 2020 at 6:5 Comment(0)
T
0

For the Debug Console you can use "debug.console.wordWrap": false,//default:true which was added in June 2019 with issue 72210

Targum answered 25/1, 2023 at 17:43 Comment(0)
D
0

VS Code 1.86+ answer

Toggling word wrapping in the Output View is now supported via the View: Toggle Word Wrap command when the Output View is focused. That command is bound by default to alt/opt+z.

Pre-1.86 answer

Output Channels can have an associated language mode (see createOutputChannel(name: string, languageId?: string): OutputChannel in the extension API docs), but most of them use the other function overload, createOutputChannel(name: string, options: {log: true}): LogOutputChannel, which uses the specially defined "log" language mode. What you need to do is find out what language mode is being used in the output channels of interest, and then override the editor.wordWrap setting just for those languages.

To handle the basic cases of the "log" language mode, try putting something akin to the following in your settings.json file:

"[log][Log]": {
    "editor.wordWrap": "on",
}

You can add other language modes to the above list as needed. See also https://code.visualstudio.com/docs/getstarted/settings#_language-specific-editor-settings.

Other related source code for the log/Log language mode IDs for when VS Code uses them can be found in relation to src/vs/workbench/services/output/common/output.ts, where OUTPUT_MODE_ID and LOG_MODE_ID are defined. Also interesting is the fact that their language support extension defines Log as an alias of log, but they are registered separately in src/vs/workbench/contrib/output/browser/output.contribution.ts, which I think is why in my experience, you need to specify "[log][Log]": instead of just "[log]": in the language override setting.

Dramatist answered 21/11, 2023 at 23:40 Comment(0)
S
0

As of vscode v1.86 the command

View: Toggle Word Wrap

will, when the Output view is focused toggle word wrap on/off. So you could set up a keybinding like:

{
  "key": "alt+z",                             // appears to be the default keybinding
  "command": "editor.action.toggleWordWrap"
},
Sillsby answered 23/1 at 22:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.