Skip to content

Instantly share code, notes, and snippets.

@dahu
dahu / gist:8704952
Created January 30, 2014 09:04
Embelish a line with a thing when you move to it
function! Embelish(thing)
let line = line('.')
let l = getline(line)
if l !~ a:thing . '\s*$'
let l = l . a:thing
endif
call setline(line, [l])
endfunction
autocmd CursorMoved * call Embelish(';')
@dahu
dahu / gist:8708115
Created January 30, 2014 13:17
my vim maps as generated by Vimple's MyMaps() function (with some hand-editing)
" Insertlessly
n <BS> <Plug>BSPastBOL
n <Del> <Plug>DelAtEOL
n <CR> <Plug>InsertNewline
n <S-CR> <Plug>OpenNewline
n <Space> <Plug>InsertSpace
" Buffalo
n <Space>l <Plug>BuffaloTrigger
c <C-G> <Plug>BuffaloRecursive
@dahu
dahu / gist:8816555
Created February 5, 2014 02:36
operate on current visual selection
function! GoToDoc()
exec '!echo http://docs.unity3d.com/Documentation/ScriptReference/' . @* . '.html'
endfunction
vnoremap <leader>d :<c-u>call GoToDoc()<cr>
@dahu
dahu / gist:8949297
Last active August 29, 2015 13:56
clearing whitespace highlighting by filetype
highlight ExtraWhitespace ctermbg=red guibg=red
" add to or replace 'text' with filetypes
" you want to prevent whitespace highlighting on
function! ExtraWhitespace(pattern)
if index(['text'], &ft) == -1
exe 'match ExtraWhitespace /' . a:pattern . '/'
endif
endfunction
@dahu
dahu / gist:9679489
Created March 21, 2014 04:25
SimpleTabComplete redux
" SimpleTabComplete redux
" Barry Arthur (bairui), 2014-03-21
" modified from https://gist.github.com/anonymous/9678319
function! SimpleTabComplete(direction, mapping)
" "n"ext or "f"orward vs, say "p"rev or "b"ackward
let dirs = ["\<c-p>", "\<c-n>"]
let dir = a:direction =~? '[nf]'
let map = a:mapping
@dahu
dahu / gist:9717174
Created March 23, 2014 01:28
clean up search history after substitution
function! Ronin()
substitute/\%V"/'&'/g
nohl
call histdel("search", -1)
endfunction
vnoremap <leader>q :<c-u>call Ronin()<cr>
@dahu
dahu / gist:9718037
Last active August 29, 2015 13:57
Combine the power of [I and :ilist /pattern/ in Vim
function! IList()
let term = input("IList: /")
if term == ''
let term = expand('<cword>')
endif
let v:errmsg = ''
redir =>slist
exe 'ilist /' . term
redir END
if v:errmsg == ''
@dahu
dahu / gist:9780316
Created March 26, 2014 10:20
VimPEG Example: reducing a list of comma separated function calls to the " deepest parenthetic argument, or the bare function name if it contains no " arguments.
" Barry Arthur
" 2014-03-26
" VimPEG Example: reducing a list of comma separated function calls to the
" deepest parenthetic argument, or the bare function name if it contains no
" arguments.
"
" Examples
"
" given:
"
@dahu
dahu / gist:9828872
Last active August 29, 2015 13:57
example of manual completion in insert mode
" I extracted the magic out into a new plugin: https://github.com/dahu/Vimpartial
" which provides the b:partial_word used below.
function! AppendTags()
let tags = ['FIXME', 'TODO', 'NOTE']
let tags = filter(tags, 'v:val =~ "^" . b:partial_word')
if !empty(tags)
let tag = matchstr(tags[0], b:partial_word . '\zs.*')
return tag . "-" . strftime("%s")
else
@dahu
dahu / gist:9830380
Created March 28, 2014 11:12
Tell vimple what to initialize in your ~/.vimrc
" init vimple vars
for [var, val] in [
\ ['bl', 1]
\,['hl', 1]
\,['sn', 1]
\,['vn', 1]
\,['ma', 1]
\,['ul', 1]
\,['mp', 1]
\]