THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Andrew Kelly

Seldom Used Keyboard Tricks


I was giving an internal talk on SSMS productivity trips and there were a few that I believe are seldom used but can be a real time or keystroke saver that I would like to mention. To the best of my knowledge these will work in any version of SSMS from at least 14.0 onward and likely earlier but I can’t verify older versions at this time. Since these are basically Visual Studio shortcuts they also work in Visual Studio and SSDT to the best of my knowledge. The first is the ability to select text in a vertical fashion as shown in the examples below. Before we get to how to do that I know your first question is why would you want to do that. Well I will leave all the possibilities up to you since everyone has slightly different techniques and circumstances. However I am confident that after seeing a few examples it will spark interest in many of you and you will immediately think of times when this will help you code more efficiently.

OK now on to the HOW to do this. That part is really pretty simple and there are two ways that I know of off hand. BTW, I am sure that after playing with this for just a few minutes you will have figured it all out anyway but I will post some instructions and examples just the same. The first way is to position your mouse cursor on the line at the point in which you want to start. Then you can use your keyboard and press SHIFT – ALT and then use the arrow keys as you see fit. Or you can press only the ALT key and move your mouse in the direction you wish to highlight or operate on. Both techniques mentioned will give you the same results. I find the mouse method a little easier overall but YMMV. I will use the block of code shown directly below as the basis for most of the subsequent examples.


Keep in mind that there are 2 types of processes or operations that you might use this for. The first is typically used when you want to insert something into existing code at a certain spot but across multiple lines at once. The example directly below shows what that would look like when selecting the rows at a specific position or insertion point. If I placed my cursor just in front of the number 1 in the first row and then pressed SHIFT – ALT – Down Arrow 7 times I would get a thin (in this case blue) line like the one with the arrow pointing to it. More on this technique shortly.



However if I needed to use the second type of operation I would take that one step further and move my cursor / mouse left or right to highlight one or more characters in each row as shown below.


Once I have highlighted a set of rows / columns I can then replace that highlighted text with new text of my choosing in a number of ways. If I had something in my clipboard I can do a paste and all of the highlighted sections in each row will be replaced with the clip board contents.  OK I hear someone saying well you could have just done a search and replace. Well sure but if you look closely you will see each character that I had highlighted in the vertical column was a different value in each row. I would have had to do 8 different search and replaces instead of just one using this method. Or I can simply start typing and you will see the original text is instantly replaced with what ever I type as shown in the partially completed replacement below.


Another great benefit of this technique is that you can be selective in which blocks of code you want the text replaced or acted upon. For instance I want to operate on only 4 of the 8 lines of code. If I did a search and replace I would have to do this one line at a time and choose which line I wanted to act upon and which I wanted left alone.


Here I selected the middle 4 lines and upper cased the word select. How did I do that? Well this technique also works with standard keyboard short cut’s such as Ctrl- Shift-U which will upper case what ever is highlighted as I did below.  I am sure you can begin to see the possibilities of this technique.



In this example shown below I use the other technique mentioned earlier to position the cursor at a certain place vertically across what ever rows I need.


I often have to terminate a number of rogue processes at the spur of the moment and this technique comes in very handy for that. I can identify the session_id’s using something like sp_whoisactive but when there are multiple sessions it can get tedious and error prone to manually type the “KILL nnn” commands for each one. Now I can simply copy the list of session_id’s and paste them into a query window and set the insertion point directly in front of all the session_id’s at once. Now I simply type “KILL “ and it instantly fills this in at the correct spot before all the lines at once. Again this is impossible to do with search and replace as each row is different text. Now all I had to do is execute the batch and smile as I rest assured the SQL Server instance is once more safe from these rogue processesSmile.  Obviously you will find more uses for this based on your own environment but I think you get the idea.


And finally I wanted to point out that if you are using the pure keyboard method don’t forget to use the SHIFT along with the ALT. If you simply press just the ALT key plus an up or down arrow you will shift the line the cursor is on up or down one line for each arrow press. The example below shows what happens if the cursor was anywhere on line 3 and the ALT and up arrow key was pressed. While that tip can certainly come in handy as well it may not do what you expect. If you use the ALT and Mouse method this will not happen.



I realize this was a long winded set of examples but I had fun outlining them. This is a very under utilized set of features that is built into some of your most important daily tools so remember to take advantage of them. I have also include a few links to some more extensive lists of short cuts for SSMS that you should find useful.

BOL SSMS Keyboard Shortcuts

Andy Mallon’s SSMS Keyboard Shortcuts

Red-Gate SSMS Keyboard Shortcuts




Published Thursday, June 22, 2017 10:48 AM by Andrew Kelly

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS


No Comments

Leave a Comment


This Blog


Privacy Statement