copy-pastevisual-studio-codefolding

Copy & paste folded text in Visual Studio Code


Given the following text

Node1_L1
  Node1_L2
  Node2_L2
Node2_L1
  Node3_L2
    Node1_L3
    Node2_L3
  Node4_L2
    Node3_L3
    Node4_L3
Node3_L1
  Node5_L2
  Node6_L2  

I can use vscode's built-in folding feature to fold it to look like so

+ Node1_L1
  Node2_L1
+   Node3_L2
+   Node4_L2
  Node3_L1
    Node5_L2
    Node6_L2

but when I now select the folded text and copy & paste it then it actually grabbed all text - also the hidden one. The result of copy & paste of the first 4 lines of the folded text above would therefore be

Node1_L1
  Node1_L2
  Node2_L2
Node2_L1
  Node3_L2
    Node1_L3
    Node2_L3
  Node4_L2

whereas I would like to have

Node1_L1
Node2_L1
  Node3_L2
  Node4_L2  

Hope that makes sense and someone knows a way to do it. Thanks!


Solution

  • Maybe there is another way of doing it but a workaround seems to be using block selection with multiple cursors - see the GIF

    Block selection to copy only top level folding text