Skip to content

Instantly share code, notes, and snippets.

@statox
Last active November 23, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statox/81cc7cecadca2bcfb038944ee47b20dd to your computer and use it in GitHub Desktop.
Save statox/81cc7cecadca2bcfb038944ee47b20dd to your computer and use it in GitHub Desktop.
Playing with vim folds
augroup pythonFold
autocmd BufReadPre *.py setlocal foldmethod=indent
autocmd CursorMovedI *.py call PinFold()
autocmd CursorMoved *.py call PinFold()
augroup END
function! PinFold()
" save current position
let saveCursor = getcurpos()
" Go to upper split, open all folds and go to the same line as bottom split
wincmd k
normal! zR
execute "normal! " . saveCursor[1] . "G"
" Go to the beginning of the fold and put the line in the middle of the upper split
normal! [z
normal! z.
" Go back to bottom split and restore position
wincmd j
call setpos('.', saveCursor)
endfunction
@statox
Copy link
Author

statox commented Nov 23, 2016

example gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment