for key in keys(mydict) echo key . ': ' . mydict(key) endfor
Lists
1 2 3 4 5 6 7 8
let mylist = [1, two, 3, "four"]
letfirst = mylist[0] letlast = mylist[-1]
" Suppresses errors let second = get(mylist, 1) let second = get(mylist, 1, "NONE")
Functions
Buffer
line('.') " current line number
col('.')
col('$')
getline('.') " current line as a string
getline(1) " get line 1
getline(1, 5) " get lines 1-5
search('^$') " next blank line, returns line number
search('^$','n') " but don't move cursor
getcurpos() " [bufnum, lnum, col, off, curswant]
getpos('.') " [bufnum, lnum, col, off]
nextnonblank(1) " next non-blank line after line1
prevnonblank()
Marks
getpos("'a") " position of a mark
setpos("'a",...)
getpos("'<") " position of selection start
expand('<cword>') " word under cursor
expand('%') " current file
" <cword> current word on cursor
" :p full path
" :h head
" :p:h dirname (/Users/rsc/project)
" :t tail (file.txt)
" :r root (file)
" :e extension (.txt)
" see :h cmdline-special
Files
fnameescape('string')
fnamemodify('main.c', ':p:h')
fnamemodify(fname, ':e') " current file extension - see expand()
filereadable(fname)
getfsize('file.txt')
getcwd()
globpath(&rtp, "plugin/commentary.vim")
if name ==# 'John' " case-sensitive
if name ==? 'John' " case-insensitive
if name == 'John' " depends on :set ignorecase
" also: is#, is?, >=#, >=?, and so on
if "hello" =~ '.*'
if "hello" !~ '.*'
Executing
Running commands
normal 'ddahello'
exe 'normal ^C' " with expansions
wincmd J