vscode中模糊搜索和替换

文章目录

调出搜索(快捷键)

  1. 单文件

    ctrl + f // 搜索

    ctrl + h // 搜索替换

  2. 全局

    ctrl + shift + f

    ctrl + shift + h

使用正则(快捷键)

alt + r

替换(快捷键)

  1. 逐个:enter
  2. 所有:ctrl + alt + enter

案例

假设给定文本如下
js 复制代码
import axios from 'axios';

export function queryInstitutionList(data) {
  return axios.post<any[]>('/courses/query', data);
}

export function updateInstitutionList(data) {
  return axios.post<any[]>('/courses/update', data);
}

export function insertInstitutionList(data) {
  return axios.post<any[]>('/courses/insert', data);
}

export function deleteInstitutionList(data) {
  return axios.post<any[]>('/courses/delete', data);
}
目标1:查找所有函数名

规则:在export function(data)之间的

export function (.*?)(data)

解释

  1. 其中(.*?)表示模糊匹配
    1. .表示匹配除换行符之外任意字符
    2. *?表示非贪婪匹配,如果要贪婪匹配使用*表示任意次+表示至少一次
  2. \(\)表示括号的转义
目标2:替换所有函数名为hello

export function (.*?)(data)

export function hello(data)

解释:

  1. 其中$1表示模糊匹配的占位符,如果有多个则是$1 $2 $3 ....
  2. 替换的时候括号就不需要转义了
目标3:给url增加查询字符串参数

'/courses/(.*?)'

'/courses/$1?username=test'

相关推荐
还有你Y9 小时前
VScode远程连接docker容器教程
ide·vscode·docker
Kaze-112 小时前
VSCode Copilot无法连接网络的解决过程
ide·vscode·copilot
屿筱13 小时前
vscode 关于C/C++的环境配置
c++·ide·vscode
2401_853448231 天前
K210环境搭建(VsCode)
vscode·踩坑·k210环境搭建
祎直向前1 天前
重装Ubuntu之后重连VSCode
linux·vscode·ubuntu
我命由我123451 天前
VSCode - VSCode 修改文件树缩进
前端·ide·vscode·前端框架·编辑器·html·js
white-persist1 天前
VSCode 快捷键大全:从设计理念到场景化高效运用(详细解析)(文章末尾有vim快捷键大全)
linux·ide·vscode·python·编辑器·系统安全·vim
我命由我123451 天前
VSCode - VSCode 颜色值快速转换
前端·ide·vscode·前端框架·编辑器·html·js
F***E2391 天前
SQL中的REGEXP正则表达式使用指南
数据库·sql·正则表达式