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?
Yes, there is: zv
:
zv View cursor line: Open just enough folds to make the line in which the cursor is located not folded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With