Visual Studio中有没有选择当前行的快捷方式?

发布于 2024-11-10 08:26:41 字数 34 浏览 3 评论 0原文

我在VS的快捷方式列表中找不到这样的功能。到底还有吗?

I couldn't find such feature in VS's shortcut list. Is there anyway?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

短叹 2024-11-17 08:26:41

如果您想复制一行,只需将光标放在该行的某个位置并按 CTRL+C

要剪切整行CTRL+X

@Sean 找到了我正在寻找的内容:

要禁用此默认行为,请删除复选标记(或检查以重新启用)

没有选择时将剪切或复制命令应用于空白行

从菜单栏访问:工具 |选项|文本编辑器 |所有语言

您还可以在选项搜索框中输入copy以更快地访问

[在VS2008、2010、2017中测试]

If you want to copy a line, simply place cursor somewhere in that line and hit CTRL+C

To cut an entire line CTRL+X

@Sean found what I was looking for:

To disable this default behavior remove the checkmark (or check to re-enable)

Apply cut or copy commands to blank lines when there is no selection

Accessed from the menu bar: Tools | Options | Text Editor | All languages

You can also enter copy into the options search box for quicker access

[Tested in VS2008, 2010, 2017]

盛夏尉蓝 2024-11-17 08:26:41

单击该线 3 次即可解决问题

Clicking the line 3 times does the trick

那一片橙海, 2024-11-17 08:26:41

如果您有 ReSharper,您可以使用

Ctrl + W
- 扩展选择

旁注:您可能需要多次使用它,具体取决于当前文本光标位置的上下文。

If you have ReSharper you could use

Ctrl + W
- Extend Selection

Sidenote: You may have to use it multiple times depending on the context of your present text cursor position.

妄司 2024-11-17 08:26:41

如果您单击行号一次,则整行将被选中。

If you click once on the row number the entire row will be selected.

电影里的梦 2024-11-17 08:26:41

如果您想选择,您可以使用ctrl + E然后的组合U。此组合也适用于取消注释整行或多行。这种组合看起来有点奇怪,但很快就会习惯的:)

您还可以使用 Ctrl + X 来剪切整行。同样,您可以使用 Ctrl + C 复制整行。
只要您没有选择任何内容,这些命令就会在整行上起作用。

If you want to select a line or lines you can use the combination of ctrl + E then U. This combination also works for uncommenting a complete line or lines. This combination looks somewhat strange to work with, but it will get habituated very soon :)

You can also use Ctrl + X to cut an entire line. Similarly, you can use Ctrl + C to copy an entire line.
As long as you don't have anything selected, these commands will work on the entire line.

假装爱人 2024-11-17 08:26:41

要选择整行,请使用以下快捷键

Shift + Alt + E

To select the whole line use the below shorcut

Shift + Alt + E
缱倦旧时光 2024-11-17 08:26:41
  • 单击该行上的任意位置并 (CRTL + C) 将复制整行。
  • 快速连续单击三次也会选择整行。
  • Clicking anywhere on the line and (CRTL + C) will copy entire line.
  • Clicking three time in quick succession also selects entire line.
遗忘曾经 2024-11-17 08:26:41

有一个简单的方法,只需使用 Home 或 End 按钮到达行的开头或结尾,然后根据光标所在的位置使用 home + Shift 或 end + Shift 。希望有帮助。

There is a simple way of doing it, simple use Home or End button to reach the start or end of line, and then use home + shift or end + Shift depending on where your cursor is. Hope it helps.

幽蝶幻影 2024-11-17 08:26:41

使用以下命令:

Shift + End 如果光标位于行首。

Shift + Home 如果光标位于行尾。

使用 resharper Ctrl + w

注意:如果在光标位于要选择的行上时

Use the following:

Shift + End If cursor is at beginning of line.

or

Shift + Home If cursor is at the end of the line.

Note: If you use resharper

Ctrl + w while the cursor is positioned on the line you want to select

甜心小果奶 2024-11-17 08:26:41

其他答案需要使用鼠标或点击多个组合。
因此,我为那些想要类似 VSCode 的 Ctrl+L 行为的人创建了一个宏。它可以选择多行,这对于移动代码块很有用。

