Closed datanoise closed 12 years ago
Does it happen if you comment out line 731 and 735 in the autoload/ctrlp.vim file? Also try with line 1362, separately.
Nope. Commenting lines 731 and 735 doesn't help, as well as line 1362.
It seems like switching buffers make Vim to reevaluate modeline for some reason.
Yep, I also get this just using :bnext
, :bprev
or <c-^>
with files that have folds defined in modeline. So it's not a problem with ctrlp. It's just Vim.
I don't see this issue when using :bn
, :bp
, <c-^>
or any other standard buffer switching commands. No issue with using BufExplorer or Command-T either. I would file a bug report to Bram if that was a standard behavior a long time ago :)
Weird, I definitely get it with this modeline for my plugin files:
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
And this in vimrc:
se foldmethod=marker
se foldlevel=1
se foldnestmax=10
se nofoldenable
If I'm outside a fold, <c-^>
away and back will close all folds.
Hm, strange. I've just tested your modeline and I don't see that behavior when switching back and forth with <c-^>
. Must be something to do with your setup. I do see that when I'm using CtrlPBuffer
though.
OK, I tried again with --noplugin, <c-^>
definitely closes all the folds, even if the cursor's in a fold when switching away:
vim --noplugin -u .vimrc
.vimrc
se nocp
"runtime! plugin/ctrlp.vim
With 2 buffers: buffertag.vim and dir.vim from autoload/ctrlp/
.
Vim 7.3.401
Alright, I searched around a bit to make sure I wasn't crazy or missed something. Someone had the same question on StackOverflow with using NERDTree: all folds close when switching to a different file and back
http://stackoverflow.com/questions/7221318/vim-nerdtree-folding-can-it-remember-the-state-of-folds
So if your tests are correct, cmd-t and bufexplorer probably do something to override this default behaviour of Vim.
This is really weird. Actually, just tried that with Command-T
and in some cases I see the same issue, but I don't see it when I switch with <c-^>
or BufExplorer
.
And I'm using the same revision number 7.3.401. That must be indeed a Vim's bug. I will try to debug it if the time permits.
I think I have found the issue. CtrlPBuffer uses :edit command to switch to a buffer, which makes Vim to reevaluate modeline. Please consider this patch:
diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim
index a95df44..a942e69 100644
--- a/autoload/ctrlp.vim
+++ b/autoload/ctrlp.vim
@@ -734,8 +734,10 @@ fu! ctrlp#acceptfile(mode, matchstr, ...)
el
" Determine the command to use
let cmd = md == 't' || s:splitwin == 1 ? 'tabe'
- \ : md == 'h' || s:splitwin == 2 ? 'new'
- \ : md == 'v' || s:splitwin == 3 ? 'vne' : ctrlp#normcmd('e')
+ \ : md == 'h' || s:splitwin == 2 ? (s:itemtype == 1 ? 'sb' : 'new')
+ \ : md == 'v' || s:splitwin == 3 ? (s:itemtype == 1 ? 'vert sb' : 'vne')
+ \ : md == 'e' && s:itemtype == 1 ? 'b'
+ \ : ctrlp#normcmd('e')
" Open new window/buffer
cal call('s:openfile', a:0 ? [cmd, filpath, ' +'.a:1] : [cmd, filpath])
en
That would work only if hidden
option is set, otherwise this patch has no effect.
I don't see it when I switch with
<c-^>
And as you said later:
uses :edit command to switch to a buffer, which makes Vim to reevaluate modeline
But from the description in Vim's help:
CTRL-^ edit Nth alternate file (equivalent to ":e #N")
Seems like there's something else in your config that changes the behavior of <c-^>
or :edit #N
.
But set hidden
does help when using the :buffer
commands. So there's our use case. However, this patch doesn't account for commands after :
(fail to open the buf), so I'll need to work it into the code and will commit later along with the others.
Thanks for the help!
Ah, you are right. I do have <c-^>
redefined. I completely forgot about it.
Thanks for looking into that issue anyway.
When switching to a previous buffer with CtrlPBuffer, this buffer is displayed with all folds closed. This is quite annoying since I lose track where I was editing previously.