How can I switch word wrap on and off in Visual Studio Code?

Visual Studio-Code

Visual Studio-Code Problem Overview


When using code files, you typically don't need longer lines to wrap around. However, with .md files this is in fact rather useful. However, I can't seem to find the option to enable word wrap so longer lines will be wrapped.

To reproduce, open Visual Studio Code resized to a small-enough window, and enter the following text in a new document:

This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum. This is my test lorem ipsum.
A linebreak before this. 

The effect is this:

Example of missing word wrap

I'm trying to get the horizontal scrollbar to stay away, having line 1 wrap around at the right side of the window.

I've done a few things to answer my own question:

  • Search Stack Overflow: zero results at the time of writing this;
  • Meticulously going through the menu of Visual Studio Code: didn't find it;
  • Using the Command Palette with "wrap": gives no matching commands.

Perhaps it's not possible, and I'd need to file a feature request? Or am I missing something?

Note that I'd like to be able to turn it on and off quickly. For one, @PanagiotisKanavos mentioned in comments this solution to change wrapping behavior in the settings, but I'm looking for a quick command or menu option to do this (much like Notepad++ and Sublime Text 2 have).

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

Since v1.0 you can toggle word wrap:

  • with the new command editor.action.toggleWordWrap, or
  • from the View menu (View* → Toggle Word Wrap), or
  • using the ALT+Z keyboard shortcut (for Mac: +Z).

It can also be controlled with the following settings:

  • editor.wordWrap
  • editor.wordWrapColumn
  • editor.wrappingIndent

Known issues:

  1. renderLineHighlight should highlight the entire logical line

If you'd like these bugs fixed, please vote for them.

Solution 2 - Visual Studio-Code

Go to menu FilePreferencesUser Settings.

It will open up Default Settings and settings.json automatically. Just add the following in the settings.json file and save it. This will overwrite the default settings.

// Place your settings in this file to overwrite the default settings
{ "editor.wrappingColumn": 0 }

Screenshot of settings being edited.

Solution 3 - Visual Studio-Code

wrappingColumn has been deprecated in favour of wordWrap.

Add this line to settings.json to set wordWrap on by default:

"editor.wordWrap": "on" 

or open user settings:

Mac: + ,

Windows: Ctrl + ,

Then search for "wordWrap" or scroll through the 'Commonly Used' settings to find it and select 'on'

enter image description here

Solution 4 - Visual Studio-Code

Since version 0.3.0, wrapping has been put in the command palette. You can activate it with Toggle Word Wrap or Alt + Z.

Solution 5 - Visual Studio-Code

Check out this screenshot (Toogle Word Wrap):

Enter image description here

Solution 6 - Visual Studio-Code

If you want to use text word wrap in your Visual Studio Code editor, you have to press button Alt + Z for text word wrap. Its word wrap is toggled between text wrap or unwrap.

Solution 7 - Visual Studio-Code

Since 1.9, it's possible to select a specific language for word wrap settings (or any settings). You can find this in the command palette under:

Preferences: Configure Language Specific Settings...

Which will take you to your "settings.json" for a selected language where you might include:

"[markdown]": {
  "editor.wordWrapColumn": 100,
  "editor.wordWrap": "wordWrapColumn"
},

Solution 8 - Visual Studio-Code

Go to the Preferences tab (menu FileSettings), and then search as “word wrap”. The following animated image is helpful too.

Enter image description here

Solution 9 - Visual Studio-Code

Here you go with word-wrap on Visual Studio Code.

Solution 10 - Visual Studio-Code

I am not sure when it was added, but I'm using v0.10.8 and Alt + Z is the keyboard shortcut for turning word wrap on and off. This satisfies the requirement of "able to turn it on and off quickly".

The setting does not persist after closing Visual Studio Code. To persist, you need to set it through Radha's answer of using the settings.json file...

// Place your settings in this file to overwrite the default settings
{ "editor.wrappingColumn": 0 }

Solution 11 - Visual Studio-Code

Word wrap settings redesign

Here are the new word wrap options:

editor.wordWrap: "off" - Lines will never wrap.
editor.wordWrap: "on" - Lines will wrap at viewport width.
editor.wordWrap: "wordWrapColumn" - Lines will wrap at the value of editor.wordWrapColumn.
editor.wordWrap: "bounded" 

Lines will wrap at the minimum of viewport width and the value of editor.wordWrapColumn.

Solution 12 - Visual Studio-Code

  1. press ctrl+ shift + p
  2. Preferences open keyboard shortcut
  3. search Toggle Wrap word
  4. Set your preferences toggle wrap word

NOTES:

  • Works for version 1.55.2
  • Default one is alt+z

Solution 13 - Visual Studio-Code

Explained here [Language-specific editor settings][1] but specifically:

  1. Ctrl+Shift+P and type "Preferences: Configure Language Specific Settings"
  2. Select the language or add section in the file (start typing "[" to see list of suggestions) or edit section as you like if already there.
  3. If set it to bounded you might need to adjust the editor.wordWrapColumn value to wrap depending on the screen size. With bounded Lines will wrap at the minimum of viewport and editor.wordWrapColumn

Example:


"editor.wordWrapColumn": 200,
"[markdown]": {
"editor.wordWrap": "on",
},
"[plaintext]": {
"editor.wordWrap": "bounded",
},
"[typescript]": {
"editor.tabSize": 2,
"editor.wordWrap": "off",
},
[1]: https://code.visualstudio.com/docs/getstarted/settings#_languagespecific-editor-settings

Solution 14 - Visual Studio-Code

This is from the VS Code docs as of May 2020:

> Here are the new word wrap options: > > editor.wordWrap: "off" - Lines will never wrap. > editor.wordWrap: "on" - Lines will wrap at viewport width. > editor.wordWrap: "wordWrapColumn" - Lines will wrap at the value of editor.wordWrapColumn. > editor.wordWrap: "bounded" - Lines will wrap at the minimum of viewport width and the value of editor.wordWrapColumn.

So for example, if you want to have the lines wrapped at the boundary of the window, you should:

  1. Open settings.json (Hit CTRL+SHIFT+P and type "settings.json")

  2. Put "editor.wordWrap": "bounded" in the json file, like this:

    {

    ... ,

    "editor.wordWrap": "bounded",

    ... ,

    }

and then it should work.

Solution 15 - Visual Studio-Code

If it's not working in mac,

make sure to tell VScode that you are not using a screen reader. I had word wrap on and restarted VScode, and it gave me a notification window saying that if I'm in a screenreader, yes or no, and to note that word-wrap does not work in screen readers.

Solution 16 - Visual Studio-Code

  • Windows: Ctrl + Shift + press the key "P". Now on the command line, type Toggle Word Wrap and press Enter.
  • Mac: Command + Shift + press the key "P". Now in the command line, type Toggle Word Wrap and press Enter.

Solution 17 - Visual Studio-Code

For Dart check "Line length" property in Settings.

Solution 18 - Visual Studio-Code

Accessibility support is on by default and it will override your selected wrapper behavior. So disable Accessibility Support first.

Then choose "on" for the Word Wrap option. You don't need to go into settings.json to enable word wrap.

Picture of the accessibility support option

Solution 19 - Visual Studio-Code

  • Mac: Code -> Preferences -> Settings -> Type wordwrap in Search settings -> Change Editor: Word Wrap from off to on.

  • Windows: File -> Preferences -> Settings -> Type wordwrap in Search settings -> Change Editor: Word Wrap from off to on.

Solution 20 - Visual Studio-Code

If you want a permanent solution for wordwrapping lines, go to menu FilePreferenceSettings and change editor.wordWrap: "on". This will apply always.

However, we usually keep changing our preference to check code. So, I use the Alt + Z key to wrap written code of a file or you can go to menu ViewToggle Word Wrap. This applies whenever you want not always. And again Alt + Z to undo wordwrap (will show the full line in one line).

Solution 21 - Visual Studio-Code

In version 1.52 and above go to File > Preferences > Settings > Text Editor > Diff Editor and change Word Wrap parameter as you wish

Solution 22 - Visual Studio-Code

The language-specific example by @Riga is great. For a general setting, I would recommend the following:

"editor.wordWrap": "bounded",
"editor.wordWrapColumn": 90,
"editor.wrappingIndent": "same",

This wraps text if your viewport is smaller than the column limit (90 here) and uses the same indent when wrapping.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeroenView Question on Stackoverflow
Solution 1 - Visual Studio-CodeBenjamin PaseroView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeRadha SatamView Answer on Stackoverflow
Solution 3 - Visual Studio-CodePixelomoView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeHaroen ViaeneView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeNishView Answer on Stackoverflow
Solution 6 - Visual Studio-CodeAvinash DewanganView Answer on Stackoverflow
Solution 7 - Visual Studio-CoderobstarbuckView Answer on Stackoverflow
Solution 8 - Visual Studio-CodesnrView Answer on Stackoverflow
Solution 9 - Visual Studio-Codeحمزہ صابرView Answer on Stackoverflow
Solution 10 - Visual Studio-CodeHossView Answer on Stackoverflow
Solution 11 - Visual Studio-Codedigish a dView Answer on Stackoverflow
Solution 12 - Visual Studio-CodeSyahidur RahmanView Answer on Stackoverflow
Solution 13 - Visual Studio-CodeRicardo stands with UkraineView Answer on Stackoverflow
Solution 14 - Visual Studio-CodeTim Skov JacobsenView Answer on Stackoverflow
Solution 15 - Visual Studio-CodeRoyer AdamesView Answer on Stackoverflow
Solution 16 - Visual Studio-CodeBahman.AView Answer on Stackoverflow
Solution 17 - Visual Studio-CodeAdam SmakaView Answer on Stackoverflow
Solution 18 - Visual Studio-CodeCihanView Answer on Stackoverflow
Solution 19 - Visual Studio-CodeDaniel DanieleckiView Answer on Stackoverflow
Solution 20 - Visual Studio-CodeAbhishekView Answer on Stackoverflow
Solution 21 - Visual Studio-CodermbView Answer on Stackoverflow
Solution 22 - Visual Studio-CodeAdam EricksonView Answer on Stackoverflow