Skip to content

Instantly share code, notes, and snippets.

@dcu
Created May 9, 2015 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcu/9a5c8eb3d2adeab79437 to your computer and use it in GitHub Desktop.
Save dcu/9a5c8eb3d2adeab79437 to your computer and use it in GitHub Desktop.
gofmt-like vim plugin for go
if exists("b:did_ftplugin_ruby_fmt")
finish
endif
if !exists("g:ruby_fmt_commands")
let g:ruby_fmt_commands = 1
endif
if !exists("g:rubyfmt_command")
let g:rubyfmt_command = "rubocop -o /dev/null -a "
endif
if g:ruby_fmt_commands
command! Fmt call s:RubyFormat()
endif
function! s:RubyFormat()
let view = winsaveview()
try | silent undojoin | catch | endtry
let default_srr = &srr
set srr=>%s
silent execute "!" . "cp % /tmp/%.tmp"
silent execute "%!" . g:rubyfmt_command . " /tmp/%.tmp; cat /tmp/%.tmp"
silent execute "!rm /tmp/%.tmp"
let &srr = default_srr
call winrestview(view)
endfunction
nmap ff :Fmt<CR>
autocmd BufWritePre <buffer> Fmt
let b:did_ftplugin_ruby_fmt = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment