In default vim, whenever foldenable is set to false, the left-hand fold column becomes blank but continues to take up valuable screen real estate.

It would be better instead if the fold column automatically disappeared or became hidden whenever foldenable is set to false. And then become visible whenever it is set back to true.

Is there an easy way to do this?

Setting up mappings that change foldcolumn=0 and then back to foldcolumn=4 or something like that I think would be a little complicated because the foldenable option is auto-changed with several different normal-mode commands (zi, zm, zM, etc.).

  • 2
    I don't think there is an easy way to do it Feb 7, 2017 at 6:24

1 Answer 1


I don't know of a way to actively monitor a vim setting like foldenable for changes, and therein lies your main problem.

However, you can achieve a partial solution using autocommands. I don't know how often you change your foldenable setting, but normally I would think it to be either file or buffer specific. Often it is set in the file itself by a modeline at the end. This is pretty common and allows files to look nicely formatted and self-consistent, more or less independently of any user settings.

Create an autocommand for WinEnter and WinLeave which checks the foldenable setting and sets the foldcolumn accordingly (the following would go in your vimrc):

au! WinEnter,WinLeave * call CheckFoldColumnSetting()

function! CheckFoldColumnSetting()
    if foldenable == 1
        set foldcolumn = 4
        set foldcolumn = 0

You can then add more events if you want to monitor more often, such as file reads and writes, by changing the autocommand like so:

au! WinEnter,WinLeave,BufRead,BufWrite * call CheckFoldColumnSetting()
  • 2
    You could also do it on CursorHold. Or perhaps use a timer to constantly check, whether foldenable is set. Feb 8, 2017 at 16:42
  • @ChristianBrabandt Thanks that's a good one, I didn't think of that. Feel free to edit that into my answer if you like, or I can if you don't mind.
    – Tim
    Feb 8, 2017 at 16:46

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.