Is there any shortcut to select the current line in Visual Studio?
Visual StudioShortcutVisual Studio Problem Overview
I couldn't find such feature in VS's shortcut list. Is there anyway?
Visual Studio Solutions
Solution 1 - Visual Studio
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]
Solution 2 - Visual Studio
Clicking the line 3 times does the trick
Solution 3 - Visual Studio
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.
Solution 4 - Visual Studio
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.
Solution 5 - Visual Studio
If you click once on the row number the entire row will be selected.
Solution 6 - Visual Studio
- Clicking anywhere on the line and (CRTL + C) will copy entire line.
- Clicking three time in quick succession also selects entire line.
Solution 7 - Visual Studio
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.
Solution 8 - Visual Studio
Use the following:
Shift + End If cursor is at beginning of line.
or
Shift + Home If cursor is at the end of the line.
Alternatively, if you use resharper, you can also use the following
Ctrl + w while the cursor is positioned on the line you want to select
Solution 9 - 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.)
Solution 10 - Visual Studio
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.
Solution 11 - Visual Studio
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:
Tested in VS 2022.
Solution 12 - Visual Studio
If you want to select full row Ctrl E + U
Solution 13 - 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
Solution 14 - Visual Studio
a work around for this:
ctrl+d = duplicate line
ctrl+l = copy line
ctrl+v = paste copied text
Solution 15 - Visual Studio
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
Solution 16 - Visual Studio
You can set a bind to the Edit.ExpandSelection
command:
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.