diff options
author | Dmitry Chestnykh <dchest@gmail.com> | 2011-04-13 11:55:41 +1000 |
---|---|---|
committer | David Symonds <dsymonds@golang.org> | 2011-04-13 11:55:41 +1000 |
commit | 89901bbd14298f4e21c1b8bf8df166c47480183d (patch) | |
tree | 036f8e09d886c90506067804545c5b14245009dc | |
parent | 1de71a07e08c86e6fdf1be4ca11ae57c7c757635 (diff) | |
download | go-89901bbd14298f4e21c1b8bf8df166c47480183d.tar.gz go-89901bbd14298f4e21c1b8bf8df166c47480183d.zip |
misc/vim: add plugin with Fmt command.
Fmt command filters the current Go buffer through gofmt.
It tries to preserve cursor position and avoids replacing
the buffer with stderr output.
R=golang-dev, dsymonds, niemeyer
CC=golang-dev
https://golang.org/cl/4382053
-rw-r--r-- | misc/vim/ftplugin/go/fmt.vim | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/misc/vim/ftplugin/go/fmt.vim b/misc/vim/ftplugin/go/fmt.vim new file mode 100644 index 0000000000..18a2156f5f --- /dev/null +++ b/misc/vim/ftplugin/go/fmt.vim @@ -0,0 +1,30 @@ +" Copyright 2011 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. +" +" fmt.vim: Vim command to format Go files with gofmt. +" +" This filetype plugin add a new commands for go buffers: +" +" :Fmt +" +" Filter the current Go buffer through gofmt. +" It tries to preserve cursor position and avoids +" replacing the buffer with stderr output. +" + +command! Fmt call s:GoFormat() + +function! s:GoFormat() + let view = winsaveview() + %!gofmt + if v:shell_error + %| " output errors returned by gofmt + " TODO(dchest): perhaps, errors should go to quickfix + undo + echohl Error | echomsg "Gofmt returned error" | echohl None + endif + call winrestview(view) +endfunction + +" vim:ts=4:sw=4:et |