Select nonadjacent lines containing a common phrase in vscode

Viewed 5965

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?

2 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

Ok, I found one method that works. I don't know if it the best though.

After Ctrl+Shift+L, you have cursors on all the lines with that phrase. Then pressing Home will take you to the beginning of all of them and Shift+End then will select all those lines on which you have the cursor. Then cut the text and paste it wherever you wish. Came out to be pretty useful for me while I was editing a html file with 700 links.

Related