至少有三个扩展可以帮助你:
Find and Transform - 我写的
replace rules
regreplace
它们允许您存储和运行(单独或全部保存)正则表达式的查找和替换列表。
查找和替换的示例设置(settings.json):
"findInCurrentFile": {
"addClassToElement": {
"title": "Add Class to Html Element", // will appear in the Command Palette
"find": ">",
"replace": " class=\"@\">",
"restrictFind": "selections",
"cursorMoveSelect": "@" // after the replacement, move to and select this text
}
}
查找和替换中的键绑定示例(在 keybindings.json 中):
{
"key": "alt+y",
"command": "findInCurrentFile", // note no setting command here
"args": {
"find": "^([ \\t]*const\\s*)(\\w*)", // note the double escaping
"replace": "$1\\U$2", // capitalize the word following "const"
"isRegex": true,
"restrictFind": "selections" // find only in selections
}
}
因此,您可以将查找/替换或跨文件搜索保存为命名设置或键绑定。