Skip to content

Instantly share code, notes, and snippets.

@PeterRincker
Last active August 29, 2015 13:57
Show Gist options
  • Save PeterRincker/9773667 to your computer and use it in GitHub Desktop.
Save PeterRincker/9773667 to your computer and use it in GitHub Desktop.
" Set b:formatprg to emulate a setlocal for formatprg
if exists('g:loaded_gq') || &cp || v:version < 700
finish
endif
let g:loaded_gq = 1
function! s:gq(type, ...)
let formatprg = &formatprg
let &formatprg = get(b:, 'formatprg', &formatprg)
try
if a:0
execute "normal! '<V'>gq"
else
execute "normal! '[gq']"
endif
finally
let &formatprg = formatprg
endtry
endfunction
nnoremap <silent> <Plug>(gq) :<c-u>set opfunc=<SID>gq<cr>g@
nnoremap <silent> <Plug>(gq-line) :<c-u>set opfunc=<SID>gq<bar>exe 'norm! '.v:count.'g@_'<cr>
xnoremap <silent> <Plug>(gq) :<c-u>call <SID>gq(visualmode(), 1)<cr>
nmap gq <Plug>(gq)
nmap gqq <Plug>(gq-line)
nmap gqgq <Plug>(gq-line)
xmap gq <Plug>(gq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment