Open zeorin opened 8 years ago
Interesting new feature, thanks.
The blacklisting feature in my pencil
plugin uses a similar technique of examining the highlight group to determine if Vim's autoformat should be disabled.
I'll mark this as an enhancement for now as I don't have time to look into it deeper.
I know this plugin is designed primarily for prose, but I wanted smart quotes in comments in my code.
I've managed to do this. Currently it looks like this in my
.vimrc
:I've achieved this by loading the plugin for both text-like and non-text-like file types. For text-like file types,
Educate
is enabled when loading the plugin.For non-text-like file types (basically, for source code), the plugin is loaded, but
Educate
is not enabled. However, the configuration variable is still set to1
(after plugin init). I figured that the plugin only read it on initialization anyway (i.e. changing it after init doesn't change the plugin's behaviour), so I've reused it for the following purpose:In non-text-like file types:
1
, a function is run before a character is inserted in insert mode. This function checks to see whether we're currently in a piece of text that has a syntax group whose name contains the stringcomment
(case-insentive). If it does, enableEducate
. If it does not, disableEducate
.0
, don't even check what the current syntax group is, and therefore don't enableEducate
Educate
if we leave insert mode.The result is that I have smart quotes in my code's comments automatically. I am also able to toggle that off in case I need ASCII quotes in my comments (e.g. when typing a string in VimL, before the closing double quote is entered, Vim thinks we're in a comment—if I couldn't toggle
Educate
for comments I'd go mad).I developed and tested this on an Asus Transformer Book (T100TA), which has a wimpy little Atom processor. I didn't notice any performance impact.
I thought this might be of interest to others. Perhaps you'd like to add this functionality to your plugin, or mention this in the docs. ☺