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

21

66

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

Unless answered 28/5, 2011 at 3:2 Comment(3)
Home, Shift+End? :)Haddad
@AssafLavie Sometimes you have to press "Home" 2 times and sometimes one, so is not idempotent (aka can't use muscle memory) so is less than idealEelpout
Maybe consider updating the selected answer as this feature (along others) is now available in Visual Studio.Harri
A
59

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]

Ardoin answered 28/5, 2011 at 3:17 Comment(10)
I hate the CTRL+X behaviour, sometimes I push CTRL+Z but miss and now I'm missing the whole line. My fault, but still.Quartering
@todda.speot.is: disable "apply cut or copy commands to blank lines when there is no selection" in Tools | Options | Text Editor | All languages.Perdition
The whole point of this is not to use the mouse I don't understand why this is the most voted answerIgbo
@ Kepol : who says you need to use the mouse?Ardoin
This is not what the question asked, instead this is specifically to cut and copy.Eelpout
@Ivan Castellanos: and why would you select a line if you weren't going to do something with it? LOLArdoin
@MitchWheat The things one wants do with multiple lines arent limited to copy and cut, besides how do I cut MULTIPLE lines with this method? you can'tEelpout
@ Ivan Castellano: your response has nothing to do with the question asked.Ardoin
@MitchWheat Neither does yours, the question never mentions copy or pasting but somehow this got selected as the "accepted" answerEelpout
I refer you to my previous comments. Moving along....Ardoin
C
39

Clicking the line 3 times does the trick

Cordle answered 29/10, 2013 at 3:41 Comment(0)
R
17

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.

Roundup answered 28/5, 2011 at 3:44 Comment(0)
E
13

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

Excusatory answered 18/8, 2017 at 11:35 Comment(0)
I
11

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.

Ixion answered 9/10, 2012 at 6:49 Comment(3)
Neat! I never realized the 'uncomment' hotkey can also be used for that. My search-replace on a single line suddenly became 10% faster.Benedictbenedicta
I use Crtl + K, C and Ctrl + K, U all the time, but good call on Ctrl + E, USynchroscope
This doesn't work too well when the line is a comment line.Bertabertasi
J
9

To select the whole line use the below shorcut

Shift + Alt + E
Johppa answered 6/4, 2023 at 8:2 Comment(2)
Out of all the answers on this page, this is the only one that worked for me. Maybe it's because I'm using the Visual C++ mapping scheme? Either way, the command to select a line is Edit.ExpandSelectionToEntireLine if you want to look it up and/or change it in the Tools>Customize>Keyboard or Tools>Options>Environment\Keyboard menu.Gastrotrich
Thank you, this is the answer to the main question.Stringfellow
T
8
  • Clicking anywhere on the line and (CRTL + C) will copy entire line.
  • Clicking three time in quick succession also selects entire line.
Tedman answered 16/6, 2016 at 14:30 Comment(0)
H
7

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.

Hinojosa answered 9/1, 2014 at 7:58 Comment(0)
W
7

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

Wrier answered 30/5, 2018 at 13:57 Comment(0)
T
5

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.

Tenet answered 30/3, 2022 at 19:47 Comment(1)
Got kind of used to Ctrl+L in sublime text editor and this solution works exactly like that, thanks.Brendanbrenden
I
3

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

Incommensurable answered 4/6, 2020 at 18:17 Comment(0)
A
1

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.

Ary answered 22/2, 2017 at 17:39 Comment(0)
R
1

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

Radar answered 4/6, 2020 at 20:1 Comment(1)
This is the only thing that was close. Thank you.Tabescent
T
1

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.

Tellford answered 8/4, 2022 at 21:32 Comment(0)
P
0

If you want to select full row Ctrl E + U

Peacoat answered 29/10, 2013 at 10:58 Comment(1)
This doesn't work too well when the line is a comment line.Bertabertasi
D
0

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

Dressingdown answered 10/11, 2021 at 18:8 Comment(0)
P
0

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

Philosopher answered 9/2, 2022 at 6:49 Comment(0)
R
0

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.

Roxyroy answered 21/6, 2022 at 5:20 Comment(0)
A
0

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.

Amiamiable answered 25/1, 2023 at 18:18 Comment(0)
G
0

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

Edit.SubwordExpandSelection
Gasser answered 19/2, 2023 at 18:49 Comment(0)
H
0

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.

Harri answered 25/1 at 15:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.