Skip to content

Instantly share code, notes, and snippets.

@isomorphisms
Last active October 11, 2018 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isomorphisms/e545bb1efb5493052cd6b98d0b2d90bc to your computer and use it in GitHub Desktop.
Save isomorphisms/e545bb1efb5493052cd6b98d0b2d90bc to your computer and use it in GitHub Desktop.
"=============================================================================
" What Is This: Prettify .Rmd and .R scripts in vim
" Who made it?: Vincent Barbroux
" https://github.com/Twinside/vim-haskellConceal/blob/master/after/syntax/haskell.vim
" ideas imported also from: https://alok.github.io/2018/04/26/using-vim-s-conceal-to-make-languages-more-tolerable/
" Who adapted it? isomorphisms@sdf.org
" Last change: 10 Oct 2018
" Require:
" set nocompatible
" somewhere on your .vimrc
"
" Vim 7.3 or Vim compiled with conceal patch.
" Use --with-features=big or huge in order to compile it in.
"
" Usage:
" Drop this file in your
" ~/.vim/after/syntax folder (Linux/MacOSX/BSD...)
" ~/vimfiles/after/syntax folder (Windows)
"
" For this script to work, you have to set the encoding
" to utf-8 :set enc=utf-8
"
" Additional:
" * if you want to avoid the loading, add the following
" line in your .vimrc :
" let g:no_r_conceal = 1
"
" * yet somehow change s/haskell/r/.
"if exists('g:no_r_conceal' || !has('conceal') || &enc != 'utf-8'
" finish
"endif
" vim: set fenc=utf-8:
" NOTE TO MAC USERS:
" Apple’s `vi` command was NOT compiled with `+conceal`.
" (you can see this with `vi --version | tr ' ' '\n' | grep '-'`)
" Homebrew’s `brew install vim` version 8.1 WAS compiled with `+conceal`
" (you can see this with `vim --version | tr ' ' '\n' | grep '+'`)
" if you don’t understand where these things are kept
" or how they are coded
" use the `type` command eg `type vi; type vim`
" and `ls -oh /usr/local/bin/vim` to see where
" the `/usr/local/bin` link *points to*.
" If you decide you want to compile vim from source, it’s
" on github.com/vim/vim, so `cd /opt` and `git clone git://github.com/vim/vim`
" then `less Makefile`; ctrl-Z; `./configure --help | less` and use
" `d` and `u` to scroll or `/` to search through the
" various flags `vim` can be compiled with.
" NOTE TO ANYONE:
" some characters might not display for you
" and I like, might not care
"★, ∘, 〛, 〚, ∉, ∪, ∩, ∃, ∐, ∏, ι, ☡, ⥁, ↻, ▸, ◁, ◀, ※, 𝐒, 𝔹, ∁, ♀, ℘, 𝒬
"𝔻, 𝔼
"❗, ⬳
" %match%
" paste0, paste00
" format
" unclass, class
" enquos, quosure, quo_x_y, aes_x, quote, do.call, caller_env, !missing
" structure
" parent.frame
" ~
" unarguably helpful substitutions
syntax match assignment "<-" conceal cchar=
syntax match assignment "<<-" conceal cchar=
"
"long <<---, ⬳
syntax match assignment "->" conceal cchar=
"
"
syntax match comparison "<=" conceal cchar=
syntax match comparison ">=" conceal cchar=
syntax match comparison "!=" conceal cchar=
syntax match elem "%in%" conceal cchar=
syntax match mult "%\*%" conceal cchar=
syntax match mult "\*" conceal cchar=
syntax match math "\^2" conceal cchar=²
syntax match math "\*\*2" conceal cchar=²
syntax match math "\^ 2" conceal cchar=²
"syntax match noisy "function" conceal cchar=ƒ
syntax match minus "-" conceal cchar=
syntax match tidyverse "quosure" conceal cchar=𝒬
syntax match ggplot "aes" conceal cchar=𝒜
syntax match overkill "stop" conceal cchar=
syntax match overkill "lapply" conceal cchar=𝓛
syntax match overkill "sapply" conceal cchar=𝒮 "𝓢
syntax match overkill "vapply" conceal cchar=𝓥
"
"let s:extraConceal = 1
"" Some windows font don't support some of the characters,
"" so if they are the main font, we don't load them :)
"if has("win32")
" let s:incompleteFont = [ 'Consolas'
" \ , 'Lucida Console'
" \ , 'Courier New'
"" \ ]
"" let s:mainfont = substitute( &guifont, '^\([^:,]\+\).*', '\1', '')
"" for s:fontName in s:incompleteFont
"" if s:mainfont ==? s:fontName
"" let s:extraConceal = 0
"" break
"" endif
"" endfor
""endif
"
""if s:extraConceal
"" potentially silly substitutions — commented out
"syntax match kwargs "..." conceal cchar=…
"syntax match kwargs "..." conceal cchar=⎵
syntax match kwargs "\.\.\." conceal cchar=
"syntax match kwargs "..." conceal cchar=‿
"
"syntax match bache "%>%" conceal cchar=»
"
"syntax match negation "!" conceal cchar=¬
"syntax match sum "sum" conceal cchar=∑
"syntax match sum "sum" conceal cchar=𝔼 "we’re statisticians here, not
"mathematicians!
"syntax match sum "int" conceal cchar=∫
"syntax match math "/" conceal cchar=÷
"syntax match math "pi" conceal cchar=π
syntax match math "sqrt" conceal cchar=
syntax match math "\*" conceal cchar=
""syntax match math "*" conceal cchar=∗
""syntax match math "*" conceal cchar=×
""syntax match math "*" conceal cchar=•
syntax match math "\." conceal cchar=
"syntax match math "complex" conceal cchar=ℂ
syntax match math "NULL" conceal cchar=
syntax match math "TRUE" conceal cchar=
syntax match math "FALSE" conceal cchar=
syntax match math "Inf" conceal cchar=
syntax match kronecker "%o%" conceal cchar=
"
"syntax match verbose "length" conceal cchar=λ
"
"syntax match loop "apply" conceal cchar=∀ "sapply, lapply, mapply, tapply
"syntax match loop "for" conceal cchar=↻
"
"syntax match concatenation "c" conceal cchar=∁
"
""syntax match greek "hat" conceal cchar='̂'
"syntax match greek "gamma" conceal cchar=Γ
"
"
""syntax match overboard "\$" conceal cchar=§
"syntax match overboard "message" conceal cchar=µ
"syntax match overboard "warn" conceal cchar=ω
syntax match overkill "\[\[" conceal cchar=
syntax match overkill "\]\]" conceal cchar=
syntax match overkill "structure" conceal cchar= "� stupa 🏠
syntax match overkill "structure" conceal cchar=🏠
"
"
"syntax match questionable "\i\f" conceal cchar=ι
"
"
""stuff for matrix multiplication?
""ginv
""chol
""solve
""diag
""crossprod
""%*%
"syntax match overboard "t" conceal cchar=τ
"
""stuff for other %xx% operators? these are the noisiest
"
"
"
"" tidyverse / tinyverse / ggplot ideas
"
"
""turn their ubiquitous and super important . placeholder into a •
"
""endif
"
""hi link
"
"hi link hsNiceOperator Operator
"hi! link Conceal Operator
setlocal conceallevel=2
"test files used:
" - https://github.com/stan-dev/rstan/blob/develop/rstan/rstan/R/chains.R
" - my trim.R
" - some base r source
" - something from ggplot
" -
"where more than one idea could be had I put in each idea I had and uncommented my fav
"have fun! HTH
"=============================================================================
" What Is This: Prettify .Rmd and .R scripts in vim
" Who made it?: Vincent Barbroux
" https://github.com/Twinside/vim-haskellConceal/blob/master/after/syntax/haskell.vim
" ideas imported also from: https://alok.github.io/2018/04/26/using-vim-s-conceal-to-make-languages-more-tolerable/
" Who adapted it? isomorphisms@sdf.org
" Last change: 10 Oct 2018
" Require:
" set nocompatible
" somewhere on your .vimrc
"
" Vim 7.3 or Vim compiled with conceal patch.
" Use --with-features=big or huge in order to compile it in.
"
" Usage:
" Drop this file in your
" ~/.vim/after/syntax folder (Linux/MacOSX/BSD...)
" ~/vimfiles/after/syntax folder (Windows)
"
" For this script to work, you have to set the encoding
" to utf-8 :set enc=utf-8
"
" Additional:
" * if you want to avoid the loading, add the following
" line in your .vimrc :
" let g:no_r_conceal = 1
"
" * yet somehow change s/haskell/r/.
"if exists('g:no_r_conceal' || !has('conceal') || &enc != 'utf-8'
" finish
"endif
" vim: set fenc=utf-8:
" NOTE TO MAC USERS:
" Apple’s `vi` command was NOT compiled with `+conceal`.
" (you can see this with `vi --version | tr ' ' '\n' | grep '-'`)
" Homebrew’s `brew install vim` version 8.1 WAS compiled with `+conceal`
" (you can see this with `vim --version | tr ' ' '\n' | grep '+'`)
" if you don’t understand where these things are kept
" or how they are coded
" use the `type` command eg `type vi; type vim`
" and `ls -oh /usr/local/bin/vim` to see where
" the `/usr/local/bin` link *points to*.
" If you decide you want to compile vim from source, it’s
" on github.com/vim/vim, so `cd /opt` and `git clone git://github.com/vim/vim`
" then `less Makefile`; ctrl-Z; `./configure --help | less` and use
" `d` and `u` to scroll or `/` to search through the
" various flags `vim` can be compiled with.
" NOTE TO ANYONE:
" some characters might not display for you
" and I like, might not care
"★, ∘, 〛, 〚, ∉, ∪, ∩, ∃, ∐, ∏, ι, ☡, ⥁, ↻, ▸, ◁, ◀, ※, 𝐒, 𝔹, ∁, ♀, ℘, 𝒬
"ꕆ, ⸩, ⟫, ᙃ, ᗥ, ⳾, ⸨
"𝔻, 𝔼, ∽
"return ↔ carriage return
"new.env(), emptyenv
"something for () .. means Do It …… astrosun, lozenge, fullmoon, nabla, heart
"distinguish size of outer paren’s?
"❗, ⬳
" %match%
" paste0, paste00
" format
" unclass, class
" enquos, quosure, quo_x_y, aes_x, quote, do.call, caller_env, !missing
" structure
" plot, qplot
" parent.frame
" ~
" ::
"
"
" map similar enough stuff to the SAME symbol
" is.null, NULL
" is.character, character, as.character
" totally hide the commentary lines # (toggle-able)
" unarguably helpful substitutions
syntax match assignment "<-" conceal cchar=←
syntax match rArrow "<-" conceal cchar=←
syntax match assignment "<<-" conceal cchar=⬳
syntax match rArrow "<<-" conceal cchar=⬳
"↞
"long <<---, ⬳
syntax match assignment "->" conceal cchar=⟶
syntax match rArrow "->" conceal cchar=⟶
"⟶
"→
syntax match comparison "<=" conceal cchar=≤
syntax match comparison ">=" conceal cchar=≥
syntax match comparison "!=" conceal cchar=≠
syntax match overkill "warning" conceal cchar=𝓦 "❓
syntax keyword rConditional if conceal cchar=¬
"data.frame 𝔻, 𝒟
"vector 𝒱
"@export
"close to unarguable
syntax match importantYetHardToSee "x" conceal cchar=𝑥 "𝐱
syntax match importantYetHardToSee "y" conceal cchar=𝑦 "𝐱
syntax match importantYetHardToSee "z" conceal cchar=𝑧 "𝐱
syntax match comparison "==" conceal cchar=≡
syntax match elem "%in%" conceal cchar=∈ "∋
syntax match mult "%\*%" conceal cchar=※
syntax match mult "\*" conceal cchar=∙
"⋅ "∙ ∘
syntax match math "\^2" conceal cchar=²
syntax match math "\*\*2" conceal cchar=²
syntax match math "\^ 2" conceal cchar=²
syntax keyword rType function conceal cchar=ƒ
"syntax keyword rType "function" conceal cchar=ƒ
syntax match tidyverse "ggplot" conceal cchar=𝒢
syntax match tidyverse "aesthetic" conceal cchar=𝒜
syntax match tidyverse "mapping" conceal cchar=𝓜
syntax match minus "-" conceal cchar=−
syntax match tidyverse "quosure" conceal cchar=𝒬
syntax match ggplot "aes" conceal cchar=𝒜
syntax match overkill "stop" conceal cchar=❗
syntax match overkill "missing" conceal cchar=❓
syntax match overkill "lapply" conceal cchar=𝓛
syntax match overkill "sapply" conceal cchar=𝒮 "𝓢
syntax match overkill "vapply" conceal cchar=𝓥
syntax match overkill "list" conceal cchar=ᥨ "𝑳
syntax match overkill "cat" conceal cchar=𝒞
syntax match rRepeat "while" conceal cchar=⥁
"
"let s:extraConceal = 1
"" Some windows font don't support some of the characters,
"" so if they are the main font, we don't load them :)
"if has("win32")
" let s:incompleteFont = [ 'Consolas'
" \ , 'Lucida Console'
" \ , 'Courier New'
"" \ ]
"" let s:mainfont = substitute( &guifont, '^\([^:,]\+\).*', '\1', '')
"" for s:fontName in s:incompleteFont
"" if s:mainfont ==? s:fontName
"" let s:extraConceal = 0
"" break
"" endif
"" endfor
""endif
"
""if s:extraConceal
"" potentially silly substitutions — commented out
"syntax match kwargs "..." conceal cchar=…
"syntax match kwargs "..." conceal cchar=⎵
syntax match kwargs "\.\.\." conceal cchar=⎵
"syntax match kwargs "..." conceal cchar=‿
"
"syntax match bache "%>%" conceal cchar=»
"
"syntax match negation "!" conceal cchar=¬
"syntax match sum "sum" conceal cchar=∑
"syntax match sum "sum" conceal cchar=𝔼 "we’re statisticians here, not
"mathematicians!
"syntax match sum "int" conceal cchar=∫
"syntax match math "/" conceal cchar=÷
"syntax match math "pi" conceal cchar=π
syntax match math "sqrt" conceal cchar=√
syntax match math "\*" conceal cchar=⋅
""syntax match math "*" conceal cchar=∗
""syntax match math "*" conceal cchar=×
""syntax match math "*" conceal cchar=•
"syntax match math "\." conceal cchar=•
"syntax match math "complex" conceal cchar=ℂ
syntax keyword rConstant NULL conceal cchar=∅
"box for args
"tetraform for matrix
"vars
"names
syntax match "intersect" conceal cchar=∪⊃⊂
"match.call
syntax keyword rType is.null conceal cchar=∅
syntax match rBoolean "TRUE" conceal cchar=⊤
syntax match rBoolean "FALSE" conceal cchar=⊥
syntax match rConstant "Inf" conceal cchar=∞
syntax match kronecker "%o%" conceal cchar=⊗
"
syntax match verbose "length" conceal cchar=λ
"
"syntax match loop "apply" conceal cchar=∀ "sapply, lapply, mapply, tapply
"syntax match loop "for" conceal cchar=↻
"
"syntax match concatenation "c" conceal cchar=∁
"
""syntax match greek "hat" conceal cchar='̂'
"syntax match greek "gamma" conceal cchar=Γ
"
"
""syntax match overboard "\$" conceal cchar=§
"syntax match overboard "message" conceal cchar=µ
"syntax match overboard "warn" conceal cchar=ω
syntax match overkill "\[\[" conceal cchar=〚
syntax match overkill "\]\]" conceal cchar=〛
syntax match overkill "structure" conceal cchar=⌂ "� stupa 🏠
syntax match overkill "structure" conceal cchar=🏠
"
"
"syntax match questionable "\i\f" conceal cchar=ι
"
"
""stuff for matrix multiplication?
""ginv
""chol
""solve
""diag
""crossprod
""%*%
"syntax match overboard "t" conceal cchar=τ
"
""stuff for other %xx% operators? these are the noisiest
"
"
"
"" tidyverse / tinyverse / ggplot ideas
"
"
""turn their ubiquitous and super important . placeholder into a •
"
""endif
"
""hi link
"
"hi link hsNiceOperator Operator
"hi! link Conceal Operator
setlocal conceallevel=2
hi Conceal ctermbg=NONE
"test files used:
" - https://github.com/stan-dev/rstan/blob/develop/rstan/rstan/R/chains.R
" - my trim.R
" - some base r source
" - something from ggplot
" -
"where more than one idea could be had I put in each idea I had and uncommented my fav
"have fun! HTH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment