Delete a line in Visual Studio without copying it?

124,322

Solution 1

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.

Solution 2

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

Solution 3

Ctrl + Shift + K 

will work fine for both Windows and Linux.

Solution 4

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

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

Solution 5

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

Share:
124,322

Related videos on Youtube

BrunoLM
Author by

BrunoLM

I'm a Developer for Fun! Things I like Code Play games Anime / Manga Contact information [email protected] LinkedIn Facebook Site - https://brunolm.github.io/ Blog - http://blog.codingwise.com/

Updated on September 17, 2022

Comments

  • BrunoLM
    BrunoLM over 1 year

    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?

    • ChrisF
      ChrisF over 13 years
      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
      ChrisF over 13 years
      Also what keyboard mapping scheme are you using?
    • ChrisF
      ChrisF over 13 years
      @T. Kaltnekar - he should have explained that in the question or as a comment on the answer, we're not all mind readers!
    • T. Kaltnekar
      T. Kaltnekar over 13 years
      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.
  • ChrisF
    ChrisF over 13 years
    I did get down-voted for suggesting this very solution.
  • BrunoLM
    BrunoLM over 13 years
    My question is not how to delete a line in a text-editor. It is about a shortcut on Visual Studio to delete a line.
  • StackedCrooked
    StackedCrooked over 13 years
    @BrunoLM: my solution works in Visual Studio
  • ChrisF
    ChrisF over 13 years
    see @T. Kaltnekar's comment on the question
  • T. Kaltnekar
    T. Kaltnekar over 13 years
    +1 for pointing out where you can find a key combo or add new one.
  • BrunoLM
    BrunoLM over 13 years
    Not what I asked.
  • Mike Clark
    Mike Clark about 13 years
    Yes, of course this works. But it is too slow! :)
  • gronostaj
    gronostaj over 10 years
    Same thing, but one key less: go to line, Home, Shift+Down, Del ;)
  • Samuel
    Samuel over 10 years
    Old school boy :)
  • ᴍᴀᴛᴛ ʙᴀᴋᴇʀ
    ᴍᴀᴛᴛ ʙᴀᴋᴇʀ almost 10 years
    This setting is under Tools>Options as mentioned below
  • Kamil
    Kamil over 9 years
    This is not keyboard shortcut, this is another "how to play on the piano" answer ;)
  • Cfinley
    Cfinley about 9 years
    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.
  • HankCa
    HankCa over 6 years
    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!
  • mgae2m
    mgae2m over 6 years
    What is different between CTRL+L and CTRL+SHIFT+L?
  • Tetsujin
    Tetsujin over 5 years
    Can you provide a reference for this. It has already been posited as an answer & has one comment underneath... "No it's not."
  • PeterPan
    PeterPan about 5 years
    Actually it works just fine on Windows 10 with Visual Studio Code 1.32.3.
  • dawsnap
    dawsnap almost 5 years
    Also worked for me in W10
  • Josh Noe
    Josh Noe over 4 years
    This should be a comment.
  • Ravish
    Ravish over 4 years
    Yeah, I realized 4 years later too that this should a comment :D, deleting it
  • DAG
    DAG about 3 years
    mgae2m - CTRL+L is Edit.LineCut while CTRL+SHIFT+L is Edit.LineDelete
  • bwdm
    bwdm almost 3 years
    ctrl + shift + K works for me on Linux.
  • Ooker
    Ooker over 2 years
    this answer is outdated. Let's downvote it