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'

相关推荐
alpszero4 小时前
使用VSCode开发Django指南
vscode·python·django·sqlite
Wallace Zhang5 小时前
VScode - 我的常用插件01 - 主题插件Noctis
ide·vscode·编辑器
程序猿小D18 小时前
第22节 Node.js JXcore 打包
开发语言·人工智能·vscode·node.js·c#
面朝大海,春不暖,花不开19 小时前
使用 Python 正则表达式实现文本替换与电话号码规范化
python·mysql·正则表达式
至善迎风1 天前
Windows系统中如何使用符号链接将.vscode等配置文件夹迁移到D盘(附 CMD & PowerShell 双版本命令)
ide·windows·vscode
old_power1 天前
在 Windows 系统下配置 VSCode + CMake + Ninja 进行 C++ 或 Qt 开发
c++·windows·vscode·cmake·ninja
miachen-空中飞鸟1 天前
[BIOS]VSCode zx-6000 编译问题
ide·vscode·编辑器
cooldream20091 天前
在 Visual Studio Code 中使用驭码 CodeRider 提升开发效率:以冒泡排序为例
vscode·编辑器·驭码 coderider
BigData-01 天前
vscode vue debug
ide·vue.js·vscode
笑虾1 天前
Visual Studio Code 扩展
ide·vscode·编辑器