0

I always come across a lot of code wrapped in {}s while reading, and I wondered if there was a way for vi to automatically fold these {}s instead of manually marking them.

1 Answer 1

1

You can try to set this value:

set foldmethod=syntax
3
  • I open a file with "vi", and enter "set foldmethod=syntax" which works well. But if I add "set foldmethod=syntax" to the vimrc, it doesn't work. Commented Apr 27, 2021 at 8:14
  • Oh, I thought you're using vim not vi. I don't even have the option 'foldmethod'. Anyway according to the man page of vi, you should put set foldmethod=syntax into your $HOME/.exrc file if you're using vi.
    – TornaxO7
    Commented Apr 27, 2021 at 9:11
  • 1
    I don't think OP's issue comes from the fact they are using vi (they probably have aliased 'vi' to 'vim' like in most distributions today). The issue is that if you read :h 'foldmethod' you'll see that this option is local to a window, so setting it up in the .vimrc doesn't affect the other windows. One will need to either use an autocommand (e.g. :h BufReadPost) or a ftplugin :h ftplugin-overrule.
    – statox
    Commented Apr 27, 2021 at 9:19

Your Answer

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

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