这是我编写的一个扩展,它允许您将查找/替换保存在文件中或作为命名命令和/或键绑定搜索文件:Find and Transform。使用 OP 的原始问题,进行此设置(在 中settings.json
):
"findInCurrentFile": { // in settings.json
"reduceUserEntry": {
"title": "Reduce User to ...", // will appear in the Command Palette
"find": "CN=([^,]+).*",
"replace": "$1",
"isRegex": true,
// "restrictFind": "selections", // default is entire document
}
},
您还可以使用此设置对文件进行搜索:
"runInSearchPanel": {
"reduceUserEntry": {
"title": "Reduce User to ...", // will appear in the Command Palette
"find": "CN=([^,]+).*",
"replace": "$1",
"isRegex": true
// "filesToInclude": "${fileDirname}"
// "onlyOpenEditors": true
// and more options
}
}
作为独立的键绑定:
{
"key": "alt+r", // whatever keybinding you want
"command": "findInCurrentFile", // or runInSearchPanel
"args": {
"find": "CN=([^,]+).*",
"replace": "$1",
"isRegex": true
该扩展还可以运行多个查找/替换 - 只需将它们放入一个数组中:
"find": ["<some find term 1>", "<some find term 2>", etc.
与替换相同,将它们组成一个数组。