13

I have a habit of using code editors for notes in the following fashion:

a topic
. a note
 ? a question regarding the note
  - a to do item
 . some more details
. another note
 . more details

another topic
...

What I like about VS Code is that it allows to fold (collapse) blocks in txt files based on their indentation (like for Python):

  a topic
+ . a note
  . another note
   . more details

  another topic
  ...

What I don't like, though, is that it also includes empty lines into collapsed blocks: the line after . more details has no indentation, but when I collapse that block I get

  a topic
+ . a note
+ . another note
  another topic
  ...

while I want it to be

  a topic
+ . a note
+ . another note

  another topic
  ...

Can you suggest what options should I change to get this difference about collapsing?

5
  • I am similarly annoyed with SQL. It doesn't do it for all languages so maybe its somewhere in the language definition file. Commented Apr 1, 2020 at 19:11
  • VScode doesn't do that to me. What os & version are you using? Commented Apr 3, 2020 at 17:01
  • Doesn't do that for me either. You code try setting the Folding Strategy to indentation. And yes, if you have that set to auto it will use the folding strategy contributed by the language service, if there is one. What is your language? It works for me in a .txt file with the folding strategy set to indentation or auto (probably because auto falls back to indentation in .txt files). Commented Apr 3, 2020 at 20:27
  • @Andoo , Mark, yeah thanks, the problem doesn't seem to exist in the latest version of VS Code, but if anybody explains how to solve the issue of blindguy, I'll accept that as an answer Commented Apr 11, 2020 at 13:46
  • bummer. I was hoping indentation was my solution also, but my current build+language combo seems to still strip empty lines when folding, which is the cause of my particular problem :-( Commented Jun 19 at 4:40

3 Answers 3

1

I don't know of a way to prevent the last line from being folded in VS Code, unless you use a 3rd party extension.

If you search extensions for 'folding' you should see several. Explicit Folding appears to have options to control this. But there are a lot more. Take a look & see if one fits your needs. If not then the only way to get this would be to develop an extension to handle this the way you want.

Sign up to request clarification or add additional context in comments.

Comments

0

While not an ideal, a quick and dirty solution that one can use today is to set custom ranges: in the example above,

  . another note
   . more details

  another topic

put the cursor after "note" and select the text to the end of "details", then press ctrl+k, ctrk+, ("Create Folding Range from Selection"). The result will be

+ . another note

  another topic

as needed; the obvious downside is that one has to create such ranges manually. But if you have not that much problematic blocks, it can be good enough (at least it's quick and doesn't require any plugins).

Comments

0

I too would like a better solution as sometimes setting custom folding doesnt work in my workflow.
My work-around is to whack a comment before the whitespace that I don't want folded:

a topic
. a note
 ? a question regarding the note
  - a to do item
 . some more details
. another note
 . more details
#END a topic

another topic
...

->

+a topic
#END a topic

another topic

In Practical use: I add that trailing comment to all my class-def snippets (etc) so they automatically preserve the whitespace after that definition without needing custom folding regions
:-(

If someone knows how to tell VSCode to simply never cull empty lines, my problem would be solved without needing my work-around.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.