Skip to content

Instantly share code, notes, and snippets.

@dahu
dahu / gist:3047302
Created July 4, 2012 13:26
toggle or inc/dec
function! ToggleBoolean()
return "ciw\<c-r>=@\" =~# 'true' ? 'false' : 'true'\<cr>\<esc>"
endfunction
nnoremap <expr> <c-x> match(expand('<cword>'), '[-+]\?\d\+') == -1 ? ToggleBoolean() : ":normal! \<c-x>\<cr>"
finish
3
@dahu
dahu / gist:3175660
Created July 25, 2012 11:36
neongenesis
let s:neongenesis = [
\ ['q', ['d', '+']],
\ ['d', ['s', '+']],
\ ['s', ['d', '-']],
\ ['d', ['q', '-']]
\]
function! NeonIn(neon, n)
let s = a:neon[1][0]
let s .= a:n*2
@dahu
dahu / gist:3217078
Created July 31, 2012 13:35
Simple VimL AST walker with visitor
" VimL Example of Walking an AST
" Barry Arthur, 2012 07 31
" simple AST walker with a visitor, applied to each node in the tree
func! Walk(ast, visitor)
return type(a:ast) == type([]) ? call(a:visitor[a:ast[0]], [a:ast[1]], a:visitor) : a:ast
endfunc
" one way to define a VimLPOO object
let eval_visitor = {}
@dahu
dahu / gist:3221647
Created July 31, 2012 23:17
Simple AST walker with multi-child AST
" VimL Example of Walking a multi-child AST
" Barry Arthur, 2012 08 01
" The same simple AST walker
func! Walk(ast, visitor)
return type(a:ast) == type([]) ? call(a:visitor[a:ast[0]], [a:ast[1]], a:visitor) : a:ast
endfunc
" rainbows and unicorns
function! RnU()
@dahu
dahu / gist:3227306
Created August 1, 2012 14:24
show HTML Current div in statusbar
function! HTMLCurrentDivId()
let m = searchpos('<\s*div.\{-}id\s*=\s*"\([^"]*\)"', 'bnWp')
if m[2] == 2
return matchlist(getline(m[0]), 'id\s*=\s*"\([^"]*\)"')[1]
else
return ''
endif
endfunction
set statusline=%f%m%r%h%w\ [%n:%{&ff}/%Y]%=[0x\%04.4B][%03v][%p%%\ line\ %l\ of\ %L,\ \%{HTMLCurrentDivId()}]
@dahu
dahu / gist:3227307
Created August 1, 2012 14:24
show HTML Current div in statusbar
function! HTMLCurrentDivId()
let m = searchpos('<\s*div.\{-}id\s*=\s*"\([^"]*\)"', 'bnWp')
if m[2] == 2
return matchlist(getline(m[0]), 'id\s*=\s*"\([^"]*\)"')[1]
else
return ''
endif
endfunction
set statusline=%f%m%r%h%w\ [%n:%{&ff}/%Y]%=[0x\%04.4B][%03v][%p%%\ line\ %l\ of\ %L,\ \%{HTMLCurrentDivId()}]
@dahu
dahu / gist:3232034
Created August 2, 2012 00:49
Chroma -- print *markup* in Error highlight in Vim
function! Chroma(msg)
let msg = substitute(a:msg, '\*\([^\*]\+\)\*', '"|echohl Error|echon "\1"|echohl None|echon "', 'g')
exe 'echon "' . msg . '"'
endfunction
@dahu
dahu / gist:3232488
Created August 2, 2012 02:11
Chroma mkII - proof of concept for a full-blown plugin
" proof of concept - Chroma: Vim colour printer using *markup*
" Barry Arthur, 2012 08 02
let s:ChromaTags = ['!' , '\\*' , '+' , '/' , '_']
let s:ChromaTagNames = ['Bang' , 'Star' , 'Plus' , 'Slash' , 'UScore']
let s:ChromaHighlights = ['Error' , 'WarningMsg' , 'Type' , 'Keyword' , 'Label']
let s:ChromaTagPattern = '%\([^%]\+\)%'
let s:ChromaEchoPattern = '"|echohl % |echon "\1"|echohl None|echon "'
let s:Chroma = {}
@dahu
dahu / gist:3322468
Created August 11, 2012 08:19
Simple Flatten() for lists in VimL
function! Flatten(list)
let val = []
for elem in a:list
if type(elem) == type([])
call extend(val, Flatten(elem))
else
call extend(val, [elem])
endif
unlet elem
endfor
@dahu
dahu / gist:3344530
Created August 13, 2012 22:29
Maximize Current Window Without Resizing Quickfix Window
" MaximizeWithoutResizingQuickfix
" Barry Arthur, 2012 08 14
" A solution not using vimple
function! MaximizeWithoutResizingQuickfix()
let qfwnr = get(get(filter(map(range(1,winnr('$')), '[v:val, getwinvar(v:val, "&buftype")]'), 'v:val[1] =~ "quickfix"'), 0, []), 0, -1)
let qfh = winheight(qfwnr)
wincmd _
if qfwnr != -1
exe qfwnr . "wincmd w"