This is so easy in vim, I just select the lines and type gq
. Surely there is a simple way or extension to do the same in Visual Studio Code. To be clear, I am not looking to automatically wrap every line. I want to select a block of text, such as this example JavaScript template literal in a .js
file:
div.innerHTML = `<p>Tempore voluptatem cupiditate ullam. Et eum possimus et qui placeat sit voluptatem. Aut omnis similique eum nisi molestias laborum officia. Consectetur debitis sequi sapiente. Vero incidunt perspiciatis aut ut libero tenetur saepe eaque. Hic voluptates quis quasi expedita nemo hic omnis.</p>`;
Then do something to have it wrapped to a maximum line length of say, 80 characters.
This is what I tried already. By "no changes" I mean that nothing visible happened, i.e. the long lines remained:
- Selected the code and with right-click, chose "Format Selection". No changes.
- Looked it up on two search engines, found no suitable answer yet.
- Installed the
prettier
extension. If does format a larger selection, but no changes to the long lines. - Installed the
Rewrap
extension. After selecting the block I doALT + Q
but no changes. I also didCTRL + SHIFT + P
and chose theRewrap Comment / Text
command, but no changes. - Looked at a similar question but the answers there only apply to HTML.
So what is the way to do it that just works? I am happy to use vim but I quite like using VS Code as well, so would like to know this basic feature. Thank you!
Note: At the time of writing, I am on version 1.60.1 on Windows and WSL.