I am using SQL Server Management Studio and there are 5-10 lines of queries that I edit and execute a lot. I'm wondering whether there is a way that can quickly select a block of code? The code could start and end with some key words. For example:
--Start
line1
line2
--end
I searched the shortcut key webpage for Sql management studio and didn't find a quick solution.
The solution could either be a keyboard shortcut or some automatic script like autohotkey. A generic solution works with general text/code editor would be the best, since I also works with R/MATLAB and wondering whether there is a generic solution for selecting code.
Thanks in advance for your help!
Jason
Simple, general, autohotkey solution, working with notepad, bound to ctrl+b for testing purposes, do edit accordingly.
^b::
selectBlock(){
clipbackup:=clipboard
clipboard:=
Send ^a^c
ClipWait
Loop, parse, clipboard, `n, `r
{
if (SubStr(A_LoopField,1,7)="--Start")
s:=A_Index
if (s and SubStr(A_LoopField,1,5)="--end"){
e:=A_Index-1
break
}
}
if (s and e)
Send % "^{Home}{Down " s "}{Shift Down}{Down " e-s "}{Shift Up}"
else
Send {Left}
clipboard:=clipbackup
}
return
Side note, I'm not familiar with your software but I find it hard to imagine there are no better ways of doing it. For example using built in search tool that might even support regex as most "text editors" aimed at "coding" have. Or adopting above code to work with "go to X line" function of your program.
Related
I want to create a script that triggers when pressing Q twice while holding Alt, but couldn't figure out what're the correct key codes for that, could someone please shed some light?
P.S. I want to bind this shortcut to Ctrl+F12, which I assigned Sogou IME to turn on the Chinese input mode.
I didn't test this and there's probably a more concise way to do it, but I think something like this should work.
!Q::
If(keyPressed = 1){
...Do a thing...
}
keyPressed := 1
SetTimer, altQTimer, 50
return
altQTimer:
keyPressed := 0
return
TL;DR
In conclusion, even if I do all kinds of hacks and get the script working as intended, it's likely to break in the future, which is really not worth the trouble.
After hours of experimenting, the current conclusion is Sogou IME which uses Ctrl+F12 won't trigger the bound action i.e. switching to the Chinese input mode if it was sent by Alt+[Any Other Key], it can be triggered if it was sent by other shortcuts such as Ctrl+C, which is really unfortunate.
And the weirdest thing is the following code works:
^c::Send !q
!q::Send ^{F12}
And to rule out the potential extra simulated keystrokes (Ctrl by default) effect, the following code also works:
^!q::Send ^{F12}
But the following doesn't (tested on several machines):
!q::Send ^{F12}
Update
After much effort, I did get Alt+Q to turn on the Chinese input mode with the following code, not sure why:
!q::Send ^{F6}
^F6::Send ^{F7}
^F7::Send ^{F12}
But because I also need to trigger a VSCode command using Alt+Q at the same time, I had to modify the above code to the following:
~!q::Send ^{F6} ; with ~ prefixed
^F6::Send ^{F7}
^F7::Send ^{F12}
Now Alt+Q does trigger the VSCode command, but it won't turn on the Chinese input mode...
At last, if I take a step back and bind the VSCode command to Ctrl+C (which could turn on the Chinese input mode with just ^c::Send ^{F12}), I still have to prefix ^c with ~, otherwise it won't trigger the VSCode command, now I'm repeating the cycle all over again...
After all of these attempts, I have to say Sogou IME's logic for determining whether to enable the Chinese input mode is quite indeterminate, making the script for enabling the Chinese input mode very unreliable.
In conclusion, even if I do all kinds of hacks and get the script working as intended, it's likely to break in the future, which is really not worth the trouble.
I have the following AutoHotkey script sample, notice the code is indented by a single space:
#z::
MsgBox The Win-Z hotkey was pressed.
Gosub MySubroutine
return
MySubroutine:
Sleep 1000
return
I searched through the VS Marketplace but didn't find a usable formatter extension for AHK scripts.
I've configured "editor.tabSize": 2, is there a way to format the code to use the specified tabSize with the VSCode built-in formatter?
It looks like there is an AutoHotKey Plus extension that includes formatting that seems to adhere to the Visual Studio Code built-in formatter setting for the tab size. I set my tab size to two and performed the format shortcut using the extension (Shift + Alt + F):
It seems though that certain keywords, such as return will cling to the margin, presumably because the formatter for the extension interprets this as the standard convention for AHK (in my opinion though, I like the way it looks).
This feature request is tracked here.
How would one achieve the same result. I believe the keybinding for macOS Intellij is op+up/down and on windows it is alt+w/d.
Essentially the function highlights the current word, then, with successive presses, expands out to the full string/line/area in-between parenthesis/further out to the next set of parenthesis. Very useful for developing in LISP.
The closest I've gotten is this: https://vi.stackexchange.com/a/19028
Try this plug in: https://github.com/terryma/vim-expand-region
It expands selections based on Vim’s text objects.
Well this may seem comfortable but does not correspondent with the internal logic of vim itself.
See, in vim everything you enter is like a sentence. va{ for example: there is a verb v -> visually select and an object (or movement) { -> paragraph. In this case there is also a modifier a around. You can exchange stuff in this sentence and it will still work vaw, dil, cB and so on. The power of vim is greatly based on that concept.
Of course you can write a function that does vaw first, then S-v and lastly va{ but that will only work with visual selection. It will not work with c or d or anything. So I will recommend to get used to use different keys for different actions.
The visual selection is mostly not needed anyway. Change a paragraph? directly use ca} and so on.
I have found that VI/VA + WOBO (as many times as you need to expand) works similarly. Not as fast but its the same concept and you can even expand/shrink asymmetrically based on your WO's and BO's (Or OW's and OB's depending on how you look at it)
I have a windows form in VB.net 2010 which needs to read remote .exe's language string.
Usually, this could be done via
oFileInfo = FileVersionInfo.GetVersionInfo("path to .exe here")
Dim sMyLanguage = oFileInfo.Language
Unfortunately, this will return something like "englisch", "französisch" on a German Windows which is absolutely useless for me.
The best would be an ISO-based code, like EN, DE, FR, etc. Another unique identifier like a codepage number or something similar would also be okay.
System.Globalization also doesn't seem to have kind of a mapping of language strings to something useful.
Any idea how to get such a language identification de-coupled from the language of my operating system? Currently, my idea is to use a .csv file with three gazillions of translations which doesn't sound to be appropriate.
Okay, I found a solution:
In System.Globalization, there is not quite a direct mapping, but as in https://msdn.microsoft.com/de-de/library/system.globalization.cultureinfo.lcid(v=vs.110).aspx there are just about 140 languages listed, so I made a .csv file with Culture ID and to returning string and looped thru it with a simple For loop.
For i = 1 To gsLanguages.Count - 1
Try
oLang = New System.Globalization.CultureInfo(CInt(gsLanguages(i).Split(";")(1)), True)
If oLang.DisplayName.ToLower.StartsWith(sLangString) Then
sLanguage = gsLanguages(i).Split(";")(0)
Exit For
End If
Catch ex As Exception
End Try
Next
No question, this may not be the best solution. But in my testing, it had a very high chance to hit, so this is good enough for me.
I have a file variable in d3 pick basic and I am trying to figure out what file it corresponds to.
I tried the obvious thing which was to say:
print f *suppose the file variable's name is f in this case
but that didn't work, because:
SELECTION: 58[B34] in program "FILEPRINTER", Line 7: File variable used
where string expression expected.
I also tried things like:
list f *didn't compile
execute list dict f *same error
execute list f *same error
but those also did not work.
In case any one is wondering, the reason I am trying to do this in the first place is that there is a global variable that is passed up and down in the code base I am working with, but I can't find where the global variable gets its value from.
That file pointer variable is called a "file descriptor". You can't get any information from it.
You can use the file-of-files to log Write events, and after a Write is performed by the code, check to see what file was updated. The details for doing this would be a bit cumbersome. You really should rely on the Value-Add Reseller or contract with competent assistance for this.
If this is not a live end-user system, you can also modify an item getting written with some very unique text like "WHAT!FILE!IS!THIS?". Then you can do a Search-System command to search the entire account (or system) to find that text. See docs for proper use of that command.
This is probably the best option... Inject the following:
IF #USER = "CRISZ" THEN ; * substitute your user ID
READU FOO FROM F,"BLAH" ELSE
DEBUG
RELEASE F,"BLAH"
END
END
That code will stop only for one person - for everyone else it will flow as normal. When it does stop, use the LIST-LOCKS command to see which file has a read lock for item "BLAH". That's your file! Don't forget to remove and recompile the code. Note that recompiling code while users are actively using it results in aborts. It's best to do this kind of thing after hours or on a test system.
If you can't modify the code like that, diagnostics like this can be difficult. If the above suggestions don't help, I think this challenge might be beyond your personal level of experience yet and recommend you get some help.
If suggestion here Does help, please flag this as the answer. :)