In SQL Server Management Studio 2008, I tends to write a lot of queries in a single window and execute a single line of them whenever I need. Hence a shortcut to highlight a sentence is kind of helping a lot.
I've tried all combination of the following but no luck.
Ctrl+Alt+Down
Ctrl+Shift+Down
Alt+Shift+Down
Shift + End -- selects the entire line after the cursor.
To find this out, press CTRL+L to display the estimated query execution plan as shown below without actually running the whole query (in fact it runs for top 1 row).
The key combination of "CTRL+R" is used to show or hide the query results pane. Sometimes we do not require a query results pane and therefore it can be hidden using the keyboard shortcut keys "CTRL+R". However, there is no direct option to hide this pane.
This selects the whole line as well:
CTRL + KU
Note that if the line is commented, it also removes the comment
Building on @iagowp's clever suggestion of using a side-effect of the Uncomment command, you can assign the shortcut key of your choice for selecting a line.
I use Ctrl+L.
By default this is mapped to Edit.LineCut in some SSMS editors. I use Ctrl+X for that, so I remapped it, but you can choose any key combination you like.
It's worth going over how to assign shortcut keys, as it's really, really easy but can be confusing at first. I'm very glad I made the effort, as it's a doddle now and having relevant shortcuts can be a real boost. These are the steps:
Show commands containing
and (remembering we're going to map a key to the Uncomment Selection command) start to type "uncomment" till the command is selected in the list below:Here we see that this command can be executed in the DataWarehouse Designer using the shortcut Ctrl+K, Ctrl+U
. We see that the same shortcut can be used in the Text Editor. Finally, we see that the same shortcut can be used anywhere in SSMS (it's Global), so in fact these specific mappings for DataWarehouse Designer and Text Editor are redundant (which we could demonstrate by removing them, using the button alongside—but we won't do that just now.)
Press shortcut keys
, click the box to give it focus, then press your chosen shortcut keys on the keyboard (Ctrl+L
in this example):Our desired shortcut may well already be in use, and the final dropdown shows any existing commands it's mapped to. Here we see that Ctrl+L
is used for Edit.LineCut in one designer, and for the same command in one editor, but for something quite different in SQL Query Editor. It has no Global mapping at present.
Alongside the Press shortcut keys
box is the Assign button. Before pressing Assign to map the new shortcut to the command, there's one final choice to make. In the Use new shortcut in
dropdown on the left, we can control the scope of the shortcut. We could choose Global, but since it's overriden in SQL Query Editor, our shortcut wouldn't then work in that editor. For this example, we'll choose SQL Query Editor.
(At this point the Press shortcut keys
part has to be done again. Normally it's best to set the scope first, which avoids this glitch. The sequence we followed in this example was just for introducing the concepts.)
As a final check, if we enter the shortcut keys one last time and open the dropdown, we can see that SSMS has replaced the previous SQL Query Editor mapping with our new one.
We're good to go! From now on, pressing Ctrl+L with no selection will select the current line in SQL Query Editor.
Home Shift+End would do it. I doubt there is a need for anything shorter
By the way, you can copy (or cut) an entire line by just pressing CTRL+C and CTRL+X without having any selection.
Same should work in Visual Studio and other good text editors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With