summaryrefslogtreecommitdiff
path: root/misc/vim
diff options
context:
space:
mode:
Diffstat (limited to 'misc/vim')
-rw-r--r--misc/vim/ftplugin/go/fmt.vim30
-rw-r--r--misc/vim/indent/go.vim30
-rw-r--r--misc/vim/readme.txt13
-rw-r--r--misc/vim/syntax/go.vim4
4 files changed, 75 insertions, 2 deletions
diff --git a/misc/vim/ftplugin/go/fmt.vim b/misc/vim/ftplugin/go/fmt.vim
new file mode 100644
index 000000000..18a2156f5
--- /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
diff --git a/misc/vim/indent/go.vim b/misc/vim/indent/go.vim
new file mode 100644
index 000000000..2e9f191f5
--- /dev/null
+++ b/misc/vim/indent/go.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.
+"
+" indent/go.vim: Vim indent file for Go.
+"
+
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+" C indentation is mostly correct
+setlocal cindent
+
+" Options set:
+" +0 -- Don't indent continuation lines (because Go doesn't use semicolons
+" much)
+" L0 -- Don't move jump labels (NOTE: this isn't correct when working with
+" gofmt, but it does keep struct literals properly indented.)
+" :0 -- Align case labels with switch statement
+" l1 -- Always align case body relative to case labels
+" J1 -- Indent JSON-style objects (properly indents struct-literals)
+" (0, Ws -- Indent lines inside of unclosed parentheses by one shiftwidth
+" m1 -- Align closing parenthesis line with first non-blank of matching
+" parenthesis line
+"
+" Known issue: Trying to do a multi-line struct literal in a short variable
+" declaration will not indent properly.
+setlocal cinoptions+=+0,L0,:0,l1,J1,(0,Ws,m1
diff --git a/misc/vim/readme.txt b/misc/vim/readme.txt
index f836f58f3..3c3255113 100644
--- a/misc/vim/readme.txt
+++ b/misc/vim/readme.txt
@@ -35,3 +35,16 @@ To install one of the available filetype plugins for Go:
3. Add the following line to your .vimrc file (normally $HOME/.vimrc):
filetype plugin on
+
+
+Vim indentation plugin for Go
+=============================
+
+To install automatic indentation for Go:
+
+ 1. Same as 1 above.
+ 2. Copy or link indent/go.vim to the indent directory underneath your vim
+ runtime directory (normally $HOME/.vim/indent).
+ 3. Add the following line to your .vimrc file (normally $HOME/.vimrc):
+
+ filetype indent on
diff --git a/misc/vim/syntax/go.vim b/misc/vim/syntax/go.vim
index 7507cada2..26d7defe3 100644
--- a/misc/vim/syntax/go.vim
+++ b/misc/vim/syntax/go.vim
@@ -85,7 +85,7 @@ syn match goType /\<func\>/
syn match goDeclaration /^func\>/
" Predefined functions and values
-syn keyword goBuiltins append cap close closed complex copy imag len
+syn keyword goBuiltins append cap close complex copy imag len
syn keyword goBuiltins make new panic print println real recover
syn keyword goConstants iota true false nil
@@ -181,7 +181,7 @@ if go_highlight_extra_types != 0
syn match goExtraType /\<bytes\.\(Buffer\)\>/
syn match goExtraType /\<io\.\(Reader\|Writer\|ReadWriter\|ReadWriteCloser\)\>/
syn match goExtraType /\<\(os\.Error\)\>/
- syn match goExtraType /\<reflect\.\w*\(Type\|Value\)\>/
+ syn match goExtraType /\<reflect\.\(Kind\|Type\|Value\)\>/
syn match goExtraType /\<unsafe\.Pointer\>/
endif