简体   繁体   中英

How Can I Make VS Code Split Long Strings *Properly* When I Break Them Up?

In other editors if I have a line of Javascript like:

const longString = 'abc abc abc abc abc abc abc abc abc';

and my cursor is in the middle of that string:

const longString = 'abc abc abc abc abc |abc abc abc abc';

and I hit ENTER , my editor will be smart enough to break that string into two valid strings, joined by a + :

const longString = 'abc abc abc abc abc ' +
                   'abc abc abc abc';

... but not VS Code. The most advanced editor I've ever used can't do this one (seemingly) basic thing, and it's driving me crazy.

Now there is a plug-in called Split Lines, that promises to do just this... but it's been broken for awhile.

My question is, is there any way, in 2021 (ideally with just VS Code, but if not, with extensions) to make VS Code smarter when I break up strings?

You could replace the single quotes with back ticks and it will still be recognized as a single string.

 console.log(`string text line 1 string text line 2`); // "string text line 1 // string text line 2"

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#multi-line_strings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM