Visual Studio Code select same position above and below not the whole line before and after (see image) - visual-studio-code

I'm using visual studio code and run into a weird problem. I'm not sure how I got here - I could have accidently pressed a shortcut unknowingly.
I'm trying to select a phrase, link or anything that crosses multiple lines (whether the lines are true lines or due to word wrap). When I select multiple lines, it doesn't automatically select the text at the start and end between the two points. Rather, it just selects the length of text for that line and repeats it in the subsequent lines. See the image below to understand.
Image of issue
As you can see, I am trying to select the words from "the" to the end of "sub". Instead of selecting all the words between the two, it selects the text "the instru" and selects every line with the same amount of characters/length.
In order to show what I am expecting, I have pasted the text into Notepad and done the same thing.
What I am expecting
As you can see, all the words between "the" and "sub" are selected.
If anyone has any idea about how to fix this, I would be greatly appreciative.
Below is a copy of the text if the images don't display.
Follow the instructions below for a click guide to retire and/or add 'School'.
Best practice if there is a change in 'School' structure would be to 'retire' any existing school setup that is no longer required and add the new sub school information. The reason why we don't just edit existing school names (typically) is due to leaving historical data intact.

Try using ctrl+shift+P and typing "Toggle Column Selection Mode"

Related

VSCode will copy full line when only a word is selected (single click)

I'm on OSX and running Version 1.42.0 of Visual Studio Code. I have noticed that when I single click a word it will highlight. But if I copy CMD + c and then paste CMD+v, the full line will be in the clipboard. This causes problems from time to time, when the screen has given me every indication that I have only selected a single word. Is there some setting that I can set that will make the default behavior to select a word on a single quote and never ghost select a full line?
What it looks like when I single click a word:
And what it looks like after I've copied and pasted:
After filing an issue, it turns out that this behavior is by design.
The word the cursor is on (from a single click) is highlighted along with every occurrence of that word. The word is not selected (that would be a deeper blue).
By default copying without a selection copies the current line.
This in my opinion is an Accessibility issue, as there are strong visual clues that a word is selected. I have found that the behavior can be made more intuitive if you set these to settings.
// Controls whether copying without a selection copies the current line.
"editor.emptySelectionClipboard": false,
// Controls whether the editor should highlight semantic symbol occurrences.
"editor.occurrencesHighlight": false
With these two settings the word the cursor is on will not be highlighted (nor any other occurrences of that word). And if you do happen to copy, with an empty selection, the editor will behave similar to how other applications behave and not copy the current line.

How to put the cursor at the end of all selected lines in Visual Studio Code?

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.

Microsoft Word->Field Code->{TC}

