简体   繁体   English

当我分解它们时,如何使 VS Code 拆分长字符串*正确*?

[英]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:在其他编辑器中,如果我有一行 Javascript ,例如:

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

and my cursor is in the middle of that string:我的 cursor 位于该字符串的中间:

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 + :然后我按ENTER ,我的编辑器将足够聪明,可以将该字符串分成两个有效字符串,由+连接:

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

... but not VS Code. ...但不是 VS 代码。 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.现在一个名为 Split Lines 的插件,它承诺可以做到这一点……但它已经被破坏了一段时间。

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?我的问题是,有什么方法可以在 2021 年(理想情况下仅使用 VS Code,但如果没有,使用扩展)在我分解字符串时使 VS Code 更智能?

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 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#multi-line_strings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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