使用 Visual Studio Code 重构局部变量名称 [英] Refactor local variable name using Visual Studio Code

查看:44
本文介绍了使用 Visual Studio Code 重构局部变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的情况.我想重构角色变量的名称:

I have this simple situation. I'd like to refactor the name of the role variable:

看起来 Visual Studio Code 足够聪明,知道不应触及 URL 中的角色".

It looks like Visual Studio Code is smart enough to know that "roles" in the URL should not be touched.

我只想在单个文件中重构变量的名称,在单个范围内,而不是整个文件,绝对不是多个文件!

I just want to refactor the name of the variable in a single file, in a single scope, not the whole file and definitely not multiple files!

如果我使用 Ctrl + H,它将带我进入一个菜单,该菜单默认重构多个文件或整个单个文件中的名称,但我只想在单个函数范围内重构名称!

If I use Ctrl + H, it will bring me to a menu which by default refactors the name in multiple files or a whole single file, but I just want to refactor the name in a single function scope!

推荐答案

使用 重命名符号 而不是标准的查找/替换.重命名默认绑定到 F2.

Use rename symbol instead of the standard find/replace. Rename is bound to F2 by default.

重命名符号将知道只接触示例中的本地 roles 引用.Visual Studio Code 附带对 JavaScript 和 TypeScript 的重命名支持.其他语言可能需要安装语言扩展.

Rename symbol will know to only touch the local roles references in your example. Visual Studio Code ships with rename support for JavaScript and TypeScript. Other languages may require installing a language extension.

这篇关于使用 Visual Studio Code 重构局部变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