JChristian
JChristian

Reputation: 4170

Is there a way to delete a line in Visual Studio without cutting it?

I want to delete a line just like hitting Ctrl + X without anything selected, but without saving the line to the copy stack. Is this possible?

I'm using Visual Studio 2010.

Upvotes: 235

Views: 118247

Answers (13)

Yves
Yves

Reputation: 278

Valid Answer By 2023 for VS Code (with image)

All the above answers regarding Ctrl + Shift + L are now deprecated.

The correct default behavior is Ctrl + Shift + K
( + Shift + K if you're a MAC user).

To change this default behavior:

1- Go to File > Preferences > Keyboard Shortcuts (OR click Ctr+K Ctrl+S)

enter image description here


2- Type in the search bar delete line

enter image description here

Here you will find the corresponding behavior. You can change it just by double-clicking on it and pressing any desired combination of keys on your keyboard (pay attention of conflicting shortcuts).

Upvotes: 8

Sh4msi
Sh4msi

Reputation: 1531

By default, if you are using the C# default profile, you can delete a line using Ctrl + Shift + L.

You can customize this using Tools->Customize. Select "Keyboard". Look for the command Edit.LineDelete to assign it to whichever keyboard shortcut you like. Source


If you got here looking for an answer for Visual Studio Code the default shortcut is:

ctrl + shift + K for Windows

+ shift + K for MacOS

However, you can change on File > Preferences > Keyboard shortcuts

{
    "key": "ctrl+shift+delete",
    "command": "editor.action.deleteLines",
    "when": "editorTextFocus && !editorReadonly"
}

Source

Upvotes: 8

Tony Lezimis
Tony Lezimis

Reputation: 37

Here is a url for the keyboard short cut reference for windows: https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf

For windows: Ctrl + Shift + k

Upvotes: 1

user1689175
user1689175

Reputation: 857

The other answers are specific to Visual Studio, which is what was requested by OP, however if anyone is looking for a more generalized way to do this for most Windows programs, you can also Triple-Click to select any block of text, then just press the Delete key. This works for any Windows text editors or TextBoxes, including password boxes, search boxes, browser web address boxes, etc. For text editors such as Visual Studio, a block of text is typically one line of code. Obviously you can do other things too, such as triple-click to select a line of code, then Ctrl-X, Ctrl-V to cut/paste, etc, or just triple-click and type over it to replace a line.

Upvotes: 0

Pragati Dugar
Pragati Dugar

Reputation: 272

none of the above answers worked for me. to delete a line in visual studio code use :shift+del

Upvotes: 6

Jon Ander
Jon Ander

Reputation: 780

CTRL + L (Visual Studio 2019 Windows)

Upvotes: 19

Shahzad Latif
Shahzad Latif

Reputation: 1424

On Visual Studio 2019 for Mac, it's CTRL + K to cut the whole line by default.

Upvotes: 2

Patapoom
Patapoom

Reputation: 890

All the answers were helpful but didn't seem to work for me.

So I found the solution --> for Visual Studio 2017 (and certainly 2019):

Tools > Options > Environment > Keyboard > on the right pane select Edit.LineEdit.

Below there is a ComboBox Use new shortcut in: with Global written --> Change it to Text Editor.

On the right there is a Text input Press shortcut keys:, so use the shortcut of your choice.

Then click on Assign PushButton on the right (otherwise it won't be applied).

Finally > OK.

You can now open a .CPP file and use your shortcut to remove a line.

Upvotes: 1

A_01
A_01

Reputation: 1141

Correction in my answer

Ubuntu 16 & Visual studio Version: 1.30.1

To cut line Shift + del

To delete line Shift + Ctrl + k

Upvotes: 31

jitendrapurohit
jitendrapurohit

Reputation: 9675

Its Cmd + Shift + K on mac by default.

But it can be modified according to user needs from the settings (Preferences -> Keyboard Shortcuts) -> search for Delete Line key value.

Upvotes: 13

AMissico
AMissico

Reputation: 21684

I mapped Ctrl + L (Global) to Edit.LineDelete. Otherwise, the shortcut key is Ctrl + Shift + L, which is awkward. Go to Tools > Options > Environment > Keyboard as shown below.

Tools | Options | Keyboard

Upvotes: 31

Kirk Woll
Kirk Woll

Reputation: 77536

Edit.LineDelete is the name of the command. By default it's bound to Ctrl + Shift + L, but you can give it whatever you like in Tools | Options | Keyboard.

Edit: Corrected default shortcut info.

Upvotes: 332

griegs
griegs

Reputation: 22760

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

Upvotes: 57

Related Questions