demaxSH
demaxSH

Reputation: 1815

Is there any shortcut to select the current line in Visual Studio?

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

Upvotes: 68

Views: 95740

Answers (21)

Mwiza
Mwiza

Reputation: 8961

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

Upvotes: 7

Johnson
Johnson

Reputation: 358

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.

Upvotes: 0

Miltos
Miltos

Reputation: 141

To select the whole line use the below shorcut

Shift + Alt + E

Upvotes: 11

Hamed Homaee
Hamed Homaee

Reputation: 73

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

Edit.SubwordExpandSelection

Upvotes: 0

Wajahath
Wajahath

Reputation: 4008

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.

Upvotes: 0

Sanketsz
Sanketsz

Reputation: 138

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.

Upvotes: 0

KulaGGin
KulaGGin

Reputation: 1233

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.

Upvotes: 1

Moon
Moon

Reputation: 156

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.

Upvotes: 5

Delsilon
Delsilon

Reputation: 157

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

Upvotes: 0

Or Shalmayev
Or Shalmayev

Reputation: 315

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

Upvotes: 0

Marcin Swornowski
Marcin Swornowski

Reputation: 72

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.)

Upvotes: 3

Chris Catignani
Chris Catignani

Reputation: 5306

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

Upvotes: 1

Necvetanov
Necvetanov

Reputation: 374

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

Upvotes: 13

Mitch Wheat
Mitch Wheat

Reputation: 300549

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]

Upvotes: 60

Valentin Anghel
Valentin Anghel

Reputation: 805

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.

Upvotes: 1

Syed Ali
Syed Ali

Reputation: 241

  • Clicking anywhere on the line and (CRTL + C) will copy entire line.
  • Clicking three time in quick succession also selects entire line.

Upvotes: 8

cocoaNoob
cocoaNoob

Reputation: 439

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.

Upvotes: 7

V.B.
V.B.

Reputation: 69

If you want to select full row Ctrl E + U

Upvotes: 0

ZYX
ZYX

Reputation: 834

Clicking the line 3 times does the trick

Upvotes: 42

Mr_Green
Mr_Green

Reputation: 41832

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.

Upvotes: 11

abhilash
abhilash

Reputation: 5651

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.

Upvotes: 18

Related Questions