[英]Replace matching brackets for parenthesis vscode
Is there a way to quickly replace matching brackets for matching parenthesis (or any other opening/closing characters) in vscode?有没有办法快速替换匹配括号以匹配 vscode 中的括号(或任何其他开始/结束字符)?
Something like ctrl + d but for matching brackets, parenthesis and such.类似于ctrl + d但用于匹配括号、括号等。
I'm currently replacing traditional JavaScript function definitions (redux action creators) for arrow functions, also I'm using airbnb rules in eslint in which the rule arrow-body-style needs to move the returning value immediately after the =>
and because most action creators return an object literal it needs to be surrounded by parenthesis, that's why I need a mechanism to make the replacements easy.我目前正在为箭头函数替换传统的 JavaScript 函数定义(redux 动作创建者),我也在 eslint 中使用 airbnb 规则,其中规则箭头体样式需要在
=>
之后立即移动返回值,因为大多数动作创建者返回一个对象文字,它需要用括号括起来,这就是为什么我需要一种机制来使替换变得容易。
I'm trying to change.我正在努力改变。
export function hideServerErrors() {
return {
type: HIDE_SERVER_ERRORS,
};
}
to到
export const hideServerErrors = () => ({
type: HIDE_SERVER_ERRORS,
});
For your specific example, try this:对于您的具体示例,请尝试以下操作:
First, bind this command to some keychord, like首先,将此命令绑定到某个键和弦,例如
{
"key": "ctrl+alt+]",
"command": "editor.action.selectToBracket"
}
Then, with the cursor just inside your first bracket (end of your first line of code), trigger the command, eg, Ctrl - Alt - ] in my example keybinding.然后,将光标放在第一个括号内(第一行代码的末尾),触发命令,例如,在我的示例键绑定中, Ctrl - Alt - ] 。 The type your ( and you get:
类型您的(和你得到:
export function hideServerErrors() ({
return {
type: HIDE_SERVER_ERRORS,
};
})
which I think is all you are trying to accomplish with this one step.我认为这就是您要通过这一步完成的全部工作。 Given that you have a few things to change a snippet might be the way to go to make all the changes at once.
鉴于您有一些事情需要更改,因此片段可能是一次进行所有更改的方法。
I think the Quick and Simple Text Selection extension , as referenced in this tip on Smart Select may be able to help.我认为Quick and Simple Text Selection extension ,正如Smart Select 的这个技巧中所引用的那样,可能会有所帮助。
With the extension installed, if you want to replace {
with (
:安装扩展程序后,如果要将
{
替换为(
:
{
s{
s 内的某处 When I tried this, it worked but formatting was whacky, so perhaps not exactly what we're looking for...当我尝试这个时,它起作用了,但格式很奇怪,所以也许不是我们正在寻找的......
In your case, it looks like you want to wrap the { type: HIDE_SERVER_ERRORS, }
with parens, which is even easier - click inside, Use Ctrl + k , Shift + } to grab the parens included, and then ( to wrap that in parens... or mix & match as necessary...在您的情况下,您似乎想用括号包裹
{ type: HIDE_SERVER_ERRORS, }
,这更容易 - 单击内部,使用Ctrl + k , Shift + }抓取包含的括号,然后(将其包裹在括号...或根据需要混合和匹配...
(I think Smart Select can do the same thing on its own, but it takes more machinations/steps/combinations...) (我认为 Smart Select 可以自己做同样的事情,但它需要更多的谋划/步骤/组合......)
Not 100% convenient, but in some more complicated scenarios, this should be much better than trying to select/match the braces yourself.不是 100% 方便,但在一些更复杂的场景中,这应该比尝试自己选择/匹配大括号要好得多。
You may also use Regex:您也可以使用正则表达式:
Find: funcName\\('([\\s\\S\\r]*?)'\\)
查找:
funcName\\('([\\s\\S\\r]*?)'\\)
Replace: funcName['$1']
替换:
funcName['$1']
it will replace things like funcName('test')
to funcname['test']
它会将
funcName('test')
类的内容替换为funcname['test']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.