tpope / vim-obsession

obsession.vim: continuously updated session files
http://www.vim.org/scripts/script.php?script_id=4472
1.76k stars 70 forks source link

iskeyword clobbered when restoring #26

Open unphased opened 8 years ago

unphased commented 8 years ago

My C++ files end up loading up (when restoring with vim -S or nvim -S) with iskeyword having gained a - which causes problems for various reasons.

What's confusing to me is that the Session.vim file has no mention of iskeyword inside of it. And using verbose set iskeyword? does NOT show me where it got set/changed.

I also acknowledge that this is likely not an error with or caused by obsession... but hopefully someone has a clue for me.

tpope commented 8 years ago

Are you loading only C++ files? My hunch is that some rogue runtime file is mucking with the global value, and the session is only relevant because that triggers it at startup.

unphased commented 8 years ago

Well, I'm still confused, but I can verify that it happens with vim as well as nvim so that means something specific and potentially tractable is likely at the root of this.

I'm working on reproducing this with a more "minimal" Session.vim file.

unphased commented 8 years ago

OK I found what I believe is the culprit. Whenever the session I'm restoring includes both C++ and JS files, this happens, because my ~/.vim/after/ftplugin/javascript.js contains the line set iskeyword+=-.

For whatever reason (maybe the cause are the argglobal or some other such thing strewn about these Session.vim files), that appears to be getting run on the filetypes that it isn't intended for.

I have also tested that if I replace my after/ftplugin tweaks to iskeyword using setlocal that this solves the problem!

I don't know enough about setlocal or ftplugin or Vim and Vim best practices in general to say whether this is a problem with Vim's mksession stuff, this plugin, or whatever else. All I can tell is that iskeyword is supposedly local to a buffer (that's what help says), therefore the use of setlocal theoretically is redundant, but clearly is not in this scenario.

For now I will be changing all these type of tweaks to setlocal and I can happily resume using sessions again.

benknoble commented 5 years ago

@unphased (Buffer-)Local options are only changed locally when using setlocal; otherwise, they are set globally. It is generally good practice to prefer setlocal (and *map <local>, &c.) in ftplugin files for this reason.

This can probably be closed.