Search code examples
keyboard-shortcutsvisual-studio-2019

Visual Studio - Keyboard-Shortcut: How do I select a line by shortcut


How do I select a line by shortcut?

My goal is e.g. to surround a specific code snippet with something like try/catch block:

Select line Key -> Shift+F10 -> s -> s -> t -> r -> y -> enter -> baammm.

I found I could do HOME and then shift+END, but the HOME and END button are far away. According to Visual Studio Shortcut Description (unstated to which version this is referencing to) it says Ctrl + L.

In my case (freshly downloaded VS without any changes made in any settings) Ctrl+L (i.e. Ctrl+Shift+l) is deleting the line, which is NOT selecting it. Ctrl+l is then deleting the line keeping its contents in the cache which is very basically Ctrl+x

According to Mr_Green in that similar question) it is Ctrl+E then U, which doesn't work either.

And then I found this: Tools -> Options -> Environment -> Keyboard Here I would think to find something like "Edit.SelectLine", but it's not there.


Solution

  • At least for Visual Studio 2022 there are now three commands usable in the context of a text editor:

    • Edit.ExpandSelection (default: Shift + Alt + +)
    • Edit.ExpandSelectiontoContainingBlock (default: Shift + Alt + ´)
    • Edit.ExpandSelectionToEntireLine (default: Shift + Alt + E)

    For more information about subword selection/navigation see my answer here.