How do I make Notepad++ delete lines like Eclipse does?

82

22

Eclipse has a keyboard shortcut which deletes either the current line (if nothing is selected) or all lines which are part of the currently selected text: Ctrl+D.

Is there a way to make Ctrl+D do the same thing in Notepad++?

The best I could do is remap the shortcut to Scintilla's SCI_LINE_DELETE, but that only deletes one line at a time, even if the selection spans multiple lines.

Matt Ball

Posted 2011-03-16T14:28:14.560

Reputation: 3 322

Answers

100

Ctrl + Shift + L will achieve the same effect.

Ctrl + L will delete the line but will also keep it in your clipboard replacing clipboard contents.

I'm not sure if you can map Ctrl+D to do the same thing or not. I've not really messed with the keyboard mappings with Notepad++ since they are very similar to those of Visual Studio

Anthony Shaw

Posted 2011-03-16T14:28:14.560

Reputation: 1 618

1@RØŠÐÎ SCI_LINEDELETE is what Ctrl+Shift+L was mapped to. I tried that but it only deleted (without copying to clipboard) the first of the selected lines, similar to OP. Am I missing something? – jinglesthula – 2016-04-21T15:13:01.340

6Why isn't this in the menu Edit > Line Operations – aliopi – 2017-11-24T07:03:49.010

16Brilliant! Now I just have to find what Ctrl+L is mapped to ... *edit* aha, it's mapped to SCI_LINECUT. That was literally the next Scintilla command below SCI_LINE_DELETE. – Matt Ball – 2011-03-16T17:17:25.787

28Please note that Ctrl+L will cut the line (copy it into your clipboard). To actually delete the line is Ctrl+Shift+L, this will delete the selected lines without overwriting your clipboard. – Rosdi – 2013-01-11T00:42:05.160

21

I had to map Ctrl+D to both SCI_LINEDELETE and SCI_LINECUT in order to make it behave like Eclipse. Hope this is helpful.

You also need to disable or rebind SCI_SELECTIONDUPLICATE so there's no conflict on Ctrl+D.
To disable a shortcut, highlight it, click Modify set the DropDownList to None, click Apply first and then Okay.

alex

Posted 2011-03-16T14:28:14.560

Reputation: 211

2How come both were required? – Jonathan Benn – 2015-06-19T21:02:38.220

