I couldn't find such feature in VS's shortcut list. Is there anyway?
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]
CTRL+X
behaviour, sometimes I push CTRL+Z
but miss and now I'm missing the whole line. My fault, but still. –
Quartering 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.
If you click once on the row number the entire row will be selected.
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.
To select the whole line use the below shorcut
Shift + Alt + E
- Clicking anywhere on the line and (CRTL + C) will copy entire line.
- Clicking three time in quick succession also selects entire line.
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.
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
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.
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.)
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.
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
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.
If you want to select full row Ctrl E + U
a work around for this:
ctrl+d = duplicate line
ctrl+l = copy line
ctrl+v = paste copied text
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
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.
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.
I assigned a shortcut key to the following functionality. I press the shortcut until it selects the whole current line:
Edit.SubwordExpandSelection
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.
© 2022 - 2024 — McMap. All rights reserved.