Skip to content

Instantly share code, notes, and snippets.

View Raimondi's full-sized avatar

Israel Chauca Fuentes Raimondi

View GitHub Profile
@Raimondi
Raimondi / augroup_boom.vim
Created May 9, 2011 06:06
Self destructing autogroup
augroup Test
au!
au CursorHold * call append(0, 'apetito')
au VimEnter * augroup Test|exec 'au!'|augroup END|augroup! Test
augroup END
function! TPArchive2()
s/^/\t/
.write >> ~/SimpleText/september_log2.taskpaper
d
endfunction
function! TPArchive()
g/.*@[Dd]one([0-9\-]\+)$/call TPArchive2()
endfunction
@Raimondi
Raimondi / syntax_snippets.vim
Created October 26, 2011 22:27
Some useful snippets for Vim syntax.
" Name of syntax item under the cursor
nore <leader>n :echo synIDattr(synID(line("."), col("."), 1), "name")<CR>
" Syntax stack of item under the cursor
nnore <leader>s :<C-U>echo join(map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")'), ' => ')<CR>
" Color of syntax item under the cursor
echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
@Raimondi
Raimondi / snippets.vim
Last active September 28, 2015 10:38
Vim snippets
" Count matches in a string.
function! s:count(str, pat)
let cnt = 1
let index = matchend(a:str, a:pat)
while index >= 0
let cnt += 1
let index = matchend(a:str, a:pat, index)
endwhile
return cnt - 1
endfunction
@Raimondi
Raimondi / qfwin.vim
Created February 26, 2012 21:53
Is a quickfix window open in any tabpage?
function! QFWinInTab(tabnr) "{{{
return len(filter(range(1, winnr('$')), 'gettabwinvar('.a:tabnr.', v:val, "&buftype") == "quickfix"'))
endfunction "QFWinInTab }}}
function! HasQF() "{{{
return len(filter(range(1, tabpagenr('$')), 'QFWinInTab(v:val)'))
endfunction "HasQF }}}
@Raimondi
Raimondi / swap-pivot.vim
Created February 27, 2012 03:48
Swap a selection with what follows it using a pivot.
" Switch both sides around a 'pivot'.
" e.g.: let's say we have this string
" abc && def
" put the cursor on 'a' then vf&<leader>ssff
" That will yield:
" def && abc
function! Swap(...) "{{{
let start_v = col("'<")
let end_v = col("'>")
@Raimondi
Raimondi / remove_ws.vim
Created April 5, 2012 06:34 — forked from sgharms/gist:2308471
remove_ws.vim
function! s:ScourgeWhitespace(flag)
if a:flag
echo "Killing whitespace with fire..."
%s/ \+$//
else
echo "Gently helping you to remove whitespace..."
%s/ \+$//c
endif
endfunction
@Raimondi
Raimondi / ftplugin_help.vim
Created April 16, 2012 00:38 — forked from Osse/ftplugin_help.vim
Mappings to make :help perusal easier for lazy people
if &readonly
nnoremap <silent><buffer> <Esc> :quit<CR>
nnoremap <silent><buffer> <CR> <C-]>
nnoremap <silent><buffer> <BS> <C-O>
nnoremap <silent><buffer> <Down> :call search('\(''\<bar><bar>\)[^, <bar>]\{-1,}\1', 'W')<CR>
nnoremap <silent><buffer> <Up> :call search('\(''\<bar><bar>\)[^, <bar>]\{-1,}\1', 'Wb')<CR>
endif
@Raimondi
Raimondi / literal_search.vim
Created April 24, 2012 22:18
Search for a string literaly, as in 'without regex'. Type g/ to start.
" Our private history.
let s:history = exists('s:history') ? s:history : []
function! LiteralSearch()
" First, empty the input history.
call histdel('input')
" next, add our own history.
call map(copy(s:history), 'histadd("input", v:val)')
" Get user's input.
let input = input('g/')
if empty(input)
@Raimondi
Raimondi / transpose_words.vim
Created April 26, 2012 18:19
Transpose words, a la alt-t on emacs.
function! TransposeWords(...) range
" if no arg was provided use the count.
let cnt = a:0 ? a:1 : v:count1
let cur = getpos('.')
let pos = searchpos('\%#.', 'wcn')
if matchstr(getline(line('.'))[(col('.') - 1) :], '^.') =~ '\w'
\ && col('.') != col('$')
let pat = '\(\w*\%#\w\+\)\(\_W\+'
\ . repeat('\w\+\_W\+', cnt - 1)
\ . '\)\(\w\+\)'