Last active
August 29, 2015 14:22
-
-
Save Olical/deb15c33bd0e254b329b to your computer and use it in GitHub Desktop.
Auto expansion for my JavaScript conceal characters based on syntax type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " These bindings allow my conceal characters to work both ways. So if I type | |
| " @, it is actually translated to this. I have conceal set up to render this | |
| " as @. So I essentially have my own flavour of JavaScript but only in my Vim. | |
| " Fantastic. | |
| " Returns a mapped version of the list. | |
| " http://learnvimscriptthehardway.stevelosh.com/chapters/39.html#higher-order-functions | |
| function! Mapped(fn, l) | |
| let new_list = deepcopy(a:l) | |
| call map(new_list, string(a:fn) . '(v:val)') | |
| return new_list | |
| endfunction | |
| " Expands the given character as long as it's not in a comment or string. | |
| function! s:syntax_expand(from, to) | |
| let syntax = synIDtrans(synID(line("."), col(".") - 1, 1)) | |
| let blacklist = Mapped(function("hlID"), ["Comment", "String"]) | |
| if index(blacklist, syntax) == -1 | |
| return a:to | |
| else | |
| return a:from | |
| endif | |
| endfunction | |
| inoremap <silent> @ <C-r>=<SID>syntax_expand("@", "this")<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment