Skip to content

Instantly share code, notes, and snippets.

@dahu
dahu / gist:3923049
Created October 20, 2012 11:30
A hideous, contrived switch
let y = 0
let c = 0
for x in ['== 1', '>1', '<1']
if eval(y . x)
echo c
break
endif
let c += 1
endfor
@dahu
dahu / gist:3964354
Created October 27, 2012 11:31
WaitForKeyMap
function! WaitForKeyMap(start)
let c = nr2char(getchar())
if maparg(a:start . c, 'i') != ''
echo "soup!"
call feedkeys(a:start . c)
return ''
else
return c
endif
endfunction
@dahu
dahu / gist:3986511
Last active March 31, 2026 18:26
Vim Motions
Large Object Motions:
(
)
{
}
[[
[]
][
]]
[m
@dahu
dahu / gist:4035975
Created November 8, 2012 01:50
godlygeek's syntax region text object
" author: godlygeek
function s:movement_string(line, col)
return a:line . "G0" . (a:col > 1 ? (a:col - 1) . "l" : "")
endfunction
function! s:VAR()
let group = synID(line('.'), col('.'), 1)
let orig = [ line('.'), col('.') ]
@dahu
dahu / gist:4054442
Created November 11, 2012 10:28
RotateBuffer
function! RotateBuffer()
let rb=[]
for x in range(max(map(getline(1, '$'), 'len(v:val)')))
call add(rb, [])
for y in range(line('$'))
call add(rb[x], ' ')
endfor
endfor
let y = 0
for line in getline(1,'$')
@dahu
dahu / gist:4058093
Created November 12, 2012 08:11
noisy weechat plugin
# Copyright (c) 2010 by Barry Arthur <barry.arthur@gmail.com>:
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@dahu
dahu / gist:4137807
Created November 24, 2012 00:18
ftplugin/help.vim
" help.vim - ftplugin for better Help navigation and operation
" Barry Arthur
" jump to links with CR
nmap <buffer> <CR> <C-]>
" jump back with BS
nmap <buffer> <BS> <C-T>
" skip to next option link
nmap <buffer> o /'[a-z]\{2,\}'<CR>
" skip to previous option link
vnoremap <leader>d :call Test()<CR>gv"yp
function! Test()
"yank current visual selection to reg x
normal! gv"xy
"put new string value in reg y
let @y = " IF (DEBUG.GT.0) THEN\n" . @x . "\n ENDIF"
endfunction
@dahu
dahu / gist:4174715
Created November 30, 2012 09:21
Possible List of Showcase Vids for Vim
Possible List of Showcase Vids for Vim
--------------------------------------
. text objects
. search & replace (:s/// & :g//) (waz tutorial chapters 1-4 and vimranger poster)
. macros (impromptu, dynamic short-term solutions)
. registers (vimregrap poster)
. buffers, windows, tabs & sessions (including --clientserver)
. marks & jumps
. :find & &path, :args & :e & :ls & :b (perhaps showcase some buffer switchers either here or in a dedicated vid)
@dahu
dahu / gist:4250520
Created December 10, 2012 13:21
Godlygeek's Comment Text Object
" author: godlygeek
" 22 Jun 2010
"
" the objects returned are visual mode commands
" in visual mode, o jumps to the other end of the match
"
function! s:VAC()
if search('\m\%#/\*', 'bcnW') || search('\m/\%#\*', 'bcnW')
" On /*
return ']*o]*[*o'