wincent/terminus

Terminus automatically closes vim folds in tmux

paulhybryant opened this issue · 13 comments

When the focus moves from the pane vim is in to another pane, all folds in vim will be closed.
I am wondering whether this is intended and if so is there an option to turn off this behavior?

Thanks,

Nope, this is not intended behavior (and I can't imagine why anyone could ever want this in a plug-in whose job is to improve integration with the terminal), but I've never seen this. If you look at the Terminus source code, you'll see there's not much to it, and certainly no fold-related commands, just some autocommands.

I suspect there's an interaction going on with something else in your set-up. Can you provide any more details on what plug-ins and other configuration you are using?

Thanks for the reply. I did looked at the source code before opening this issue and as you mentioned I didn't find any fold related command.
This is somehow related to terminus because if I disable terminus (I used NeoBundle for managing my plugins), this behavior goes away.
I also suspect that this is related to other plugins I installed.

I will try to find a minimal vimrc that can reproduce this issue.

Thanks,

I will try to find a minimal vimrc that can reproduce this issue.

Great! Let me know how you go.

The fold is closed because of autocmds.
If I use
:doautocmd FocusLost %

All folds will be closed. So far I haven't been able to identify which autocmds caused this. There is no autocmds defined for FocusLost in my settings (autocmd FocusLost shows nothing)
Will the above command cause other autocmds to be executed?
Any tips on how to identify that more effectively?

Thank you!

You could try doing:

:9verbose doautocmd FocusLost %

Which should show you everything being executed. You can crank the verbosity level up even higher if need be.

OK. Here is how to repro this.

A file with fold: test.txt
##########BEGIN OF FILE##########
" vim: filetype=vim sw=2 ts=2 sts=2 expandtab tw=80
" vim: foldlevel=0 foldmethod=marker nospell
" {{{
Hello World
" }}}
##########END OF FILE#########

.vimrc.repro
##########BEGIN OF FILE##########
set nocompatible

filetype off
set runtimepath+=$HOME/.vim/bundle/neobundle.vim/
call neobundle#begin('$HOME/.vim/bundle')

NeoBundleFetch 'Shougo/neobundle.vim'
NeoBundle 'christoomey/vim-tmux-navigator'
NeoBundle 'wincent/terminus'

filetype plugin indent on
call neobundle#end()
NeoBundleCheck
##########END OF FILE#########

Open a terminal.
Run tmux
Split tmux into two panes vertically
In the left pane, run
vi -u .vimrc.repro test.txt
Open all the fold

Press Ctrl-L to move to the right pane
The fold will be closed.

Remove "NeoBundle 'wincent/terminus'" and repeat these steps, the fold will not be closed.

That's an amazing repro recipe. Thanks for digging into that.

I'm able to repro this even without the involvement of vim-tmux-navigator. Also repros with foldmethod=indent. The key trigger seems to be the foldlevel=0 in the modeline; without it being in the modeline, even with an explicit set foldlevel=0, it doesn't repro. 'foldlevelstart' also doesn't cause the issue to repro.

Somehow the modeline is being reevaluated on losing focus. :h 'foldlevelstart' talks a little about when the modeline is evaluated, but I am still not sure what is going on here:

Sets 'foldlevel' when starting to edit another buffer in a window.
Useful to always start editing with all folds closed (value zero),
some folds closed (one) or no folds closed (99).
This is done before reading any modeline, thus a setting in a modeline
overrules this option.  Starting to edit a file for |diff-mode| also
ignores this option and closes all folds.
It is also done before BufReadPre autocommands, to allow an autocmd to
overrule the 'foldlevel' value for specific files.
When the value is negative, it is not used.

And bingo, the answer lies in :h :doautocmd:

        When the [group] argument is not given, Vim executes
        the autocommands for all groups.  When the [group]
        argument is included, Vim executes only the matching
        autocommands for that group.  Note: if you use an
        undefined group name, Vim gives you an error message.
                        *<nomodeline>*
        After applying the autocommands the modelines are
        processed, so that their settings overrule the
        settings from autocommands, like what happens when
        editing a file. This is skipped when the <nomodeline>
        argument is present. You probably want to use
        <nomodeline> for events that are not used when loading
        a buffer, such as |User|.

Fix should be easy enough, will just have to add <nomodeline> to the Terminus :doautocmd calls.

Thanks for the great report!

Fix is now in master. Thanks once again for the report!

Cool! Thanks for the detailed explanation, that is extremely helpful!
And thanks for the quick fix.

Another question though. With terminus enabled, using vim will result in some funny characters showing up in the terminal. Do you have any idea why this happens?

If needed I can open another issue related to this.
Thanks,
selection_001
selection_002
selection_003
selection_004

minimum vimrc to repro this:
set nocompatible
filetype off
set runtimepath+=$HOME/.vim/bundle/neobundle.vim/
call neobundle#begin('$HOME/.vim/bundle')
NeoBundleFetch 'Shougo/neobundle.vim'
NeoBundle 'wincent/terminus'
filetype plugin indent on
call neobundle#end()
NeoBundleCheck

This could be related to my zsh settings though?

Any insight to this? Thanks!

Not really sure what's going on there and I don't think I can repro. Would you mind creating a new issue for this?