Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Management Studio keyboard shortcut to highlight entire line

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

like image 330
SuicideSheep Avatar asked Mar 04 '14 03:03

SuicideSheep


People also ask

What is the shortcut to select a whole line?

Shift + End -- selects the entire line after the cursor.

What is CTRL L in SSMS?

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).

What is CTRL R in SQL?

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.


4 Answers

This selects the whole line as well:

CTRL + KU

Note that if the line is commented, it also removes the comment

like image 66
iagowp Avatar answered Oct 17 '22 20:10

iagowp


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:

  1. From Tools, Options, select Keyboard (under Environment). There's a lot of magic on this dialog but for now, head straight for 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:

enter image description here

  1. Beneath the list we can see any shortcuts currently mapped to the command, and whether each mapping is Global. This is where things can start to seem confusing but if we open the dropdown of shortcuts for this command, things start to make sense:

enter image description here

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.)

  1. Under Press shortcut keys, click the box to give it focus, then press your chosen shortcut keys on the keyboard (Ctrl+L in this example):

enter image description here

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.

enter image description here

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.

enter image description here (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.

enter image description here

We're good to go! From now on, pressing Ctrl+L with no selection will select the current line in SQL Query Editor.

like image 42
Reg Edit Avatar answered Oct 17 '22 21:10

Reg Edit


Home Shift+End would do it. I doubt there is a need for anything shorter

like image 14
Martin Booth Avatar answered Oct 17 '22 20:10

Martin Booth


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.

like image 9
thepirat000 Avatar answered Oct 17 '22 22:10

thepirat000