3

I've made changes to my _vimrc (windows) file since creating a session. I'm finding it impossible (using :source) to apply these changes to the session; it sticks stubbornly to the values as they were when the session was created. If I load a new instance of vim without loading the session I can see that my new settings are fine, but it seems the values I used previously are "burned in" to the session.

Is there a solution, or do I have to delete this session and recreate it?

I'm using the following plugins:

Plug 'ctrlpvim/ctrlp.vim'
Plug 'easymotion/vim-easymotion'
Plug 'altercation/vim-colors-solarized'
Plug 'justinmk/vim-syntax-extra'

Previously I had a mapping for / and ? to use easymotion to search, but I've since changed the vimrc file to leave those using the default vim search.

  • 1
    You should give more details, such as any plugins involved, and perhaps include a example of a setting you changed, then how you sourced and verified that it is unchanged. – mMontu Nov 26 '15 at 15:22
  • @mMontu Thanks for your interest; i've updated the question. I sourced the vimrc file using :source. Are you implying that some settings can be overriden and some can't? – user859 Nov 26 '15 at 16:01
5

The :map command defines a new mapping, while the :unmap removes them.

If you define a new mapping, it will remain there until you explicitly removes it. Your session file is probably saving it, so when you reload your session it is back. You can inspect the contents of your session file to confirm it.

Thus you probably can continue using your session if you execute the :unmap to remove the mappings for / and ? (on the command line, it is not necessary on the vimrc). Check :help :unmap and :help 40.1 for details.


Edit:

But it's still me manually changing one thing that my vimrc file contains; it can contain other things: autocommands, for example. I was hoping there'd be some way of saying "forgot the settings as they were at the point the session was created and use these new settings; burn these into the session"

If I understood you, you want to restore the settings after changing too many options/mappings/autocmds, thus it would be cumbersome to restore them manually. The 'sessionoptions' could be useful in this case:

Changes the effect of the |:mksession| command.  It is a comma
separated list of words.  Each word enables saving and restoring
something:
   word     save and restore ~
   blank    empty windows
   buffers  hidden and unloaded buffers, not just those in windows
   curdir   the current directory
   folds    manually created folds, opened/closed folds and local
        fold options
   globals  global variables that start with an uppercase letter
        and contain at least one lowercase letter.  Only
        String and Number types are stored.
   help     the help window
   localoptions options and mappings local to a window or buffer (not
        global values for local options)
   options  all options and mappings (also global values for local
        options)
   ...

Try ':set sessionoptions-=options', reload your session and then restore it with ':set sessionoptions+=options'.

If you need to do this often you should try some session plugin, such as session.vim, which provides the following command:

The *:RestartVim* command

This command saves your current editing session, restarts Vim and restores your
editing session. This can come in handy when you're debugging Vim scripts which
can't be easily/safely reloaded using a more lightweight approach [10]. It
should work fine on Windows and UNIX alike but because of technical limitations
it only works in graphical Vim.

Any commands following the |:RestartVim| command are intercepted and executed
after Vim is restarted and your session has been restored. This makes it easy
to perform manual tests which involve restarting Vim, e.g. ':RestartVim | edit
/path/to/file | call MyTest()'.

Using this plugin you could create a simple mapping that changes 'sessionoptions', restarts your session, and restore that option.

  • Ok, that works. But it's still me manually changing one thing that my vimrc file contains; it can contain other things: autocommands, for example. I was hoping there'd be some way of saying "forgot the settings as they were at the point the session was created and use these new settings; burn these into the session". Perhaps this is not possible. I'm gonig to mark your question as correct because it seems to describe the only sensible option. – user859 Nov 27 '15 at 9:50
  • 1
    @Alex I've updated the answer, maybe it fulfills your needs – mMontu Nov 27 '15 at 17:15

Your Answer

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