Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I preserve folds in VIM when cutting and pasting?

Tags:

vim

In vim, you can create a fold with zf, so if is %, you can neatly fold a delimited block.

  • is there a way to select some text in visual mode and automatically fold that?

  • I've noticed that if I select a closed fold and use dd to delete it, then go somewhere else and use P to paste it, the fold will disappear and the fold will be expanded. I want to cut the folded stuff and paste it and have it paste with the folds still intact and closed.

like image 811
eeeeaaii Avatar asked Oct 15 '22 05:10

eeeeaaii


2 Answers

  • You can do the first if you use :set foldmethod=manual and then simply highlight the block you want and use zf to fold it.
  • I don't think you can do this (at least, not without a script)
like image 170
Daniel DiPaolo Avatar answered Oct 21 '22 03:10

Daniel DiPaolo


Vim has several different fold strategies; I assume you are talking about manual folding.

Unfortunately, yanking and pasting does not keep the fold in-tact. You may be able to create a script that will re-fold pasted text, but it seems like it would be more annoying than useful in the end.

like image 21
Jay Avatar answered Oct 21 '22 02:10

Jay