Reputation: 11188
I'm wondering if there's a keyboard shortcut in SSMS to surround a selected column name (or an uninterupted sequence of characters for the given cursor position) with the [ and ] chars.
So if I have user_id
and would press something like CTRL + SHIFT + [ + ]
it would turn into [user_id]
. Is there such a keyboard shortcut?
Upvotes: 8
Views: 5732
Reputation: 141
place cursor left of word to surround
Type [ then ctl-return
This will use auto-complete to surround the current word with square brackets.
***Works only if the current script is running in the appropriate database for auto-complete to find the name. {column, table, schema, etc.}
Upvotes: 1
Reputation: 31
I use an AutoHotKey script to do this. You can Google around to figure out how to set up AHK.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GET RID OF BRACKETS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; winkey + Z
#z::
ClipSaved := ClipboardAll
Send ^c
Clipwait
Sleep 100
str := clipboard
str := RegExReplace(str, "\[|\]") ; Match '[' or ']' - have to escape each with backslash - and replace with nothing
clipboard := str
Sleep 100
Send ^v
Clipboard := ClipSaved
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ADD BRACKETS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; winkey + V
#v::
ClipSaved := ClipboardAll
Send ^c
Clipwait
Sleep 100
str := clipboard
str := "[" . str . "]"
str := RegExReplace(str, "\.", "].[")
clipboard := str
Sleep 100
Send ^v
Clipboard := ClipSaved
return
Usage: highlight your text and press the corresponding hotkey. Currently these macros are set to use the Windows key + Z / V respectively but that can be changed easily.
The add brackets macro is a little finnicky in that it will add a bracket to the end and beginning of whatever you have selected, even if there is whitespace - that could be fixed but I personally haven't had trouble selecting exactly what I want.
Upvotes: 1
Reputation: 618
There's no keyboard shortcut out of the box that surrounds text in brackets, but you can you create your own using a custom snippet. You can check out this blog post to get clear steps but I'll list them briefly here.
Open notepad and paste in this xml. Save it as brackets.snippet:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<_locDefinition xmlns="urn:locstudio">
<_locDefault _loc="locNone" />
<_locTag _loc="locData">Title</_locTag>
<_locTag _loc="locData">Description</_locTag>
<_locTag _loc="locData">Author</_locTag>
<_locTag _loc="locData">ToolTip</_locTag>
<_locTag _loc="locData">Default</_locTag>
</_locDefinition>
<CodeSnippet Format="1.0.0">
<Header>
<Title>Brackets</Title>
<Shortcut>br</Shortcut>
<Description>Snippet for Brackets</Description>
<Author>SQL Super Hero</Author>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>OpenBracket</ID>
<Default>[</Default>
</Literal>
<Literal>
<ID>CloseBracket</ID>
<Default>]</Default>
</Literal>
</Declarations>
<Code Language="SQL"><![CDATA[$OpenBracket$$selected$$CloseBracket$$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
In SSMS, Go to Tools > Code Snippets Manager.
Click import. Find the Brackets.snippet file and click Open
Choose “My Code Snippets” as the location and click finish
Close and reopen SQL Server Management Studio
You should now be able to use the snippet to surround highlighted text in brackets. The keyboard shortcut to access the snippet is ctrl+k, ctrl+s
The most efficient way to do this is with the following sequence of key presses:
Highlight Desired Text > Ctrl+K,Ctrl+S > M > Enter > Enter > Enter
Upvotes: 13