简体   繁体   English

如何在 VS Code 中的同一文件的其他拆分选项卡中打开“转到定义”?

[英]How to open 'Go to definition' in other split tab for same file in VS Code?

I'm considerably new to Visual Studio Code and I am struggling a bit with an easy functionality.我对 Visual Studio Code 相当陌生,并且在使用简单的功能时遇到了一些困难。 Imagine the case when I am reviewing some code in a file a.py and I select 'Go to definition' on a function x of the same file.想象一下,当我查看文件 a.py 中的一些代码并在同一文件的函数 x 上选择“转到定义”时的情况。 Is there any possible configuration or shortcut that opens the definition on a split on the editor?是否有任何可能的配置或快捷方式可以在编辑器的拆分上打开定义?

I have tried having already the same file split in the editor an it still opens the definition in the same file what is uncomfortable when you have to trace some code because you need to scroll up and down whenever you want to see another function of the same file.我已经尝试在编辑器中拆分相同的文件,但它仍然会在同一个文件中打开定义,当您必须跟踪一些代码时会感到不舒服,因为每当您想查看另一个相同的功能时,您都需要上下滚动文件。

An extension that allows to do the trick will also be well received.一个允许这样做的扩展也将受到好评。 Thanks.谢谢。

There are 2 ways to achieve this.有两种方法可以实现这一点。

Either:任何一个:

  1. Left-click function name that you want to open.左键单击要打开的函数名称。
  2. Ctrl + t Ctrl + t
  3. Ctrl + enter Ctrl + 输入

Or:或者:

  1. Change setting Editor > Goto Location: Multiple to be gotoAndPeek or goto更改设置Editor > Goto Location: Multiple to be gotoAndPeek or goto
  2. Ctrl + Alt + [click on function name] Ctrl + Alt + [点击函数名]

Both methods will open the definition in the split to the right (or create a new split if this is the right-most split).两种方法都将打开右侧拆分中的定义(如果这是最右侧的拆分,则创建一个新拆分)。

You like?你喜欢?

快捷方式是 Ctrl+K, F12 但这可以在快捷方式中更改(搜索快捷方式 editor.action.revealDefinitionAside)更多详细信息在这里https://github.com/microsoft/vscode/issues/112136

[选项 + 命令 + 左键单击] 在拆分选项卡中打开定义。

For me setting workbench.editor.revealIfOpen to true like described here worked.对我来说,将workbench.editor.revealIfOpen设置为 true 就像这里描述的那样有效。

Controls whether an editor is revealed in any of the visible groups if opened.控制是否在任何可见组中显示编辑器(如果打开)。 If disabled, an editor will prefer to open in the currently active editor group.如果禁用,编辑器将更愿意在当前活动的编辑器组中打开。 If enabled, an already opened editor will be revealed instead of opened again in the currently active editor group.如果启用,将显示已打开的编辑器,而不是在当前活动的编辑器组中再次打开。 Note that there are some cases where this setting is ignored, eg when forcing an editor to open in a specific group or to the side of the currently active group.请注意,在某些情况下会忽略此设置,例如强制编辑器在特定组或当前活动组一侧打开时。

You have two different ways to do that task: First one is, with the cursor on the word that you want to go to definition, press Alt+F12 .您有两种不同的方法来完成该任务:第一种是将光标放在您想要定义的单词上,按Alt+F12 It opens a new tab like this one:它会打开一个像这样的新标签:

在此处输入图像描述

Second one is edit the settings and add this line:第二个是编辑设置并添加这一行:

"workbench.editor.enablePreview": false

It disables all the previews for code files so always that you want to go to definition, they will be open in a new tab, as you can see here:它禁用了代码文件的所有预览,因此您总是想去定义,它们将在新选项卡中打开,如您在此处看到的:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM