Created
May 9, 2015 00:32
-
-
Save dcu/9a5c8eb3d2adeab79437 to your computer and use it in GitHub Desktop.
gofmt-like vim plugin for go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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