Skip to content

Instantly share code, notes, and snippets.

@dahu
dahu / gist:6ff4de11ca9c5bb25902
Created July 6, 2015 05:21
Use colorcolumn as a poor-man's indent indicator in vim
" toggle colorcolumn
" at cursor (mnemonic: indicate cursor)
nnoremap <leader>ic :exe 'set cc'.(&cc =~ virtcol('.')?'-=':'+=').virtcol('.')<cr>
" at start of line (mnemonic: indicate indent)
nnoremap <leader>ii :exe "normal m`^\<leader>ic``"<cr>
@dahu
dahu / gist:39282c57bba5b2d1e7b1
Last active February 25, 2017 19:33
Choose Your Own Vim Adventure -- Goal Driven Learning for Vim

Goal Driven Learning for Vim

Principles

@dahu
dahu / gist:2019325d14871dbc3a23
Last active August 29, 2015 14:24
Echo Bash Alias beneath cursor
" Echo Bash Alias beneath cursor
" Barry Arthur, July 2015
let aliases = {}
for a in split(system('/bin/bash -ic alias'), '\n')
let [k,v] = matchlist(a, 'alias \(\S\+\)=\(.*\)')[1:2]
call extend(aliases, {k : v})
endfor
function! EchoAlias()
" poor man's make
" Barry Arthur, July 2015
function! MK()
cclose
write
let res = system('gcc -std=c++11 ' . shellescape(expand("%")))
if ! v:shell_error
exe "! ./a.out"
else
@dahu
dahu / gist:5f87d130ca8986ea95d6
Created June 22, 2015 03:57
The naive beginnings of a toy hex editor in Vim
" Barry Arthur, June 2015
" The start of a Hex editor in Vim
function! HexInit()
let lines = getline(1, '$')
let s:idx = []
let s:hex = []
let s:asc = []
for l in lines
call add(s:idx, strpart(l, 0, 8))
@dahu
dahu / gist:0009113ebac81bba6c10
Created June 13, 2015 00:43
auto manage begin/end blocks in log file
" Barry Arthur, June 2015
" Auto manage Begin/End blocks in log file
" Manual function to create new block
function! SpasmLogAuto()
if ! exists('b:spasm')
let b:spasm = 1
$
let now = strftime('%c')
let last_entry = search('^\(Begin\)\|^\(End\)', 'bcpW')
@dahu
dahu / gist:498cc6b39ce5d543de92
Created June 12, 2015 09:29
Filter blank lines from implicit numbered registers
" Barry Arthur, June 2015
" Don't store empty lines in implicit numbered registers.
let s:reg_9 = ''
function! FilterBlankReg1()
let regs = map(range(9), "getreg(v:val+1)")
if regs[0] == "\n"
for reg in range(8)
call setreg(reg+1, getreg(reg+2))
endfor
@dahu
dahu / gist:c590c073fb540619c9a4
Created May 27, 2015 14:38
Plot Vim's Startup Time data
" Barry Arthur May 2015
" Plot Vim's startup time data
"
" Install in ~/.vim/plugin/
"
" Usage:
" vim --startuptime foo +q
" vim -c "Startuptime foo" +q
function! Startuptime(file)
@dahu
dahu / gist:2b13271f26d091e5a1b3
Last active August 29, 2015 14:21
Wrap visual selection
" Barry Arthur May 2015
function! VisualWrap(front, back)
exe "'<s/\\%V/" . a:front
exe "'>s/\\%V.*\\%V.\\zs/" . a:back
exe "'>s/\\ze\\n/" . a:back
endfunction
vnoremap <leader>x :<c-u>call VisualWrap('front', 'back')<cr>
@dahu
dahu / gist:5701cff9beed95f66eff
Created May 18, 2015 12:19
I keep meaning to learn viml
yeah
I keep meaning to learn viml
but it's awful
I don't really grok python (ruby is my thing) but it might be
more useful for me
but the vast majority of plugins are viml, so it doesn't really
help you to fix bugs in them or extend them
I was hoping timl would get developed some more, but seems not to be
yeah