如何移动到 VS Code 中的下一个/上一个变量引用? [英] How to move to the next/previous variable reference in VS Code?

查看:42
本文介绍了如何移动到 VS Code 中的下一个/上一个变量引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 中,使用 C# 时,我可以单击一个变量,按住 CTRL + SHIFT 并使用箭头键(向上和down)在当前打开的脚本中.

In Visual Studio, when working with C#, I can click on a variable, hold down CTRL + SHIFT and move between it's references using the arrow keys (up and down) inside the script that's currently open.

如何在使用 TypeScript 的同时在 VS Code 中执行这样的操作?

How can I perform such an action in VS Code while working with TypeScript?

推荐答案

我不会称它们为引用,因为该术语通常用于编辑器中的其他内容,您可以使用以下任何一种:

I wouldn't call them references since that terminology is usually used for other things in the editor, you can use any of the following:

editor.action.nextMatchFindAction 默认F3

editor.action.previousMatchFindAction 默认 SHIFT + F3

如果满足 findInputFocussed 条件(意味着您已经积极关注 find 输入 (CTRL + F) 您可以简单地使用 Enter 转到下一个匹配项并使用 SHIFT + Enter 转到上一个,或者您可以继续使用相同的 F3 绑定;它们和谐地工作.

If the findInputFocussed criteria is met (meaning you have actively focused on the find input (CTRL + F) you can simply use Enter to go to the next match and SHIFT + Enter for previous or you can continue to use the same F3 bindings; they work harmoniously.

您也可以将它们重新映射到您正在使用的内容,不必保留它F3

You could also just remap them to what you are using, don't have to keep it F3

对此方法的一个警告是,必须清除您的查找输入值才能使其工作如果您的词未被选中 并且已经存在一个查询这和这个词不一样.但是,如果您选择了 单词,它会自动将该单词放入查找输入框中 - 这与按 CTRL + F 当你的光标在一个字上时

A caveat to this approach is that your find input value must be cleared for this to work if your word is not selected and there is already an existing query that is not the same as the word. However, if your word is selected it will automatically put the word into the find input box - which is effectively the same thing as pressing CTRL + F when your cursor is in a word

与上面类似,没有查找/替换小部件,也没有那么多限制,但仅限于区域".

Similar to above, without the find/replace widget and not as many constraints, but it is limited to a 'region'.

此方法无限循环并且区分大小写.

This method cycles indefinitely and is case sensitive.

editor.action.wordHighlight.next 默认F7

editor.action.wordHighlight.prev 默认 SHIFT + F7

除了在 when表达式 仅在打字稿中工作,但是,为了连续性在您的工作区中使用相同的键绑定可能会很好,因为这些键绑定对于其他场景是相同的,例如当您在终端时,经销商的选择;也各有千秋.

You could override these to use CTRL+SHIFT+Navigation as you are used to if you wish, in addition to specifying the language id in the when expression to only work in typescript, though, it might be good to use the same keybindings across your workspaces for continuity since these keybinds are the same for other scenarios like when you are in the terminal, dealers choice though; too each their own.

这是一个示例快捷方式设置(如果要复制,则必须输入 keybindings.json):

Here's an example shortcut setting (you will have to put in your keybindings.json if you want to make a duplicate):

{
    "key": "ctrl+shift+down",
    "command": "editor.action.nextMatchFindAction",
    "when": "editorTextFocus && editorLangId == 'typescript'"
}

Typescript 支持符号,所以如果你想基于范围搜索,你可以使用:

Typescript supports symbols, so if you want to search based on scope you can use:

workbench.action.gotoSymbol 默认值 Ctrl+Shift+O

另一种相关方法是使用 CTRL + D 将下一个查找匹配添加到选择中,这会添加下一个找到的匹配并选择它进行编辑(想想多个光标)

Another related way is to add the next find match to a selection using CTRL + D which adds the next found match and selects it for editing (think multiple cursors)

commandId: editor.action.addSelectionToNextFindMatch

commandId: editor.action.addSelectionToNextFindMatch

这篇关于如何移动到 VS Code 中的下一个/上一个变量引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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