Reputation: 1815
I couldn't find such feature in VS's shortcut list. Is there anyway?
Upvotes: 68
Views: 95740
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
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:
Shift
+ Alt
+ +
)Shift
+ Alt
+ -
)Shift
+ Alt
+ ´
)Shift
+ Alt
+ E
)For a more granular selection of subwords there are also:
Ctrl
+ Shift
+ Alt
+ RightArrow
)Ctrl
+ Shift
+ Alt
+ LeftArrow
)There are also commands for navigating between subwords:
Ctrl
+ Alt
+ RightArrow
)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
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
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
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
Reputation: 1233
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.
Upvotes: 1
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:
Tested in VS 2022.
Upvotes: 5
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
Reputation: 315
a work around for this:
ctrl+d = duplicate line
ctrl+l = copy line
ctrl+v = paste copied text
Upvotes: 0
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
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
Reputation: 374
If you click once on the row number the entire row will be selected.
Upvotes: 13
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
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
Reputation: 241
Upvotes: 8
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
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
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