I checked the documentation for code collapsing, many languages have a marker defined but SQL doesn't.
SQL Server Management Studio recognizes begin and end as a region, allowing for folding, but VS Code doesn't.
Any suggestions are very appreciated.
For anyone coming here for the answer.
Region markers for SQL have been added to VS CODE in 2019 and you can now use them as:
--#region [name region if you like]
part of code you want to fold/collapse
--#endregion
Then use Ctrl + Shift + P or View -> Command Palette... and choose Fold All Regions.
use tab for group common code.
For example:
BEGIN
YOU SQL CODE
END
the region between BEGIN will be collapsed
Related
I want to set up automatic text replacement shortcuts in Visual Studio Code similar to snippets in SQL Complete or text replacements on iOS. So for example: if I type ssf I want VS Code to replace it with SELECT * FROM. (Or alternatively, offer it as an autocomplete suggestion).
How can I set up automatic text replacement rules in VS Code?
you can use extensions such as the "JavaScript (ES6) code snippets"
I've been transitioning to using VS Code for my python projects after previously working with the full Visual Studio, and some of the key bindings/features I'm used to in Visual Studio I can't find the equivalent for in VS Code. I'm not sure if the bindings are different or if the feature doesn't exist.
One feature in particular that I can't figure out is if it is possible to do multi-line select past line endings. In Visual Studio, using Alt + Click + Drag, lets you create a multi-line cursor or box selection, that can extend past line ends, implicitly adding spaces as needed so that the right-most side of the box stays uniform. In VS Code, if you drag the selection past the end of a line, the selection box won't go past the end of the line, even if other lines in the selection extend past it. In Visual Studio, this feature even goes further, as you could Alt + Click + Drag even in areas with no characters as all, creating a multiline cursor or box selection to the right of all existing line ends.
This isn't an essential feature, but it's very handy in making code easy to read. For example, when assigning several dictionary entries all at once, with varying key lengths. Is it possible to do something like this in VS Code?
Edit: The feature I'm looking for is virtual spaces (thank you Mark for providing the feature name), which seems to be an outstanding feature request in VS Code.
The short answer is no, vscode does not have a box select, past line ends, built-in. VS Code does not have the concept of virtual spaces which would be necessary to make this work yet.
Below is the issue, lots of comments, not that many upvotes. Upvote it.
https://github.com/microsoft/vscode/issues/5402
When trying to select a code snippet or all of the code at visual studio code, it thinks that I want to put a cursor to every line.
It supposed to select the whole line, and I don't have to move my mouse at the end of the line in order to select everything. You can see the result from the image. how can I get back to normal?
I didn't notice I opted for column selection mode under selection tab. so problem solved.
I have the following code:
CList.Add( new CodeStuff(941,"National List Limit
CList.Add( new CodeStuff(945,"Code not used
CList.Add( new CodeStuff(946,"State Building Height Limit
CList.Add( new CodeStuff(993,"Building Material Type
CList.Add( new CodeStuff(1033,"Not used - requirements changed
CList.Add( new CodeStuff(1034,"Current Unacceptable Applications
CList.Add( new CodeStuff(1035,"Historical Unacceptable Applications
I got the first bit using Alt+Shift+mouse button and typing. How do I add "); to the end of each line?
I had to use Notepad++ macro recording to do it and this is the only reason I still hang on to that editor. If someone can tell me how to do it in VSCode, I'd be very grateful.
Not completely sure I understand, but Shift-Alt-I will put a cursor at the end of all selected lines so just select your text and Shift-Alt-I (that is an 'eye' at the end). Then typing "); will put that at the end of each line.
---------------------- Edit -------------------------------
I see that Column Selection Mode (in v1.43) does this nicely now (with Selection/Column Selection Mode enabled) depending on your direction of selection [unfortunately the gif does a poor job of showing the cursors but they are all at the beginning or ends of the lines depending on the direction of selection]:
On Mac Vscode, I believe the trick is to "mouse" select the lines you wish to append, then hit Shift+Option+I.
On Windows 10, if I hit ShiftAltI, all the cursors go to the beginning of each line. To move the cursors to the end of each line, simply hit the End key after that.
By "VS Code" I mean the lightweight text editor not the monolithic IDE, unfortunately searching this on google will bring up many pieces of irrelevant information about how to do this in Visual Studio.
To the question itself, Anybody knows how to hide arbitrary selected lines of code in "Visual Studio Code", preferably into a plus sign like collapsing does?
Note: this is different than collapsing nested code which probably could be achieved by Ctrl+K,Ctrl+<num> , what I need here is to hide specific block of code of choice, no matter nested or not.
EDIT: I see there are people who don't understand my requirements.
for example, you may think what I want is this:
before hiding:
for i in j:
for k in i:
for l in k:
somestuff...
after hiding:
[+] for i in j: ...
What I actually want is this:
before hiding:
# doing stuff about a
a = ClassA()
a.bar()
a.i = 2
a.j = 3
a.k = 5
after hiding:
[+] ... ( doing stuff about a )
2017.10.17 EDIT:
turns out VS Code implemented a very similar feature called "Folding Regions" in VS Code 1.17.1 Update. link
You can use the following delimiters for code folding:
C/C++: #pragma region and #pragma endregion
C#: #region and #endregion
CSS: /* #region */ and /* #endregion */
Java: //region and //endregion
JavaScript: //#region and //#endregion and //region and //endregion
PHP: #region and #endregion
Powershell: #region and #endregion
Python: #region and #endregion
VB: #Region and #End Region
See https://github.com/Microsoft/vscode/issues/12146 ([folding] fold regions)
In the Insiders Build v1.70 now is the functionality and command to truly hide arbitrary lines of code. The command is
Create Manual Folding Range from Selection
editor.createFoldingRangeFromSelection
It is bound to Ctrl+K Ctrl+, by default. Select any lines you want to fold.
You can unfold those lines either by clicking the gutter folding controls or this command when the cursor is somewhere on the folded line:
Remove Manual Folding Ranges
editor.removeManualFoldingRanges
The above command is bound to Ctrl+K Ctrl+. by default.
Unfortunately, it doesn't appear that VSCode currently allows you to hide an arbitrary selection of code like Visual Studio does via Ctrl+M,Ctrl+H. For now you could use the code folding feature, which depends on indentation. That is, if you indent the code you want to hide, you could then collapse it via Ctrl+Shift+[, like so:
Obviously, this is kind of an ugly solution to your problem; it requires multiple steps and makes actual changes to the file. Also, it's clearly useless if you're writing in a whitespace-dependent language like Python, but I don't think you are going to find a better solution short of finding an extension (or writing one yourself). It also might be worth posting an issue on the official VSCode GitHub repo if this feature is important to you.
Here is the vs code documentation for folding a selection.
To hide: Highlight the lines you want to fold then press Ctrl+K then Ctrl+,
To unhide: Just click the ">" icon to the left of the row of the folded code or press Ctrl+K then Ctrl+.
Comment with a delimiter with decreased indentation.
Hiding then works as in nested, with the little arrow on the left.
see here
# Below here comes the code to hide.
a = ClassA()
a.bar()
a.i = 2
a.j = 3
a.k = 5