This post covers different examples of how to make and remove duplicate lines in Visual Studio Code
It contains Multiple ways to Create and delete a duplicate line or rows in a text file opened in VSCode.
How to create a duplicate line in VSCode?
You can create a duplicate line in multiple ways.
using Copy and paste You can use the normal copy-and-paste option to duplicate the lines. First, select the line you want to duplicate using the below command.
Ctrl +Cfor copy,Ctrl + Vfor paste.Inbuilt Copy Line Up and Down feature
Go to
SelectionMenu >Copy Line UporCopy Line DownArrow keyUsing shortcut commands
- Windows:
Shift + Alt+ Downkey andShift + Alt+ Upkey - Linux:
Ctrl + Shift + Alt + Downkey andCtrl + Shift + Alt + Upkey - MacOS:
Shift + Option + Downkey andShift + Option + Upkey
- Windows:
by default, these shortcut commands are bound to the below properties in Key bindings
with File > Preferences > Keyboard shortcuts
- editor.action.copyLinesDownAction
- editor.action.copyLinesUpAction
So you can customize these bindings in shortcuts or modify them in the
keybindings.jsonfile with these properties.
How to delete duplicate rows or lines in a Visual Studio Code?
Let’s have a first.txt file opened in text content.
abc
def
abc
abc
def
abc
And output:
abc
def
One approach is to hover over a line and select a text, then remove the duplicate lines manually.
It’s simple for files that aren’t very large. For a larger file with many lines of text, however, it is a time-consuming job.
There are multiple ways you can remove duplicate or blank lines.
In the builtin Delete Duplicate Lines feature
This feature is available as inbuilt vs code.
Select
ViewsMenu +Command paletteor use the following shortcut commands- Windows: hotkeys:
Ctrl + Shift + P - Mac: shortcuts:
⌘ + Shift +P
- Windows: hotkeys:
It opens the
command palettetypesdeletein the search box and selects theDelete Duplicate Linesoption

- It removes Duplicate lines from the current file.
Find and Search with regular expression
Find and search is an inbuilt feature in the editor.
Open
Edit>Replaceor use ShortcutCtrl + Hin Windows,⌘ + Alt + Fon Mac.It opens the
Replacepopup upper right cornerSelect and type below
- first find box with
^(.*)(\n\1)+$- for duplicate lines - Second input box with
$1 - Select Search Mode as
Regular Expression(.*)or ShortCutAlt + Rin Windows,⌘ + Alt + Rin Mac - Click on the
Replace Allbutton or useCtrl + Alt + Enter
- first find box with
It removes duplicate lines from the file.
Use the Transformer extension
Transformer is a custom extension that deletes duplicate lines for an entire file or selection of a file apart from other things such as filtering lines combining lines’ end and beginning spaces and tabs and deleting comments.
Install the Transformer Package.
Go to the Extensions icon and Left Side vertical bar
type “transformer” and Select
TransformerextensionOnce the
Transformerextension is installed, Go to the next steps.Go to Command Palette with one of the options - Select
ViewsMenu +Command paletteor - use the following shortcut commands - Windows: hotkeys:Ctrl + Shift + P- Mac: shortcuts:⌘ + Shift +PIt opens the
command paletteand typetransformin the search box and selects thetransform: Unique LinesoptionIt removes duplicate lines or rows