Skip to content

Instantly share code, notes, and snippets.

View Raimondi's full-sized avatar

Israel Chauca Fuentes Raimondi

View GitHub Profile
function! MapMeta(cmd, lhs, rhs)
if has('gui_running')
exec a:cmd.' <M-'.substitute(a:lhs, '[<>]', '', 'g').'> '.a:rhs
else
exec a:cmd.' <Esc>'.a:lhs.' '.a:rhs
endif
endfunction
call MapMeta('map', '<Left>', 't')
" Will write text including first match until before the second match:
" :WriteMatchedText first second /path/to/file.ext
function! WriteMatchedText(first, second, file)
exec "normal /".a:first."\<CR>"
normal v
exec "normal /".a:second."\<CR>h"
normal y
call writefile(split(@", "\n"), expand(a:file))
endfunction
@Raimondi
Raimondi / diff.vim
Created October 16, 2010 09:15
Unified patch file folding.
" From jamessan#[email protected]
" Folding for unified diffs
function! DiffFoldLevel(lineno)
let line = getline(a:lineno)
if line =~ '^Index:'
return '>1'
elseif line =~ '^===' || line =~ '^RCS file: ' || line =~ '^retrieving revision '
let lvl = foldlevel(a:lineno - 1)
return lvl >= 0 ? lvl : '='
@Raimondi
Raimondi / gist:721332
Created November 30, 2010 08:13
incrementor.vim
" http://vim.pastey.net/142521
" Author: bairui
function! Incrementor(start, step)
let incrementor = {}
let incrementor.initial_value = a:start - 1
let incrementor.value = incrementor.initial_value
let incrementor.step = a:step
function incrementor.inc() dict
let self.value += self.step
return self.value
@Raimondi
Raimondi / vo_tags.vim
Created December 12, 2010 18:14
vo_tags.vim
if v:version < 700
echom 'VimOutliner: vo_tags.vim requires Vim 7.0 or later.'
finish
endif
if !exists('g:vo_tagfile')
if glob('$HOME/.vimoutliner') != ''
let g:vo_tagfile = expand('$HOME/.vimoutliner/vo_tags.tag')
else
let g:vo_tagfile = expand("<sfile>:p:h:h").'/vimoutliner/vo_tags.tag'
@Raimondi
Raimondi / sample.txt
Created December 30, 2010 01:45
Problem with searchpair()
if true
x
end
@Raimondi
Raimondi / finished_cmd.zsh
Created February 16, 2011 22:44
Say alert when command takes a while to finish
# If a command takes more than $CUR_CMD_TIMEOUT seconds to finish,
# then let me know when it has finished.
# Code to get command name from http://aperiodic.net/phil/prompt/
CUR_CMD_TIMEOUT=1
precmd () {
CUR_CMD_END=`date +%s`
if [[ -n "$CUR_CMD_START" ]] {
let "CUR_CMD_ELAPSED = $CUR_CMD_END - $CUR_CMD_START"
@Raimondi
Raimondi / better_gf.vim
Created February 22, 2011 01:53
Better gf
" Always edit a file on gf, but be nice and ask
map gf :<C-U>call GoFile()<CR>
function! GoFile()
try
normal! gf
catch /^Vim\%((\a\+)\)\=:E447/
let q = substitute(v:exception,'^Vim\%((\a\+)\)\=:E\d\+: \(.*\)','\1','') . ', would you like to create it?'
try
buffer <cfile>
@Raimondi
Raimondi / getHiGroupInfo.vim
Created April 3, 2011 04:12
Get info of a given highlight group.
" From jamessan@#vim
" http://vim.pastey.net/148644
let i = 1
while synIDtrans(i) != 0
if synIDattr(i, 'name') == 'Normal'
if synIDattr(i, 'fg') >= 0
" fg is set
endif
if synIDattr(i, 'bg') >= 0
Monday, December 15, 2008
If programming languages were religions...
By amz at 14:52
C would be Judaism - it's old and restrictive, but most of the world
is familiar with its laws and respects them. The catch is, you can't
convert into it - you're either into it from the start, or you will
think that it's insanity. Also, when things go wrong, many people are
willing to blame the problems of the world on it.