patternMinor
Shortcuts/Snippets to select a block of code
Viewed 0 times
snippetsblockshortcutscodeselect
Problem
I am using SQL Server Management Studio 2016 on Windows 10. I'm tired of using shift/ctrl+up/down/right/left keys to select the code I want to run. I'm wondering whether there are shortcuts/snippets to select a block of code that separated from other code by blank lines?
Here is a code example:
Say, my cursor is inside the middle block and what's the best way to select the middle block?
Here is a code example:
select *
from tab1
select *
from tab2
select *
from tab3Say, my cursor is inside the middle block and what's the best way to select the middle block?
Solution
Using Autohotkey, I was able to develop a solution to select a block of code and here is the script I have:
Specifically, pressing Alt + B will invoke this script, and the script will select the block of code where the cursor is in. Note that the block of code has to be separated from other blocks of code by blank lines, and the block of code cannot have blank of lines inside itself.
The key steps of the about script are
-
using regular expression "^\r$
" to locate the blank lines above and below the cursor
-
moving the cursor to these two blank lines one by one
-
using ctrl + = to select the block of code between these two blank lines.
Note that !/^/+ are alt/ctrl/shift separately.
!b::
send ^f
sendraw ^\r$
send {F3}
send +{F3}
send {Esc}
send {down}
send ^{=}
returnSpecifically, pressing Alt + B will invoke this script, and the script will select the block of code where the cursor is in. Note that the block of code has to be separated from other blocks of code by blank lines, and the block of code cannot have blank of lines inside itself.
The key steps of the about script are
-
using regular expression "^\r$
" to locate the blank lines above and below the cursor
-
moving the cursor to these two blank lines one by one
-
using ctrl + = to select the block of code between these two blank lines.
Note that !/^/+ are alt/ctrl/shift separately.
Code Snippets
!b::
send ^f
sendraw ^\r$
send {F3}
send +{F3}
send {Esc}
send {down}
send ^{=}
returnContext
StackExchange Database Administrators Q#166877, answer score: 4
Revisions (0)
No revisions yet.