Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: Open all folds around current line

Tags:

vim

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?

like image 523
cutalion Avatar asked Dec 09 '22 18:12

cutalion


1 Answers

Yes, there is: zv:

zv View cursor line: Open just enough folds to make the line in which the cursor is located not folded.

like image 193
Ingo Karkat Avatar answered Feb 07 '23 23:02

Ingo Karkat