So I am having a problem. This is what I can create on one of my laptop:
On another, when I created something that has {TC} in it, the whole field code disappeared.
For the example above, if on the other computer, both are running Office 2010,
I can input the code to create the table of content from:
{TOC \f \h \z \f 1\t "Heading 1,1,Heading 2,2,Heading 3,3,Title,1}
to
{TC}
The moment I type in TC, the whole {} disappears.
Other field codes work just fine, except for {TC}. So my question is how do I get {TC} to show on my other laptop?
Thank you for your time.
Apparently, I found my answer.
When I searched google for my answer, most sites give this as a solution:
For Word 2010, go to File->Options->Advanced
Under Show document contents: Select "Show field code instead of their values"
This is the equivalent of pressing Alt+F9, which DID NOT solve my problem.
Apparently, the solution to get {TC} to show in your document is in:
go to File->Options->Display
and check to always show HIDDEN TEXT.
I hope this helps someone in the future.
Yeah, the disappearing TC code is annoying at first -- seems like it's broken. Other codes work, but why does that disappear, even if entering manually? Word instantly sets TC code to Hidden, even the field code itself.
To temporarily toggle this visible without permanently changing your display to show Hidden Text, you can use the normal Ctrl-Shift-8, which toggles display of spaces, paragraph marks, tabs, and Hidden Text, on and off. This is a good keyboard shortcut to have in your standard back of tricks anyway. It is frequent in Word that you need to toggle paragraph marks on and off, because paragraph formatting is attached to the Paragraph mark, and when they're hidden, it can be tricky to fix various formatting issues.
The original post was a few years ago, but I fear things have gotten worse since then, not better. I am using Word 365 v2201, which should be up to date. The other day, I wasted hours on trying to resolve this issue with TC field codes.
First I tried entering them using Insert > Quick Parts > Field. Word creates what looks like a field code, but it behaves as normal text. Messing around with the various controls to toggle field display and hidden text etc etc, has absolutely no effect. It is basically a faux field. And of course, it is completely ignored when compiling the TOC.
Next, I tried entering it manually, by using Ctrl + F9 to either create a blank field or convert some existing text into a field. Same result as above.
As with the original post, this seems to afflict only the TC field code. Other codes work fine, including TOC. And if I create a TOC field, then edit the code to TC, it immediately loses its properties as a field. If I then put the O back in, it immediately behaves as a field once again. Unlike in the original post, adjusting the settings for field display and/or hidden text, have no impact.
In the end, the only solution was to create the field using Alt + Shift + o to open the Mark Table of Contents Entry dialog box. And finally, this works!

How can I remove duplicate lines in Visual Studio Code?

Say you have the following text:
abc
123
abc
456
789
abc
abc
I want to remove all "abc" lines and just keep one. I don't mind sorting. The result should be like this:
abc
123
456
789
If the order of lines is not important
Sort lines alphabetically, if they aren't already, and perform these steps:
(based on this related question: How do I find and remove duplicate lines from a file using Regular Expressions?)
Control+F
Toggle "Replace mode"
Toggle "Use Regular Expression" (the icon with the .* symbol)
In the search field, type ^(.*)(\n\1)+$
In the "replace with" field, type $1
Click ("Replace All").
If the order of lines is important so you can't sort
In this case, either resort to a solution outside VS Code (see here), or - if your document is not very large and you don't mind spamming the Replace All button - follow the previous steps, but in steps 4 and 5, enter these:
(based on Remove specific duplicate lines without sorting)
Caution: Blocks for files with too many lines (1000+); may cause VS Code to crash; may introduce blank lines in some cases.
search: ((^[^\S$]*?(?=\S)(?:.*)+$)[\S\s]*?)^\2$(?:\n)?
replace with: $1
and then click the "Replace All" button as many times as there are duplicate occurrences.
You'll know it's enough when the line count stops decreasing when you click the button. Navigate to the last line of the document to keep an eye on that.
Coming in vscode v1.62 is a command to eliminate duplicate lines from a selection:
Delete Duplicate Lines in the Command Palette
or
editor.action.removeDuplicateLines as a command in a keybinding
(there is no default keybinding for this command)
Here is a very interesting extension: Transformer
Features:
Unique Lines As New Document
Unique Lines
Align CSV
Align To Cursor
Compact CSV
Copy To New Document
Count Duplicate Lines As New Document
Encode / Decode
Filter Lines As New Document
Filter Lines
Join Lines
JSON String As Text
Lines As JSON String Array
Normalize Diacritical Marks
Randomize Lines
Randomize Selections
Reverse Lines
Reverse Selections
Rotate Backward Selections
Rotate Forward Selections
Select Highlights
Select Lines
Selection As JSON String
Sort Lines By Length
Sort Lines
Sort Selections
Split Lines After
Split Lines Before
Split Lines
Trim Lines
Trim Selections
Unique Lines
Removes duplicate lines from the document Operates on selection or
current block if no selection
Unique Lines As New Document
Unique lines are opened in a new document Operates on selection or
current block if no selection
I haven't played with it much besides the "Unique Lines" command but it seems quite nicely done (including attempting a macro recorder!).
To add to #Marc.2377 's reply.
If the order is important and you don't care that you just keep the last of the duplicate lines, simply search for the following regexp if you want to only remove duplicte non-empty lines
^(.+)\n(?=(?:.*\n)*?\1$)
If you also want to remove duplicate empty lines, use * instead of +
^(.*)\n(?=(?:.*\n)*?\1$)
and replace with nothing.
This will take a line and try to find ahead some more (maybe 0) lines followed by the exact same line taken. It will remove the taken line.
This is just a one-shot regex. No need to spam the replace button.
This now also takes the comment of #awk into account, in where the last line has to have a linefeed in order to be identified as a duplicate. This is no longer the case now by excluding the \n from the line to search and adding a $ to the line found.
I just had the same issue and found the Visual Studio Code package "Sort lines". See the Visual Studio Code market place for details (e.g. Sort lines).
This package has the option "Sorting lines (unique)", which did it for me. Take care of any white spaces at the beginning/end of lines. They influence whether lines are considered unique or not.
Install the DupChecker extension, hit F1, and type "Check Duplicates".
It will check for duplicates and ask if you want to remove them.
Try find and replace with a regular expression.
Find:
^(.+)((?:\r?\n.*)*)(?:\r?\n\1)$
Replace:
$1$2
It is possible to introduce some variance in the first group.
If you don't mind some Vim in your VS Code. You can install Vim emulation plugin.
Then you can use vim commands
:sort u
It will sort lines and it will remove duplicates
Sublime Text 3
It has blisteringly fast native permutation functions.
Edit > Permute Lines > Unique or ⇧⌘U, and
Edit > Permute Selections > Unique
Visual Studio Code is my daily driver. But, I keep Sublime Text on standby for these situations.
Not actually in Visual Studio Code, but if it works, it works.
Open a new Excel spreadsheet
Paste the data into a column
Go to the Data tab
Select the column of data (if you haven't already)
Click Remove Duplicates (somewhat in the middle of the bar)
Click OK to remove duplicates.
It is not the best answer, as you specified Visual Studio Code, but as I said: If it works, it works :)

How do I get a cursor on every line in vscode

I'm trying to use the multi cursor functionality of vscode on a large(ish) file.
the file is too large to select every line individually with ctrl-alt-up or down. In sublime-text I would select everything and push ctrl-shift-l. Is there a similar thing in vscode. I've tried using a regex search for ^, but that gives me an error stating "Expression matches everything".
The command Selection / Add Cursors to Line Ends altshifti will put a cursor on every line in the current selection. (For mac use optshifti)
Tip: You can pull up the keyboard shortcut reference sheet with ctrlk,ctrls (as in, those two keyboard combos in sequence).
(For mac use cmdk,cmds)
Hold Alt+Shift and select the block. Then press End or Right button.
You get selected individual lines.
I use version VSCode 1.5.3 in Windows.
Hold Alt+Shift+i
Hold Home (fn+-> Mac) for right-most or End for left most(fn+<- Mac)
This feature is actually called split selection into lines in many editors.
Sublime Text uses the default keybinding, CTRLSHIFT L
VSCode uses ALTSHIFTI
For Atom you actually need to edit your keymap to something like this
'.platform-win32 .editor, .platform-linux .editor':
'ctrl-shift-L': 'editor:split-selections-into-lines'
Real Lines vs Display Lines
First we have to understand the difference between Real Lines and Display Lines to completely understand the answer of the question.
When Word Wrap is enabled, each line of text that exceeds the width of the window will display as wrapped. As a result, a single line in the file may be represented by multiple lines on the display.
The easiest way to tell the difference between Real Lines and Display Lines is by looking at the line number in the left margin of the text editor. Lines that begin with a number correspond to the real lines, which may span one or more display lines. Each time a line is wrapped to fit inside the window, it begins without a line number.
Cursor At the Beginning of each Display Lines:
Cursor At the Beginning of each Real Lines:
Answer to the Question
Now that we know the difference between Display Lines and Real Lines, we can now properly answer the actual question.
Hold AltShift and select the text block.
Press Home to put cursor on the beginning of every Display Line.
Press End to put cursor on the end of every Display Line.
Press HomeHome (Home twice) to put cursor on the beginning of every Real Line.
Press EndEnd (End twice) to put cursor on the end of every Real Line.
Please understand that AltShiftI put cursor on the end of every Real Line.
Install the extension Sublime Commands.
[Sublime Commands] Adds commands from Sublime Text to VS Code: Transpose, Expand Selection to Line, Split into Lines, Join Lines.
(Don't forget to add the keybinding(s) from the extensions details page to your keybindings.json)
Doesn't VS Code already have a "split into lines" command?
Yes, yes it does. However it differs from the one in Sublime.
In VS Code, when you split into lines your selection gets deselected and a cursor appears at the end of each line that was selected (except for the last line where the cursor appears at the end of the selection).
In Sublime, when you split into lines a cursor appears at the end of each line (with the same exception as in VS Code) and the selection is divided on each line and "given" to the same line.
I have the same problem, i'm used to Alt + drag to do 'box selections' in visual studio but it does'n work in code.
It seems to be impossible for now to do it differently than by selecting every single line.
However plugins should be supported soon so we will likely see a plugin for this if not implemented directly by microsoft.
From visual studio uservoice forums:
We plan to offer plugin support for Visual Studio Code. Thank you for your interests and look for more details in our blog in the coming weeks. http://blogs.msdn.com/b/vscode.
For the preview we are looking for exactly this type of feedback. Keep it coming.
Sean McBreen – VS Code Team Member