DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 967,611 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Lรขm
Lรขm

Posted on

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

Top comments (0)

๐ŸŒš Friends don't let friends browse without dark mode.

Sorry, it's true.