Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
AndrewRadev / with.vim
Created April 16, 2012 11:44
"with" command for vimscript
let s:undo_stack = []
command! -nargs=1 With call s:With(<f-args>)
function! s:With(expression)
if a:expression[0] == '*'
return s:WithFunction(a:expression)
else
return s:WithVariable(a:expression)
endif
endfunction
@AndrewRadev
AndrewRadev / paste_coffee.vim
Created March 3, 2012 15:17
Paste and use the current line's indentation as base
" Using the `,p` mapping would paste text below the current line, using the line's indentation.
" The `,P` mapping does the same, except pasting above the current line.
"
" This could be useful for indent-based languages. For example:
"
" foo = (bar) ->
" console.log bar
"
" baz = (qux) ->
" console.log qux
@AndrewRadev
AndrewRadev / windows.vim
Created December 30, 2011 09:52
Execute window commands in Vim with the possibility of repeating them, "."-style
nnoremap _w :Wincmd<cr>
nnoremap _. :WincmdRepeat<cr>
command! Wincmd call s:Wincmd('')
function! s:Wincmd(cmd_count)
let cmd_count = a:cmd_count
" echo the command so far for some visual feedback
redraw | echo cmd_count.'wincmd'
@scrooloose
scrooloose / custom_maps.vim
Created December 28, 2011 10:33
Couple of custom key maps for nerdtree
if exists("g:loaded_nerdtree_custom_maps")
finish
endif
let g:loaded_nerdtree_custom_maps = 1
"adds a keymapping on 'o' that overrides the standard nerdtree 'o' mapping and
"to open the file node and close the tree
call NERDTreeAddKeyMap({
\ 'key': 'o',
@AndrewRadev
AndrewRadev / inline_edit.vim
Created December 26, 2011 10:14
Edit various embedded scripts in vimscript with the inline_edit.vim plugin
function! inline_edit#VimEmbeddedScript()
let start_pattern = '^\s*\(\%(rub\|py\|pe\|mz\|lua\)\S*\)\s*<<\s*\(.*\)$'
" If we don't find the start by going backwards, bail out.
if search(start_pattern, 'Wb') <= 0
return []
endif
" The start of the code will be the line after the one we just found
let start = line('.') + 1
@AndrewRadev
AndrewRadev / tabj.vim
Created December 13, 2011 14:22
Simple jumping through buffers
command! -nargs=1 -complete=custom,s:TabjCompletion Tabj call s:Tabj(<f-args>)
function! s:Tabj(name)
for i in range(tabpagenr('$'))
let tabnr = i + 1
for bufnr in tabpagebuflist(tabnr)
if stridx(bufname(bufnr), a:name) >= 0
exe 'tabnext '.tabnr
while bufnr('%') != bufnr
@AndrewRadev
AndrewRadev / qf.vim
Created December 2, 2011 20:14
Delete lines from the quickfix window (with undo)
" Place in ftplugin/qf.vim
xnoremap <buffer> d :DeleteLines<cr>
nnoremap <buffer> dd :DeleteLines<cr>
nnoremap <buffer> u :UndoDelete<cr>
if !exists(':DeleteLines')
let b:deletion_stack = []
" Delete by a pattern (with undo placing them all on top):