1When I map the same shortcut to both of those all that happens is it switches from deleting only the first line of the selected lines to deleting only the line the cursor was on. (I used Ctrl+Shift+D, so I didn't have to worry about the selection duplicate binding.) – jinglesthula – 2016-04-21T15:17:56.477

14

Macro is a good choice here. Though the macro I came up with lags a bit (you can see may be quarter of a second lag between CTRL-D hit and lines getting deleted on a large selections) it works grand both on a single line and multiple lines selection and covers various tricky cases.

So, my macro is:

CTRL + J - if multiple lines are selected they are joined into a single line
HOME - the usual HOME button. Brings cursor to the start of a line (or start of a joined line)
SHIFT + END - selects the line till the end starting from the cursor position
CTRL + SHIFT + L - deletes the whole line

This set of actions covers all possible scenarios of line deletion I have encountered so far during heavy use of notepad++.

Jan Domozilov

Posted 2011-03-16T14:28:14.560

Reputation: 141

I know I'm a few years late, but wouldn't this macro work just as well with just DELETE instead of CTRL+SHIFT+L as the last command? If I understand you correctly, you have already marked all the text you want to delete with the first three commands. – Bjarte Aune Olsen – 2016-04-08T19:11:52.010

9

There is a shortcut in Notepad++ to delete a line: Ctrl+Shift+L ..but this will only delete a single line.

Even if several lines are selected, it will only delete the line where the cursor is resting and not the highlighted lines.

So, the simplest way to delete a series of selected lines, you have to Record a Macro with these key shortcut combinations:

Ctrl+J

followed by

Ctrl+Shift+L

This will first JOIN the selected lines and then DELETE the whole line.

This is better than using a combination of CUT and DELETE approach as mentioned above (which i've tried) because on some instances, it will also delete non-selected lines.

Open Technologist

Posted 2011-03-16T14:28:14.560

Reputation: 91

4

As a non-macro alternative to @Jan Domozilov's answer, I followed these steps (using Notepad++ v6.5.1 (UNICODE)):

  1. In the Settings menu, select Shortcut Mapper.
  2. In the Main menu tab, set Join Lines (line 26) to Ctrl+Alt+D.
  3. Click the Scintilla commands tab.
  4. Set SCI_LINEDELETE (line 90) to Ctrl+D.
  5. Close the window.

This allows you to perform the desired behavior with a small modification. You select your text, run the Join Lines command with Ctrl+Alt+D, release only the Alt key, and press D again to delete the text.

skia.heliou

Posted 2011-03-16T14:28:14.560

Reputation: 2 185

0

One other simpler way is to use the backspace button after selection, this will replace selected line with backspace.

Hitesh Wadhwani

Posted 2011-03-16T14:28:14.560

Reputation: 1

but then you need to select first then delete, which takes much more operations than a simple Ctrl+Shift+L – phuclv – 2020-01-08T14:19:06.063

-1

You can use CTRL+DELETE to delete the entire content of a line. Then all you do is use DELETE again to remove the line feed. If that is not enough for you, you can create a macro to do both actions.

As it seems to have stopped working in the latest version, I recommend you to use the Macro approach for the entire problem. Go to Macro, "Start Recording", then press "Home", "Shift"+"END", "DELETE", "DELETE", then go to Macro and stop your Macro. After that, go to Save Current Recorded Macro" and chose a name and shortcut, (e.g. CTRL+DEL). This reenables the shortcut for delete line.

private_meta

Posted 2011-03-16T14:28:14.560

Reputation: 2 204

Ctrl+Delete does not delete lines in Notepad++ for me (I have not remapped any keys other than Ctrl+D). – Matt Ball – 2011-03-16T14:47:12.997

Which version of Notepad++ are you using? It's working on Notepad++ 5.8.2 under Win7 – private_meta – 2011-03-16T14:47:57.490

5.8.7 (the latest version) on Win7 x64. Did you mean Ctrl+Backspace? (also doesn't work for me) – Matt Ball – 2011-03-16T14:50:27.003

Ah, I just tested it with 5.8.7, and it didn't work either, let me see – private_meta – 2011-03-16T14:50:58.377

I updated my Answer – private_meta – 2011-03-16T14:54:52.087

Is there a way to make that macro work with multi-line selection? I already have single-line delete working, as mentioned in my question. – Matt Ball – 2011-03-16T15:29:12.120

Again, try the Macro. It's about the order of the keys. Assuming you have multiple lines selected means you go from, e.g. middle of line 1 to middle of line n. The sequence would be something like DEL, END, SHIFT+HOME, BACKSPACE, BACKSPACE. I hope that does what you want. – private_meta – 2011-03-16T15:35:27.090

But that macro performs the line selection. I just want a shortcut that deletes already-selected lines. – Matt Ball – 2011-03-16T15:57:11.813

Uhm... if you have lines that are already selected, then just use DELETE. I don't quite get what you are getting at. If you have the cursor position on a single line, the first shortcut works. If you marked the entire line, just delete or backspace works If you marked lines from middle of first line to e.g. middle of last, the second shortcut works. If you have all the lines selected fully, Delete or backspace works again. I don't know what you want except for that! – private_meta – 2011-03-16T17:41:54.783

I don't want to have to select the entire line in order to delete it. As per the accepted answer, try Ctrl+L and see how it behaves differently. – Matt Ball – 2011-03-16T17:43:06.480

I read the answer already, and I gave you a couple of different solutions as you didn't understand that the first one I gave you actually solved your problem as well (without scintilla, as I didn't know that one). But you accepted the other answer anyway, so there's no use in ranting around. – private_meta – 2011-03-18T10:19:52.003

-1

CTRL+SHIFT+DELDETE works for me great to delete whole single line.

Zuzu

Posted 2011-03-16T14:28:14.560

Reputation: 9

2The OP wants to delete all lines which are part of the currently selected text. Your shortcut does only delete the first line of a selection. – nixda – 2013-01-13T15:08:19.540