2 title: Vimscript functions
16 echo get(colors, "apple") " suppress error
18 remove(colors, "apple")
21 if has_key(dict, 'foo')
32 map(dict, '<>> " . v:val')
33 extend(s:fruits, { ... })
37 for key in keys(mydict)
38 echo key . ': ' . mydict(key)
46 let mylist = [1, two, 3, "four"]
52 let second = get(mylist, 1)
53 let second = get(mylist, 1, "NONE")
61 line('.') " current line number
65 getline('.') " current line as a string
66 getline(1) " get line 1
67 getline(1, 5) " get lines 1-5
68 search('^$') " next blank line, returns line number
69 search('^$','n') " but don't move cursor
71 getcurpos() " [bufnum, lnum, col, off, curswant]
72 getpos('.') " [bufnum, lnum, col, off]
74 nextnonblank(1) " next non-blank line after line1
79 getpos("'a") " position of a mark
82 getpos("'<") " position of selection start
86 cursor(line,col) " moves cursor
87 cursor(line,col,off,curswant)
89 getcurpos() " returns [bufnum,line,col,off,curswant]
93 expand('<cword>') " word under cursor
94 expand('%') " current file
96 " <cword> current word on cursor
99 " :p:h dirname (/Users/rsc/project)
102 " :e extension (.txt)
103 " see :h cmdline-special
107 fnameescape('string')
108 fnamemodify('main.c', ':p:h')
109 fnamemodify(fname, ':e') " current file extension - see expand()
114 globpath(&rtp, "plugin/commentary.vim")
138 type(var) == type("")
139 type(var) == type(function("tr"))
140 type(var) == type([])
141 type(var) == type({})
142 type(var) == type(0.0)
147 strftime('%c',getftime('file.c'))
152 substitute(str, '.', 'x', 'g')
153 strpart("abcdef", 3, 2) " == "de" (substring)
154 strpart("abcdef", 3) " == "def"
155 stridx("abcdef", "e") " == 4
158 matchstr('testing','test') " == 'test' (or '')
159 match('testing','test') " == 0
160 matchend('testing','test') " == 4
161 match('testing','\ctest') " ignore case
163 split(str, '\zs') " split into characters
166 strchars() " accounts for composing chars
167 strwidth() " accounts for ambig characters
168 strdisplaywidth() " accounts for tab stops
176 synstack(line('.'),col('.')) " returns many
177 synID(line('.'),col('.'),1) " only one
184 map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
188 system('ls '.shellescape(expand('%:h')))
193 getregtype('*') " v(char), V(line) <ctrl-v>(block)
198 if name ==# 'John' " case-sensitive
199 if name ==? 'John' " case-insensitive
200 if name == 'John' " depends on :set ignorecase
201 " also: is#, is?, >=#, >=?, and so on
212 exe 'normal ^C' " with expansions