Comments (9)
I've added some <Plug> mappings, that I think do what your asking for. Here's what you can put in your vimrc to try them out.
nmap zO <Plug>(fold-cycle-open-all)
nmap zC <Plug>(fold-cycle-close-all)
nmap zA <Plug>(fold-cycle-toggle-all)
Let me know how these work out for you. I'm the least confident in the behavior of the zA mapping out of the 3.
from vim-fold-cycle.
Thank you very much. zO
and zC
work as expected.
I am also not confident about zA
in general.
Does your implementation try to toggle all contained folds (my current expectation)?
Consider this file:
A (open) {{{1
B1 (open) {{{2
in B1
B2 (closed) {{{2
in B2
# vim: fdm=marker
Close B2
with zc
and then move the cursor on A
.
Pressing zA
should close B1
and A
but open B2
, right?
However, opening A
again with zo
shows that all nested folds are closed.
from vim-fold-cycle.
There is another issue: FastFold and these mappings remap zA
, zC
and zO
.
According to Konfekt/FastFold#14 FastFold does not support custom fold mappings and this has to be done by oneself which they claim is not straightforward.
Do you have further insight how one could achieve this?
from vim-fold-cycle.
Thanks for the idea for zC and zO, they are a great addition to this plugin.
Unfortunately my heart isn't in it to try to implement this behavior for zA, or make the plugin play nice with FastFold. I just don't see either being straight forward, or useful enough to motivate me, to work on them.
from vim-fold-cycle.
I understand. However, I am already quite happy with zC
and zO
(excited if it would work together with FastFold 😃 ). Thanks again.
Doc
Do you like to add some documentation (doc/fold-cycle.txt, README.md) about <Plug>(fold-cycle-[open,close,toggle]-all)
?
I add here examples where the supercharged versions work differently compared to the builtin ones.
Demo file
A {{{1
in A
B1 {{{2
in B1
B2 {{{2
in B2
# vim: fdm=marker
zC
Initial configuration all folds open (A, B1, B2) and cursor on line 1.
-
Built-in Behavior
PressingzC
closes ONLY fold A which is the same aszc
.
Note, if you would close the top fold withzc
, you can fold all withVzC
. -
Supercharged Behavior
PressingzC
closes ALL folds A, B1, B2.
zO
Initial configuration fold A is open but B1 and B2 are closed. Again cursor on line 1.
-
Built-in Behavior
PressingzO
does nothing.
Note, if you would again close the top fold withzc
, you can open ALL nested folds withzO
. -
Supercharged Behavior
PressingzO
opens ALL folds A, B1, B2.
zA
zA
can be used if you do not want to use zC
and zO
but a single command to decide based on the current fold whether you want to open or close recursively all folds.
But you still need other commands to open folds individually to profit from several fold levels.
Originally, I used the spacebar
to toggle folds:
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
from http://vim.wikia.com/wiki/Folding
However, I now use the spacebar
as my leaderkey and use mostly the following default fold commands:
zo
/zc
to open/close a single fold (formerly I used here thespacebar
),zO
/zC
to open/close folds recursively; now with your plugin!zR
/zM
to open/close all folds in the file.
I rarely feel the need for changing the level in the file with zr
/zm
.
If I would still have my old configuration, I could imagine following extended spacebar
behavior:
spacebar
toggle current single foldctrl-spacebar
toggle current folds recursively (yourzA
)ctrl-shift-spacebar
toggle all folds of the file.
But I now made the mental shift to use two kinds of commands open and close and stick to the vim way.
I think your plugin with the cyclic recursive behavior and the suggested mappings <CR>
and <Backspace>
are really good but as I said I managed to get used to the vim way.
from vim-fold-cycle.
@arecarn May I ask you for an extension of the behavior of zC
(<Plug>(fold-cycle-close-all)
)?
A {{{1
B1 {{{2
in B1
B2 {{{2
in B2
C1 {{{3
in C1
C2 {{{3
CURSOR in C2
D1 {{{4
in D1
D2 {{{4
in D2
E1 {{{5
in E1
E2 {{{5
in E2
# vim: fdm=marker
I press zC
and it closes C2, D1, D2, E1, E2:
A {{{1
B1 {{{2
in B1
B2 {{{2
in B2
C1 {{{3
in C1
+---- 12 lines: C2 --------------------------------------------------------------------------
Now, I can use zc
to close each parent fold individually. But as you might expect, I would like to change the behaviour of zC
whether it is on an open or closed fold.
So when I am in the situation that the current fold is closed, I would like to fold all parent folds (B2 and A) to get:
+-- 19 lines: A -----------------------------------------------------------------------------
from vim-fold-cycle.
Following does what I want
nnoremap <silent><expr> zC foldclosed('.')==-1?
\ ':<C-u>call fold_cycle#close_all()<CR>':
\ 'zC'
from vim-fold-cycle.
BTW I think for zO
following is just fine:
nnoremap zO zvzczO
Update
My (hopefully final) mappings for zC
and zO
look like
nnoremap <silent><expr> zO foldclosed('.')==-1?
\ 'zczO':
\ 'zv'
nnoremap <silent><expr> zC foldclosed('.')==-1?
\ ':<C-u>call fold_cycle#close_all()<CR>':
\ 'zC'
(both have a two-step behavior)
from vim-fold-cycle.
I'll reopen this a reminder to take a look at this.
from vim-fold-cycle.
Related Issues (9)
- Add global fold cycling commands HOT 1
- when opening folds, should closed fold with lowest fold level and fold it first
- bell HOT 4
- add option to limit the levels cycled through
- Add option to enhance `zo` to open next level of closed child HOT 3
- Must I use `zc` to fold a block to use vim-fold-cycle? HOT 2
- disable vim-fold-cycle for specific FileType HOT 3
- not working in neovim without using zc or zM firstly. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-fold-cycle.