Skip to content

Instantly share code, notes, and snippets.

@dahu
dahu / gist:3357301
Created August 15, 2012 07:09
Ye Olde VimPEG
" Introducing Vimpeg - A PEG Parser Generator for Vim
" Barry Arthur, 01 Oct 2011
" Evaluate a series of inline integer addition & subtraction operations
let p = vimpeg#parser({'skip_white': 1})
call p.e('\d\+', {'id': 'integer'})
let addsub =
\ p.and(
\ [ 'integer',
\ p.maybe_many(
@dahu
dahu / gist:3382218
Created August 17, 2012 20:14
Toggle display of current div in statusline
let s:orig_statusline = &statusline
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
@dahu
dahu / gist:3435668
Last active October 9, 2015 04:07
EditFileWORD
" Edit file under cursor (not matching :help 'isfname) (:help gf)
" (:help cWORD)
function! EditFileWORD()
let file = expand('<cWORD>')
if findfile(file, &path) != ''
let file .= "\<cr>"
endif
return ":edit " . file
endfunction
@dahu
dahu / gist:3488848
Created August 27, 2012 14:19
color_plane - hsl(ish) map of Xresources colours
#!/usr/bin/env ruby
# color_plane - hsl(ish) map of Xresources colours
# Barry Arthur
require 'color'
@opt_print_values = nil
def swatch(color)
print "\x1b[48;5;#{color}m "
print @opt_print_values ? sprintf("%3s", color) : " "
@dahu
dahu / gist:3726230
Created September 15, 2012 03:20
Automatically highlight word under cursor if it appears more than once in the file.
" Clean-up of Swicher's Highlighter()
" Barry Arthur 2012-09-15
function! Highlighter()
let word_cursor = escape(expand('<cword>'), ".*[]\\")
redir => output
silent! execute '%s/\<'.word_cursor.'\>//gen'
redir END
if output != ""
if str2nr(split(output)[0]) > 1
@dahu
dahu / gist:3837333
Created October 5, 2012 00:28
gfy - a commandline tag search tool
#!/bin/sh
# gfy: command-line tag search tool.
# Barry Arthur 20121005
# expects tags file in current directory
[ -z "$1" ] && echo "usage: gfy tag" && exit 1
grep -i "$1" tags | awk -F "\t" '{printf("vim %s -c\"%s\n", $2, $3);}' | sed -e 's/;"$/"/'
@dahu
dahu / gist:3862265
Last active October 11, 2015 12:57
quiet make
" Quiet Make
"~~~~~~~~~~~~
function! QuietMake()
write
lcd %:p:h
silent! make
lcd -
copen
if empty(len(filter(getqflist(), 'v:val["valid"]')))
@dahu
dahu / gist:3863148
Created October 10, 2012 04:23
Die, Tabs, Die!
" dietabsdie.vim - Reopen new tabs as buffers
" Barry Arthur, 4 June 2010
function! DieTabsDie()
let tabbufname=expand('%')
tabclose
exe ":b " . expand(tabbufname)
endfunction
autocmd TabEnter * call DieTabsDie()
@dahu
dahu / gist:3883214
Created October 13, 2012 04:26
bisectly arch overview
Bisectly Architecture Overview
------------------------------
Components
~~~~~~~~~~
* bin/bisectly
* lib/bisectly/bsfl.rb
* lib/bisectly/clients/vim.rb
* lib/bisectly/thumpers/file_thumper.rb
@dahu
dahu / gist:3922742
Created October 20, 2012 09:14
Edit File WORD
" Edit file under cursor (not matching :help 'isfname) (:help gf)
" Deliberately left off terminating <cr> if filename can't be found
" to allow user to modify before execution.
" (:help cWORD)
function! EditFileWORD()
let file = expand('<cWORD>')
if findfile(file, &path) != ''
let file .= "\<cr>"
endif
return ":edit " . file