DEV Community

Lam
Lam

Posted on

2 1

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay