jsturtevant / vscode-softwrap

Toggles Softwrap of lines in Visual Studio Code. Useful for markdown files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NOTE: This extension is no longer needed or maintained. Visual Studio now supports word wrap. The defualt short cut is now ALT -Z

Softwrap

You can find more details about the extension and implementation at http://www.jamessturtevant.com/posts/Softwrap-a-Visual-Studio-Code-Extension/. Also see Important Notes below.

Soft wrap in VS Code

To enable Soft wrap in VS Code you have to open your user settings file (open command pallet, type 'settings', select 'Open User Settings') and add the following line:

{
// there might be other custom settings you have in this file.
"editor.wrappingColumn": 0
}

Softwrap Extension

Manually opening the User Setting file and editing the editor.wrappingColumn value was going to get old quickly. So I did what any programmer would do... automate the process.

The result is Softwrap, an extension for VS Code, that enable you to quickly switch back and for between a "soft wrap" and your more friendly code wrap. Using Softwrap is simple:

  1. Open Command Pallet
  2. Type 'Softwrap' in the command window
  3. Hit Enter.

That is it! Softwrap will toggle on/off and preserve the value it was previously set to even if you had a custom value for editor.wrappingColumn already set in your User Settings file. You can check out the source at my GitHub repository.

Get it

You can find it at the Visual Studio Market Place:

https://marketplace.visualstudio.com/items/jsturtevant.softwrap

Important Notes

Reading and Writing the User Settings File

The limitation I ran into when trying to write to the User Settings file was that there is no VS Code API for it (see github issue). Again, I got a quick response on twitter that this was something that is under consideration but not yet implemented. The suggestion was to directly modify the file itself as a work around.

This was fairly simple to do because VS Code is sitting on top of Electron and we can leverage all the power and infrastructure of Node.js and the strong ecosystem that comes with it. It was easy enough to use the File System module to read/write the User Settings file.

VSCode JSON Schema

VS Code uses a custom JSON schema that allows comments in the settings file. My current implementation does not support comments and will strip them out. This is probably not the best way to handle the situation but will have to do for now.

About

Toggles Softwrap of lines in Visual Studio Code. Useful for markdown files.

License:MIT License


Languages

Language:TypeScript 100.0%