Do you want to find out how you can quickly duplicate a line in Visual Studio Code?
Visual Studio Code (VSCode) is a free cross-platform text editor, developed by Microsoft. It is quickly becoming a favorite tool of many programmers thanks to its excellent performance and the plethora of rich features it offers.
In order to win developer hearts and minds, VSCode has integrated a huge set of features into its minimal interface. In this article, we would like to show you how to quickly duplicate a line when you’re working in VSCode.
Duplicate a line in Visual Studio Code
- Open the file with Visual Studio Code.
- Select the line that you want to duplicate.
- If you want to copy the line to the line above itself, press Shift + Alt + Up Arrow Key.
- If you want to copy the line to the line below itself, press Shift + Alt + Down Arrow Key
Change the Duplicate line Hotkey in VSCode
Visual Studio Code allows you to freely change the shortcut to copy the lines upward or downward to whatever you feel comfortable.
With VSCode open, go to File > Preferences > Keyboard Shortcuts. (Code > Preferences > Keyboard Shortcuts on macOS).
The new Keyboard Shortcuts tab lists all available commands with and without hotkey attached to it so you can easily change or remove them at will.
The Copy Line Down and Copy Line Up commands are the ones we are looking for. To quickly find them, enter "copy line" into the Search box at the top.
Let’s say we want to modify Copy Line Down keyboard shortcut from Shift + Alt + Down Arrow Key to Shift + L. We have to double click anywhere in Copy Line Down section, then press the new hotkey, followed by the Enter key.
Please do note that if we try to set the new hotkey to something already assigned to other actions, there will be a warning before you proceed.
VSCode is a great code editor with useful features. The more we use it, the more nifty little quick tricks we discover. We’ve covered how to comment out multiple lines in Visual Studio Code and automatically indent your code in Visual Studio Code in the past and will write more about VSCode in the future,
Thanks man it helped me.