Notepad++: Select/Copy Collapsed Folding Group

5

Notepad++ current supports folding as described here:

http://npp-community.tuxfamily.org/documentation/notepad-user-manual/display/folding

However, I see no immediate way to actually select or copy the actual foldings that you can collapse. In essence, I would like to move this collapsed group to a different section of my document, and although a brute force scroll-down select is possible, it seems entirely inefficient since Notepad++ already identifies this group.

Is what I am asking possible? I saw some other posts related to folding, but they were not actually interested in saving the contents within the collapsed group.

Thanks.

Mark W

Posted 2012-07-03T15:29:03.717

Reputation: 153

Answers

3

Let me give you an example:

this is the first line of code  |
{ <-- this is your collapsed code
 | Last line of code

Select from the end of the first line of code (|) to the beginning of the last line of code (|). Copy and paste wherever you need.

Rhyuk

Posted 2012-07-03T15:29:03.717

Reputation: 605

1This worked. I feel a bit silly for not considering this. Previously, I had attempted copying the line with the collapsed code only. Copying from the end of the line directly above the collapsed code to the beginning of the line directly below did appropriately select the box. – Mark W – 2012-07-03T19:33:16.720

No problem! I read your question and I actually had to open up my NotePad++ to try it. – Rhyuk – 2012-07-03T20:54:25.487

0

First of all, what programming language are you using? I know that this can be done when writing C (and I'm assuming it's also true for other C-like languages), but it's definitely easier when using a certain coding style than for others.

Specifically, the program folds code such that the opening { is the last thing visible. If you write a block like this:

if (something) {
    ...
} else {
    ...
}

the entire block will be folded up at the same time and only the if line is visible. If you instead write a block like this:

if (something)
{
    ...
}
else
{
    ...
}

the if and else halves will fold up separately. The { for each half will be on a line by itself. If you select from the line containing the { character to the first character on the following like, you will effectively select everything within that collapsed section. It's possible to do this using the first code style I demonstrated, but it's a bit more difficult (you can copy the entire block, but not just one branch of the if).

Keyboard Shortcut Remember that when the cursor is on a curly brace, Ctrl+B will jump to the matching brace. If you hold the Shift key down when you do this, you will highlight everything in between the braces as well.

bta

Posted 2012-07-03T15:29:03.717

Reputation: 376

The second style will work much better, but that was not quite the issue I had. I appreciate the response. – Mark W – 2012-07-03T19:34:29.073

@MarkWinter- I edited my answer to include a keyboard shortcut for doing this that you may find useful. – bta – 2012-07-03T22:22:53.210