1

So i am using abduco. I have an abduco session and lets say I reattach to it at a later point. Then, for some reason, I am not able to move around in vim. Specifically the mouse and the keys stop working. This can probably be fixed in abduco (I don't know though). But I did notice that if I quit vim and started it again then I was able to navigate using the keys and mouse. So I wanted to know if there was a quick way to restart vim with all the windows as they are.

  • 1
    :mksession and :source Session.vim ? – Maxim Kim Mar 10 at 12:14
  • Thanks. It worked. – Samarth S Mar 10 at 12:40
5

The best move here is to use sessions. As @Maxim Kim notes in the comments, one way to do that is with :mksession and :source Session.vim.

But I'll show you two other tricks.

  1. vim has a -S flag that can be used to source an arbitrary vimscript file; it defaults to Session.vim—so this means you can just type vim -S in your shell to start back from a session!
  2. I actually use a (bash) function in my shell for this same trick:
vs () { 
  if (($# > 0)); then
    local session="$1"
    shift
    vim "$@" -S "$session"
  else
    vim -S
  fi
}
  1. I use tpope’s Obsession for easy session management. It has a host of benefits, but the main ones include

    • automatic session updating,
    • saves only the relevant stuff
    • a statusline indicator to let me know when I'm actually using a obsession session

From its README (10th March 2020):

  • Instead of making me remember to capture the session immediately before exiting Vim, allow me to do it at any time, and automatically re-invoke :mksession immediately before exit.
  • Also invoke :mksession whenever the layout changes (in particular, on BufEnter), so that even if Vim exits abnormally, I'm good to go.
  • If I load an existing session, automatically keep it updated as above.
  • If I try to create a new session on top of an existing session, don't refuse to overwrite it. Just do what I mean.
  • If I pass in a directory rather than a file name, just create a Session.vim inside of it.
  • Don't capture options and maps. Options are sometimes mutilated and maps just interfere with updating plugins.

Use :Obsess (with optional file/directory name) to start recording to a session file and :Obsess! to stop and throw it away. That's it. Load a session in the usual manner: vim -S, or :source it.

There's also an indicator you can put in 'statusline', 'tabline', or 'titlestring'. See :help obsession-status.

| improve this answer | |
  • 2
    Answer could use more details. Link to plug-in? What does this plug-in do? What's the advantage it offers over manually managing your sessions with :mksession? Any caveats to be aware of? – filbranden Mar 10 at 15:04
  • 1
    I'm genuinely curious! 😁 I haven't been a user of sessions or of this plug-in, so I'd relish the opportunity to get your take on it, since I already knew you're a fan. – filbranden Mar 10 at 17:34
  • @delete-vote can probably be retracted now? – D. Ben Knoble Mar 11 at 1:57
  • Thanks! (I haven't voted to delete it... Don't see that vote, myself.) – filbranden Mar 11 at 1:59
  • 1
    @filbranden perhaps only I can see it bc I wrote the post? Anyway, not worried :P – D. Ben Knoble Mar 11 at 1:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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