Vim Scripting Cheat Sheet

hoanganhlam

Lam

Posted on May 13, 2021

Vim Scripting Cheat Sheet

[Strings] Include guards

if exists('g:loaded_myplugin')
  finish
endif

" ...

let g:loaded_myplugin = 1
Enter fullscreen mode Exit fullscreen mode

[Strings] Syntax

syn match :name ":regex" :flags

syn region Comment  start="/\*"  end="\*/"
syn region String   start=+"+    end=+"+     skip=+\\"+

syn cluster :name contains=:n1,:n2,:n3...

flags:
  keepend
  oneline
  nextgroup=
  contains=
  contained

hi def link markdownH1 htmlH1
Enter fullscreen mode Exit fullscreen mode

[Strings] Region conceal

syn region inBold concealends matchgroup=bTag start="<b>" end="</b>"
hi inBold gui=bold
hi bTag guifg=blue
Enter fullscreen mode Exit fullscreen mode

[Strings] Conceal

set conceallevel=2
syn match newLine "<br>" conceal cchar=}
hi newLine guifg=green
Enter fullscreen mode Exit fullscreen mode

[Strings] Filetype detection

augroup filetypedetect
  au! BufNewFile,BufRead *.json setf javascript
augroup END

au Filetype markdown setlocal spell
Enter fullscreen mode Exit fullscreen mode

[Strings] Highlights

hi Comment
  term=bold,underline
  gui=bold
  ctermfg=4
  guifg=#80a0ff
Enter fullscreen mode Exit fullscreen mode

[Strings] Arguments

| <buffer> | only in current buffer |
| <silent> | no echo |
| <nowait> | |

Syntax

[Strings] Explanation

[nvixso](nore)map
Enter fullscreen mode Exit fullscreen mode
 β”‚       β”” don't recurse
 β”‚
 β”” normal, visual, insert,
   eX mode, select, operator-pending
Enter fullscreen mode Exit fullscreen mode

[Strings] Mapping commands

nmap
vmap
imap
xmap
nnoremap
vnoremap
inoremap
xnoremap
...
Enter fullscreen mode Exit fullscreen mode

[Strings] Built-ins

has("feature")  " :h feature-list
executable("python")
globpath(&rtp, "syntax/c.vim")

exists("$ENV")
exists(":command")
exists("variable")
exists("+option")
exists("g:...")
Enter fullscreen mode Exit fullscreen mode

Mapping

Reference

πŸ’– πŸ’ͺ πŸ™… 🚩
hoanganhlam
Lam

Posted on May 13, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related