Skip to content

Instantly share code, notes, and snippets.

@PeterRincker
PeterRincker / prismo.vim
Last active September 10, 2017 07:37
vim-prismo with a twist
"Prismo.vim
" version of vim-prismo I took a crack at reimplimenting
" https://github.com/guywald1/vim-prismo
"
" Options:
" 'commentstring' - See :h 'commentstring'. Can use b:commentstring to override
" g:prismo_dash - padding character defaults to dash
" g:prismo_toupper - transform the title to uppercase (default to 1)
" b:prismo_width - width of header default to 'textwidth' or 80 if 'textwidth' is 0
"
@PeterRincker
PeterRincker / SortGroup.vim
Last active December 26, 2024 12:17
Sort groups of lines in vim
" :[range]SortGroup[!] [n|f|o|b|x] /{pattern}/
" e.g. :SortGroup /^header/
" e.g. :SortGroup n /^header/
" See :h :sort for details
function! s:sort_by_header(bang, pat) range
let pat = a:pat
let opts = ""
if pat =~ '^\s*[nfxbo]\s'
let opts = matchstr(pat, '^\s*\zs[nfxbo]')
@PeterRincker
PeterRincker / cfilter.vim
Last active February 28, 2019 19:31
Filter the quickfix list
" :Cfilter[!] /{pat}/
" :Cfilter[!] {pat}
" Filter the quickfix looking for pattern, `{pat}`. The pattern can match the filename or text.
" Providing `!` will invert the match (just like `grep -v`).
" Note: :cfilter command abbreviation is provided for convenience
"
" :Lfilter[!] /{pat}/
" :Lfilter[!] {pat}
" Same as :Cfilter but use the location list.
" Note: :lfilter command abbreviation is provided for convenience
@PeterRincker
PeterRincker / directory-expand.vim
Created November 17, 2017 17:36
Quickly expand current working directory into cmdline
" Use // in certain commands like :edit, :split, :read, etc. to insert the current buffer's directory
" :e// -> :e foo/bar/
"
" Compatible commands:
" :edit/:split/:vsplit
" :find/:sfind
" :buffer/:sbuffer
" :read
" :diffpslit/:diffpatch
" :vimgrep/:grep
@PeterRincker
PeterRincker / Y.vim
Last active December 24, 2020 15:27
Exposing your clipboard over SSH
" Add line to remote vimrc file
" :[range]Y - send [range] lines to remote-pbcopy via netcat.
command! -range Y silent <line1>,<line2>w !nc localhost 5556
@PeterRincker
PeterRincker / Railsabbrev.vim
Created January 2, 2018 23:55
Mimic Rails.vim's :Railsabbrev
" Mimic part of Rails.vim's :Railsabbrev
" aka Abbreviations that will only expand on <tab> or <c-]>
"
" Example usage:
" :Railsabbrev iff if:<left>
" :Railsabbrev fun function!\ ()<cr>endfunction<up><end><left><left>
" Now you can type "iff<tab>" and it will expand to: "if:" with the cursor before the ":"
"
" Supports completion menu of :Railsabbrev via <Plug>(Railsabbrev-complete) mapping
@PeterRincker
PeterRincker / abbrev_complete.vim
Created January 3, 2018 00:20
Complete abbreviations
" Completion for iabbrev's
" example:
" imap <c-x><c-x><c-a> <Plug>(complete-appbrev)
function! s:complete_abbrev()
let lst = split(execute('iabbrev'), '\n')
let lst = map(lst, 'split(v:val, ''\s\+'')[1:]')
let lst = map(lst, '{"word": v:val[0], "menu": substitute(join(v:val[1:], " "), ''^[@*]\s'', "", "")}')
let col = col('.')
let prefix = matchstr(getline('.')[0:col-2], '\k\+$')
@PeterRincker
PeterRincker / voggle.vim
Created April 12, 2018 20:31
Voggle - toggling pairs
" Interpratation of Voggle:
" https://github.com/JasperSmienk/Voggle
"
" Example mapping:
" nmap <cr> <Plug>(voggle)
"
" Customize by creating g:voggle_pairs or b:voggle_pairs Dictionaries
let s:voggle_pairs = {
\ 'true': 'false',
" Cancel searching with `/`, but stay in place
cnoremap <expr> <c-y> <SID>search_cr("\<c-y>", getcmdtype(), getcmdline())
function! s:search_cr(cmd, type, line)
let [key, s:pos, s:search] = [a:cmd, getpos('.'), a:line]
if a:type == '/' || a:type == '?'
let key = "\<c-c>"
augroup search_cr
autocmd!
autocmd CmdlineLeave * execute "autocmd! search_cr" |
@PeterRincker
PeterRincker / diff.md
Last active September 5, 2024 04:12 — forked from romainl/diff.md
:DiffOrig but smarter

:DiffOrig but smarter

This is an enhanced version of the snippet provided under :help diff-original-file.

Where the original :DiffOrig only shows differences between the buffer in memory and the file on disk, :Diff can be used in two ways:

  • against the file on disk, like the original, with:

    :Diff