1

I can successfully toggle between different conceal levels in Neovim, which is rather handy when working with markdown documents. Also, when working with with multiple documents in a Neovim session, I save the state of the open documents to a session file so I can pick up where I left off, ie. not having to reopen all the documents I had open in the previous session, however the conceal level isn't preserved when relaunching a Neovim session.

I'm sure there is a way to preserve the conceal level of a document on a per file / session basis, I just don't know how to do that.

I'm saving Neovim sessions with the below Vimscript, sessions.vim

" CREDIT: https://stackoverflow.com/a/47656092/708807

function! MakeSession(overwrite)
  if &filetype ==? 'man'
    return
  else
    let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
    if (filewritable(b:sessiondir) != 2)
      exe 'silent !mkdir -p ' b:sessiondir
      redraw!
    endif
    let b:filename = b:sessiondir . '/session.vim'
    if a:overwrite == 0 && !empty(glob(b:filename))
      return
    endif
    exe "mksession! " . b:filename
  endif
endfunction

function! LoadSession()
  if &filetype ==? 'man'
    return
  else
    let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
    let b:sessionfile = b:sessiondir . "/session.vim"
    if (filereadable(b:sessionfile))
      exe 'source ' b:sessionfile
    else
      echo "No session loaded."
    endif
  endif
endfunction

" Adding automatons for when entering or leaving Vim
if(argc() == 0)
  au VimEnter * nested :call LoadSession()
  au VimLeave * :call MakeSession(1)
else
  au VimLeave * :call MakeSession(0)
endif

1 Answer 1

1

Another week, another Saturday night 🥃.

I added the below line to the above posted sessions.vim file, and now custom code folds, and conceal levels are being persisted through Vim / Neovim restarts. ✧。٩(ˊᗜˋ)و✧*。

set sessionoptions=folds,localoptions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.