相关技巧
主页 > 网络编程 > 相关技巧 >

vscode中模糊搜索和替换案例介绍

2024-06-20 | 佚名 | 点击:

调出搜索(快捷键)

单文件

ctrl + f // 搜索
ctrl + h // 搜索替换

全局

ctrl + shift + f
ctrl + shift + h

使用正则(快捷键)

alt + r

替换(快捷键) 逐个:enter所有:ctrl + alt + enter

在这里插入图片描述

案例

假设给定文本如下

1

2

3

4

5

6

7

8

9

10

11

12

13

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)

在这里插入图片描述

解释

其中(.*?)表示模糊匹配

目标2:替换所有函数名为hello

export function (.*?)(data)
export function hello(data)

在这里插入图片描述

解释:

目标3:给url增加查询字符串参数

‘/courses/(.*?)’
‘/courses/$1?username=test’

在这里插入图片描述

原文链接:
相关文章
最新更新