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
You can try to set this value:
set foldmethod=syntax
-
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 usingvi
.– TornaxO7Commented Apr 27, 2021 at 9:11 -
1I 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
.– statoxCommented Apr 27, 2021 at 9:19