dhruvasagar / vim-prosession

Handle vim sessions like a pro
254 stars 22 forks source link

vim -S not working #65

Closed sbeyer closed 4 years ago

sbeyer commented 4 years ago

Using vim -S <sessionfile> does not work after having a session.

Steps to reproduce:

  1. disable the plugin
  2. start vim, do something, do :mksession foo-session.vim, exit
  3. enable the plugin
  4. start vim, do something different, exit
  5. start vim -S foo-session.vim

Expected behavior:

You should be in the session of foo-session.vim (step 2).

Observed behavior:

You are in the session of step 4.

Workaround:

:source foo-session.vim loads the session (but replaces the current one and changes are not tracked for foo-session.vim).

Versions:

$ vim --version | head -n 2
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 24 2020 03:21:40)
Included patches: 1-439
dhruvasagar commented 4 years ago

Quoting from the vim documentation :

-S {file}   The {file} will be sourced after the first file has been read.
        This is an easy way to do the equivalent of: >
            -c "source {file}"
<       It can be mixed with "-c" arguments and repeated like "-c".
        The limit of 10 "-c" arguments applies here as well.
        {file} cannot start with a "-".

        Do not use this for running a script to do some work and exit
        Vim, you won't see error messages.  Use |-u| instead.

As you can see, the -S works slightly differently, it sources the given file after the first file has been read, so by this time all plugins have been loaded. When I wrote this plugin initially I remember coming across this problem and didn't find any easy way to detect if -S or for that matter, any other command line options have been passed to vim.