'VIM: Open all folds around current line
I'm trying to write a vim function, which would fold everything except current line/block/method.
Here is what I already wrote:
set foldemethod=indent
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FOCUS ON BLOCK OF CODE (fold everything else)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! FocusOnBock()
:normal! zM " close all folds
:normal! zozozozozozozozozo " I hope enough to open all nested folds :)
:normal! zz " center the current line
endfunction
:command! FocusOnBock :call FocusOnBock()
:map <leader>F :FocusOnBock<CR>
Here I close all folds, then open many folds (more then usually exists in good code), and then I center the current line. BTW, you can see it in action - http://ascii.io/a/1771
I don't like :norm! zozozozozozozozozo line. Is there a command to open all folds around current line without moving the cursor?
Solution 1:[1]
If you want open all folds in whole buffer, you can use zR
http://vim.wikia.com/wiki/Folding - Opening and closing folds
The command zr reduces folding by opening one more level of folds throughout the whole buffer (the cursor position is not relevant). Use zR to open all folds.
Solution 2:[2]
If you want to open all folds recursively within the current line, zO works
from https://vim.fandom.com/wiki/Folding The commands zc (close), zo (open), and za (toggle) operate on one level of folding, at the cursor. The commands zC, zO and zA are similar, but operate on all folding levels (for example, the cursor line may be in an open fold, which is inside another open fold; typing zC would close all folds at the cursor).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Václav Zindulka |
| Solution 2 | vkt |
