Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select nonadjacent lines containing a common phrase in vscode

I have an HTML file that has around 700 of my bookmarks. Each line has link and a tag like the following:

<li><a href="https://www.bartleby.com/141/" time_added="1547558810" tags="paper_writing">Strunk, William, Jr. 1918. The Elements of Style</a></li>

The file has multiple lines with the same tags. I want to group the lines with the same tag next to each other. I was trying to do it in vscode. I can select multiple occurrences of the same phrase with Ctrl+Shift+L, but I could not select the lines. Is there a way for doing this?

like image 353
anotherone Avatar asked Jan 17 '19 11:01

anotherone


People also ask

How do you select common words in VS Code?

Ctrl+D selects the word at the cursor, or the next occurrence of the current selection. Tip: You can also add more cursors with Ctrl+Shift+L, which will add a selection at each occurrence of the current selected text.

How do you write the same text in multiple lines in VS Code?

Use Ctrl + D to use multi word edit of same words in Windows and Linux. Use CMD + D for Mac.

How do you highlight all occurrences in VS Code?

Ctrl + Shift + L to select all occurrences of current selection. Save this answer.


1 Answers

After your comment below that clarified what you are trying to do I think you will find this easier than your solution.

  1. Select the text to check.
  2. Ctrl-Shift-L selects all occurrences. The command is Select All Occurrences of Find Match - if that is bound to something else on your OS, use that.
  3. Ctrl-L will select the entire line. (Changed from Ctrl-i in Feb. 2019.) That is using the command Expand Line Selection - again find that command in your Keyboard Shortcuts and use the same command.
  4. Cut and paste them where you want.

There is also an extension vscode-dup-checker that will find and delete duplicate lines. I don't know if you actually want to delete the duplicates though.

I added a gif to show it in action - it only uses steps 1-4 above:

demo of selecting all common lines

like image 62
Mark Avatar answered Sep 28 '22 02:09

Mark