When toggling folds with zi, any folds expanding above the current line cause the current line to disorientingly jump to a different place on the screen.

How can I keep the current line fixed in the same place while toggling folds?

Instead of zi you should use zo to open a fold and zc to close it or za to toggle the fold. These commands never make the current line jump for me.

Note that these commands have a recursive equivalent: zC, zO and zA

See

  • Sure, but sometimes I want additional context from surrounding code and just want to temporarily dismiss all folds. Going around and manually opening nearby folds with zA wouldn't cause unexpected jumps, but it would undoubtedly take a lot more keystrokes. – gandalf3 Apr 23 at 7:14
  • 1
    @gandalf3 Oh I didn't understood your use case properly. I'm not sure you'll get a good solution: zR and zM seems to move the current line too so you might have to write a function which will save the position, handle the folds and restore the position back. – statox Apr 23 at 7:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.