要使用它,请安装宏的 Visual Commander 扩展: https://marketplace.visualstudio.com/ items?itemName=SergeyVlasov.VisualCommander

然后创建一个新命令,选择 C# 作为语言并粘贴此代码:

using EnvDTE;
using EnvDTE80;

public class C : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        var ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
        if (!ts.ActivePoint.AtStartOfLine)
            ts.StartOfLine();
        ts.LineDown(true, 1);
    }
}

现在您可以在首选项中分配所需的快捷方式:

在此处输入图像描述

在 VS 2022 中测试。

Other answers require either using a mouse or hitting more than one combination.
So I've created a macro for those who want a VSCode-like Ctrl+L behaviour. It can select multiple lines, and that's useful for moving blocks of code.

To use it, install Visual Commander extension for macros: https://marketplace.visualstudio.com/items?itemName=SergeyVlasov.VisualCommander

Then create a new command, select C# as a language and paste this code:

using EnvDTE;
using EnvDTE80;

public class C : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        var ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
        if (!ts.ActivePoint.AtStartOfLine)
            ts.StartOfLine();
        ts.LineDown(true, 1);
    }
}

Now you can assign a desired shortcut in preferences:

enter image description here

Tested in VS 2022.

凉栀 2024-11-17 08:26:41

这无法解决 Visual Studio 的问题,但如果您使用的是 Visual Studio Code,则可以使用 CTRL+L 选择光标当前所在的行。

(如果您使用的是 Visual Studio,这将剪切您当前所在的行,这也可能有用,但不是问题所在。)

This won't solve the problem for Visual Studio, but if you're using Visual Studio Code you can use CTRL+L to select the line your cursor is currently on.

