Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you delete lines with certain keywords in VScode

I have this regular expression to find certain keywords on a line:

.*(word1|word2|word3).* 

In the find and replace feature of the latest VSCode it works ok and finds the words but it just blanks the lines leaving big gaps in-between.

I would like to delete the entire line including linefeed.

The find and replace feature doesnt seem to support reg exp in the replace field.

like image 941
PapaLazarou Avatar asked Jul 11 '18 13:07

PapaLazarou


People also ask

How do I delete a line in Visual Studio?

Ctrl + Shift + L will delete the line and not copy to the clipboard.

How do you tidy your code in vs code?

The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.

How do I remove multiple lines from a string in word?

Alt-Enter to select all of the instances of the string on the page. Cmd-L to broaden the selection to the entire line of each instance on the page. Delete/Backspace to remove those lines. Show activity on this post.

How to delete a line in AutoCAD?

1. Select the text to check. 2. Ctrl/Cmd-Shift-L selects all occurrences. 3. Ctrl/Cmd-I will select the entire line. 4. Delete or whichever other action you want to do with selected lines

How to select and remove all lines containing an occurrence?

VSCode/Sublime how to select and remove all lines containing an occurrence 1. Select the text to check.. 2. Ctrl/Cmd-Shift-L selects all occurrences.. 3. Ctrl/Cmd-I will select the entire line.. 4. Delete or whichever other action you want to do with selected lines. I hope this helped and I have ...

How to remove duplicated lines in a file in Excel?

Given that we have a big file which includes a quite large number of duplicated lines, follow the following steps can easily remove the duplicates. 2. Press F1 or Ctrl + H to open the Replace mode 3. Toggle the “Use Regular Expression” icon 4. In the search field, type ^ (.*) ( \1)+$ 5. In the replace field, type $1 6.


Video Answer


1 Answers

If you want to delete the entire line make your regex find the entire line and include the linefeed as well. Something like:

^.*(word1|word2|word3).*\n? 

Then ALT-Enter will select all lines that match and Delete will eliminate them including the lines they occupied.

like image 52
Mark Avatar answered Oct 04 '22 20:10

Mark