vim-obsession icon indicating copy to clipboard operation
vim-obsession copied to clipboard

iskeyword clobbered when restoring

Open unphased opened this issue 7 years ago • 4 comments

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.

unphased avatar Aug 24 '16 15:08 unphased

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.

tpope avatar Aug 26 '16 01:08 tpope

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 avatar Aug 26 '16 22:08 unphased

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.

unphased avatar Aug 26 '16 23:08 unphased

@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.

benknoble avatar Jan 28 '19 00:01 benknoble