(If you're using Visual Studio, this will cut the line you're currently on—which may also be useful, but wasn't the question.)

胡渣熟男 2024-11-17 08:26:41

您可以使用 CTRL + U 。此快捷方式也可用于取消注释。

您可以更改此功能的快捷方式。转到“工具”->“选项”->“环境”->“键盘”->“Edit.UncommentSelection”并指定 CTRL+W(与 Resharper 相同),或者您可以使用您想要的快捷方式。

You can use CTRL + U . This shortcut is use also for uncomment.

You can change the shortcut on this feature. Go to Tools->Options->Environment->Keyboard->Edit.UncommentSelection and assign CTRL+W (same as Resharper) or you can use what shortcut do you want.

捶死心动 2024-11-17 08:26:41

只需单击左边距即可。

如果单击大纲扩展左侧的空白处 [+][-]
它将选择该行。

您也可以通过单击并拖动来选择多行。
Necvetanov 在上面关于点击行号的回答中回避了这一点。
这是正确的...但恰好行号在页边空白处。

以下是键盘快捷键的完整列表 Visual Studio 中的默认键盘快捷键

Just click in the left margin.

If you click in the margin just left of the Outline expansions [+][-]
it will select the row.

You can also just click and drag to select multiple lines.
Necvetanov eluded to this in his answer above about clicking on the line number.
This is right...but it just happens that the line number is in the margin.

Here is a whole list of the keyboard shortcuts Default keyboard shortcuts in Visual Studio

淡看悲欢离合 2024-11-17 08:26:41

您可以设置与 Edit.ExpandSelection 命令的绑定:
输入图片此处描述

在选项中。单击快捷方式,直到选择整行。

上面的截图来自 Edit > Visual Studio 2022 中的高级 菜单。我自己设置了这个 Alt+E, E 快捷键,但我不记得它最初是否设置为某些内容。

You can set a bind to the Edit.ExpandSelection command:
enter image description here

In the options. Click the shortcut until it selects the whole line.

The screenshot above is from the Edit > Advanced menu in Visual Studio 2022. I set this Alt+E, E shortcut myself and I don't remember if it's originally set to something or not.

故事未完 2024-11-17 08:26:41

如果要选择整行 Ctrl E + U

If you want to select full row Ctrl E + U

稀香 2024-11-17 08:26:41

解决此问题的方法:
ctrl+d = 重复行
ctrl+l = 复制行
ctrl+v = 粘贴复制的文本

a work around for this:
ctrl+d = duplicate line
ctrl+l = copy line
ctrl+v = paste copied text

无人接听 2024-11-17 08:26:41

您也可以输入 home,然后输入 shift + end。它的作用是将您带到行的开头,然后选择整行直到行尾。或者先输入 end 然后输入 shift + home

You can enter, home then shift + end as well. What it will do is take you to the beginning of line then select the whole line till end. Or alternatively first enter end then shift + home

诺曦 2024-11-17 08:26:41

只需单击 VS-Code 左侧显示的行号即可。只需单击一下即可选择一行。

Simply by clicking on the line number that's being shown on the left in vs-code. just a single click and a line will get selected.

梦幻的味道 2024-11-17 08:26:41

在 Mac 中,它是 +L

但如果您有一些特定的冲突键绑定,则这将不起作用。就我而言, VSCode Live Server 扩展自动注册了这些绑定的几个绑定键。我删除了它们并且它起作用了。

In Mac, it is +L.

But if you have some specific conflicting keybindings, this won't work. In my case the VSCode Live Server extension auto registered a couple of bindings for these keys. I removed them and it worked.

飘逸的'云 2024-11-17 08:26:41

我为以下功能分配了快捷键。我按下快捷键,直到它选择整个当前行:

Edit.SubwordExpandSelection

I assigned a shortcut key to the following functionality. I press the shortcut until it selects the whole current line:

Edit.SubwordExpandSelection
一绘本一梦想 2024-11-17 08:26:41

虽然 KulaGGin 和 Miltos 已经回答了您的具体问题,但请允许我提供有关单词、行和块选择/导航的更全面的更新。至少在 Windows 版本的 Visual Studio 2022 中,现在可以在文本编辑器上下文中使用各种命令来执行选择:

  • Edit.ExpandSelection(默认值:Shift + Alt + +)
  • Edit.ContractSelection (默认值:Shift + Alt + -)
  • Edit.ExpandSelectiontoContainingBlock (默认值: Shift + Alt + ´)
  • Edit.ExpandSelectionToEntireLine(默认:Shift + Alt + E

为了更精细地选择子词,还有:

  • Edit.NextSubwordExtend(默认:Ctrl+ Shift + Alt< /代码> + RightArrow)
  • Edit.PreviousSubwordExtend(默认:Ctrl+ Shift + Alt + LeftArrow )
  • Edit.SubwordExpandSelection(默认:无快捷方式)
  • Edit.SubwordContractSelection(默认:无快捷方式)

还有用于在子词之间导航的命令:

  • Edit.NextSubword(默认:Ctrl+ Alt + RightArrow)
  • Edit.PreviousSubword(默认:Ctrl+ Alt + LeftArrow

如果有人需要自定义快捷方式,请导航至:
工具 ->选项->环境->键盘

请注意,Mac 版本可能提供一组完全不同的功能。

While KulaGGin and Miltos already answer your specific question, allow me to give a more holistic update regarding word, line and block selection/navigation. At least in the Windows version of Visual Studio 2022 there are now various commands usable in the context of a text editor to perform selection:

  • Edit.ExpandSelection (default: Shift + Alt + +)
  • Edit.ContractSelection (default: Shift + Alt + -)
  • Edit.ExpandSelectiontoContainingBlock (default: Shift + Alt + ´)
  • Edit.ExpandSelectionToEntireLine (default: Shift + Alt + E)

For a more granular selection of subwords there are also:

  • Edit.NextSubwordExtend (default: Ctrl+ Shift + Alt + RightArrow)
  • Edit.PreviousSubwordExtend (default: Ctrl+ Shift + Alt + LeftArrow)
  • Edit.SubwordExpandSelection (default: no shortcut)
  • Edit.SubwordContractSelection (default: no shortcut)

There are also commands for navigating between subwords:

  • Edit.NextSubword (default: Ctrl+ Alt + RightArrow)
  • Edit.PreviousSubword (default: Ctrl+ Alt + LeftArrow)

If anyone needs to customize the shortcuts navigate to:
Tools -> Options -> Environment -> Keyboard

Note that the Mac version might offer a completely different set of features.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文