128

There is the shortcut Shift+Del to delete a line, but I want to delete the line without modifying what is in the clipboard.

Is there some way to configure it or another shortcut?

shA.t
  • 488
  • 4
  • 18
BrunoLM
  • 5,464
  • 14
  • 44
  • 53
  • Which version of Visual Studio are you using? Because `Del` on highlighted lines works for Visual Studio 2008. I wouldn't have posted my answer if I hadn't tested it first. – ChrisF Sep 29 '10 at 12:57
  • Also what keyboard mapping scheme are you using? – ChrisF Sep 29 '10 at 13:06
  • 1
    @T. Kaltnekar - he should have explained that in the question or as a comment on the answer, we're not all mind readers! – ChrisF Sep 29 '10 at 13:12
  • 1
    Well, he did state he's looking for a shortcut which would suggest a key combination. I usually just go to start of line, pres Shift+Down then Del. Didn't even know there's a combo for directly deleting a line. For most simple things I don't use special shortcuts since they usually work in one editor and not in another. – T. Kaltnekar Sep 29 '10 at 13:18

12 Answers12

138

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.

heavyd
  • 62,847
  • 18
  • 155
  • 177
  • 5
    +1 for pointing out where you can find a key combo or add new one. – T. Kaltnekar Sep 29 '10 at 13:20
  • 1
    This setting is under Tools>Options as mentioned [below](http://superuser.com/questions/194004/delete-a-line-in-visual-studio-without-copying-it/614442#614442) – ᴍᴀᴛᴛ ʙᴀᴋᴇʀ Aug 12 '14 at 13:12
  • 1
    And more importantly, `CTRL+SHIFT+L` doesn't copy the line to the buffer (`SHIFT + Del` is assigned to `CUT` by default). So if you re-assign `SHIFT + Del` as the short-cut for `Edit.LineDelete` then you can have that nice shortcut with the nasty side-effect. Nice one, thanks! – HankCa Oct 05 '17 at 00:52
  • 1
    What is different between `CTRL+L` and `CTRL+SHIFT+L`? – mgae2m Oct 13 '17 at 15:20
  • mgae2m - CTRL+L is Edit.LineCut while CTRL+SHIFT+L is Edit.LineDelete – DAG May 07 '21 at 15:03
94

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"
}

For Visual Studio answer see @heavyd's answer

roydukkey
  • 160
  • 1
  • 11
BrunoLM
  • 5,464
  • 14
  • 44
  • 53
14
Ctrl + Shift + K 

will work fine for both Windows and Linux.

Arun Kumar N
  • 241
  • 2
  • 3
  • Can you provide a reference for this. It has already been posited as an answer & has one comment underneath... "No it's not." – Tetsujin Sep 29 '18 at 13:42
4

Go to tools -> options. Tab Environment -> subtab Keyboard.

Select Edit.LineDelete. Assign a shortcut. Thats it. I use Alt + D.

Vinay
  • 41
  • 1
2

Default Shortcut Key in VS Code is : Ctrl + Shift + K.

1

You can install the Productivity Power Tools, which are made by Microsoft, as an extension.

The feature that you might get some use out of is Triple Click, which highlights an entire line when you triple click it. Then you can simply use the Delete key.

Michael
  • 1,173
  • 7
  • 12
1

The Shortcuts WinForms Control supports the modifier keys, multiple keys shortcuts, and shortcuts without modifier keys to build a keyboard trigger action, such as Ctrl, Alt and Shift with any other keys to trigger a specific action for their Windows applications.

Jawa
  • 3,619
  • 13
  • 31
  • 36
Noah
  • 11
  • 1
0

If you often find yourself copying blank lines to the clipboard and erasing the previous clipboard contents, try navigating to Tools->Options->Text Editor->[All Languages or your favorite language]->General and unchecking “Apply Cut or Copy commands to blank lines when there is no selection.”

gerleim
  • 185
  • 2
  • 9
0

This combination will only delete the line: Ctrl + Shift + L

Source: Cut or Delete the Current Line

Linger
  • 3,274
  • 10
  • 35
  • 47
nosferat
  • 145
  • 8
0

I know I am quite late in the party, but, here is a list of Shortcut keys for Visual Studio: http://blogs.msdn.com/b/piyush/archive/2007/03/16/useful-visual-studio-shortcut-keys.aspx

Ravish
  • 101
  • 1
  • Can you add in the relevant parts of the link into your answer? We ask this to help the OP out, so they will not have to search through information that may not pertain to them. This is also to preserve the relevant information in case the hosting site goes down. For more information, see this [meta post](http://meta.stackoverflow.com/q/8259). – Cfinley Apr 29 '15 at 14:17
  • This should be a comment. – Josh Noe Sep 26 '19 at 21:55
  • Yeah, I realized 4 years later too that this should a comment :D, deleting it – Ravish Sep 27 '19 at 00:38
-1

Or, the old fashioned way (for me it is a habit and I even had to think what was the combination :) ):

  1. Go to the line you want to delete
  2. Press 'Home'
  3. Then 'Shift' + 'End'
  4. Then 'Del'
  5. and again 'Del'

Works in most text editors :)

m_pGladiator
  • 127
  • 1
  • 7
-1

It seems I'm risking a downvote for not providing a single-keystroke solution, but I want to share my solution anyway:

HOME, SHIFT + ARROW-DOWN (repeat for multiple lines), DEL

It's quick and has the added advantage that works in other editors as well.

StackedCrooked
  • 2,951
  • 9
  • 37
  • 43