Skip to content

Instantly share code, notes, and snippets.

@pryg-skok
Created November 24, 2016 09:22
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 pryg-skok/7e27d897fc3a19ebc89d33b062eac536 to your computer and use it in GitHub Desktop.
Save pryg-skok/7e27d897fc3a19ebc89d33b062eac536 to your computer and use it in GitHub Desktop.
augroup pythonFold
autocmd!
autocmd BufReadPre *.py setlocal foldmethod=indent
autocmd CursorMovedI *.py call LightlineContext()
autocmd CursorMoved *.py call LightlineContext()
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
normal! zR
execute "normal! " . saveCursor[1] . "G"
" Go to the beginning of the fold and put the line top of the upper split
normal! [zkk
normal! zt
let contextline=getline('.')
" Go back to bottom split and restore position
call setpos('.', saveCursor)
return contextline
endfunction
function! LightlineContext()
return PinFold()
endfunction
Config for lightline:
\ 'component_function': {
\ 'context': 'LightlineContext',
\ },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment