Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / SortGroup.vim
Last active March 17, 2024 04:51
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 / 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 / quick-php-man.vim
Created January 28, 2017 01:09
Show php signature
" put in ~/.vim/ftplugin/php_man.vim
" Will map K to show signature on commandline.
" Will also attempt to show signature while typing.
"
" Set g:php_quick_man_color = 0 to disable color
" Set g:php_quick_man_insert_mode = 0 to disable insert mode signature
if exists('b:ftplugin_php_man')
finish
endif
@PeterRincker
PeterRincker / markdown-backtick.vim
Last active January 27, 2017 23:37
Backtick support for matchit in markdown files
" Put inside ~/after/plugin/matchit.vim
if exists('g:loaded_after_matchit') || !has('syntax') || &cp || v:version < 700
finish
endif
let g:loaded_after_matchit = 1
function! s:synnames(...) abort
if a:0
let [line, col] = [a:1, a:2]
else
@PeterRincker
PeterRincker / FancySmancyComment.vim
Created August 17, 2015 11:05
Center text inside of a comment
" FancySmancyComment(text, fill_char, width)
" Create comment string with centered text
" All arguments are optional
function! FancySmancyComment(...)
let text = get(a:000, 0, '')
let fill = get(a:000, 1, '-')[0]
let width = get(a:000, 2, 80) - len(printf(&commentstring, '')) - len(text)
let left = width / 2
let right = width - left
put=printf(&commentstring, repeat(fill, left) . text . repeat(fill, right))
@PeterRincker
PeterRincker / comment.vim
Last active March 17, 2021 22:02
SimpleComment
" Inspired by Tim Pope's commentary.vim
"
" Uses b:commentstring or 'commentstring' as the comment pattern
" example:
" let &commentstring = '/*%s*/'
nnoremap gcc :<c-u>.,.+<c-r>=v:count<cr>call <SID>toggleComment()<cr>
nnoremap gc :<c-u>set opfunc=<SID>commentOp<cr>g@
xnoremap gc :call <SID>toggleComment()<cr>
@PeterRincker
PeterRincker / python.py
Created February 21, 2015 01:28
compiler/python.vim
#!/usr/bin/env python
# put this file at ~/.vim/compiler.py
from __future__ import print_function
from sys import argv, exit
if len(argv) != 2:
exit(1)