Permalink
Browse files

[vim] go runtime files update

  • Loading branch information...
1 parent e193c10 commit dcc93129c815ce3a45c750ae3555e3266fd8f41c @guns committed Sep 13, 2013
@@ -32,39 +32,46 @@ function! go#complete#Package(ArgLead, CmdLine, CursorPos)
let dirs = []
if executable('go')
- let goroot = substitute(system('go env GOROOT'), '\n', '', 'g')
- if v:shell_error
- echo '\'go env GOROOT\' failed'
- endif
+ let goroot = substitute(system('go env GOROOT'), '\n', '', 'g')
+ if v:shell_error
+ echomsg '\'go env GOROOT\' failed'
+ endif
else
- let goroot = $GOROOT
+ let goroot = $GOROOT
endif
if len(goroot) != 0 && isdirectory(goroot)
- let dirs += [ goroot ]
+ let dirs += [goroot]
endif
- let workspaces = split($GOPATH, ':')
+ let pathsep = ':'
+ if s:goos == 'windows'
+ let pathsep = ';'
+ endif
+ let workspaces = split($GOPATH, pathsep)
if workspaces != []
- let dirs += workspaces
+ let dirs += workspaces
endif
if len(dirs) == 0
- " should not happen
- return []
+ " should not happen
+ return []
endif
let ret = {}
for dir in dirs
- let root = expand(dir . '/pkg/' . s:goos . '_' . s:goarch)
- for i in split(globpath(root, a:ArgLead.'*'), "\n")
- if isdirectory(i)
- let i .= '/'
- elseif i !~ '\.a$'
- continue
- endif
- let i = substitute(substitute(i[len(root)+1:], '[\\]', '/', 'g'), '\.a$', '', 'g')
- let ret[i] = i
+ " this may expand to multiple lines
+ let root = split(expand(dir . '/pkg/' . s:goos . '_' . s:goarch), "\n")
+ for r in root
+ for i in split(globpath(r, a:ArgLead.'*'), "\n")
+ if isdirectory(i)
+ let i .= '/'
+ elseif i !~ '\.a$'
+ continue
+ endif
+ let i = substitute(substitute(i[len(r)+1:], '[\\]', '/', 'g'), '\.a$', '', 'g')
+ let ret[i] = i
+ endfor
endfor
endfor
return sort(keys(ret))
@@ -0,0 +1,30 @@
+" Copyright 2013 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.
+"
+" compiler/go.vim: Vim compiler file for Go.
+
+if exists("current_compiler")
+ finish
+endif
+let current_compiler = "go"
+
+if exists(":CompilerSet") != 2
+ command -nargs=* CompilerSet setlocal <args>
+endif
+
+let s:save_cpo = &cpo
+set cpo-=C
+
+CompilerSet makeprg=go\ build
+CompilerSet errorformat=
+ \%-G#\ %.%#,
+ \%A%f:%l:%c:\ %m,
+ \%A%f:%l:\ %m,
+ \%C%*\\s%m,
+ \%-G%.%#
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
+
+" vim:ts=4:sw=4:et
@@ -0,0 +1,17 @@
+" Copyright 2013 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.
+"
+" go.vim: Vim filetype plugin for Go.
+
+if exists("b:did_ftplugin")
+ finish
+endif
+let b:did_ftplugin = 1
+
+setlocal comments=s1:/*,mb:*,ex:*/,://
+setlocal commentstring=//\ %s
+
+let b:undo_ftplugin = "setl com< cms<"
+
+" vim:ts=4:sw=4:et
@@ -12,11 +12,25 @@
" It tries to preserve cursor position and avoids
" replacing the buffer with stderr output.
"
+" Options:
+"
+" g:go_fmt_commands [default=1]
+"
+" Flag to indicate whether to enable the commands listed above.
+"
if exists("b:did_ftplugin_go_fmt")
finish
endif
-command! -buffer Fmt call s:GoFormat()
+
+if !exists("g:go_fmt_commands")
+ let g:go_fmt_commands = 1
+endif
+
+
+if g:go_fmt_commands
+ command! -buffer Fmt call s:GoFormat()
+endif
function! s:GoFormat()
let view = winsaveview()
@@ -24,23 +24,40 @@
" imported, an error will be displayed and the buffer will be
" untouched.
"
-" In addition to these commands, there are also two shortcuts mapped:
+" If you would like to add shortcuts, you can do so by doing the following:
"
-" \f - Runs :Import fmt
-" \F - Runs :Drop fmt
+" Import fmt
+" au Filetype go nnoremap <buffer> <LocalLeader>f :Import fmt<CR>
"
-" The backslash is the default maplocalleader, so it is possible that
+" Drop fmt
+" au Filetype go nnoremap <buffer> <LocalLeader>F :Drop fmt<CR>
+"
+" Import the word under your cursor
+" au Filetype go nnoremap <buffer> <LocalLeader>k
+" \ :exe 'Import ' . expand('<cword>')<CR>
+"
+" The backslash '\' is the default maplocalleader, so it is possible that
" your vim is set to use a different character (:help maplocalleader).
"
+" Options:
+"
+" g:go_import_commands [default=1]
+"
+" Flag to indicate whether to enable the commands listed above.
+"
if exists("b:did_ftplugin_go_import")
finish
endif
-command! -buffer -nargs=? -complete=customlist,go#complete#Package Drop call s:SwitchImport(0, '', <f-args>)
-command! -buffer -nargs=1 -complete=customlist,go#complete#Package Import call s:SwitchImport(1, '', <f-args>)
-command! -buffer -nargs=* -complete=customlist,go#complete#Package ImportAs call s:SwitchImport(1, <f-args>)
-map <buffer> <LocalLeader>f :Import fmt<CR>
-map <buffer> <LocalLeader>F :Drop fmt<CR>
+if !exists("g:go_import_commands")
+ let g:go_import_commands = 1
+endif
+
+if g:go_import_commands
+ command! -buffer -nargs=? -complete=customlist,go#complete#Package Drop call s:SwitchImport(0, '', <f-args>)
+ command! -buffer -nargs=1 -complete=customlist,go#complete#Package Import call s:SwitchImport(1, '', <f-args>)
+ command! -buffer -nargs=* -complete=customlist,go#complete#Package ImportAs call s:SwitchImport(1, <f-args>)
+endif
function! s:SwitchImport(enabled, localname, path)
let view = winsaveview()
@@ -29,13 +29,13 @@ test_one() {
vim -e -s -u /dev/null -U /dev/null --noplugin -c "source import.vim" \
-c "$1" -c 'wq! test.go' base.go
# ensure blank lines are treated correctly
- if ! gofmt test.go | cmp test.go; then
+ if ! gofmt test.go | cmp test.go -; then
echo 2>&1 "gofmt conflict"
gofmt test.go | diff -u test.go - | sed "s/^/ /" 2>&1
fail=1
return
fi
- if ! grep -P -q "(?s)$2" test.go; then
+ if ! [[ $(cat test.go) =~ $2 ]]; then
echo 2>&1 "$2 did not match"
cat test.go | sed "s/^/ /" 2>&1
fail=1
@@ -3,6 +3,20 @@
" license that can be found in the LICENSE file.
"
" godoc.vim: Vim command to see godoc.
+"
+"
+" Commands:
+"
+" :Godoc
+"
+" Open the relevant Godoc for either the word[s] passed to the command or
+" the, by default, the word under the cursor.
+"
+" Options:
+"
+" g:go_godoc_commands [default=1]
+"
+" Flag to indicate whether to enable the commands listed above.
if exists("g:loaded_godoc")
finish
@@ -12,6 +26,16 @@ let g:loaded_godoc = 1
let s:buf_nr = -1
let s:last_word = ''
+if !exists('g:go_godoc_commands')
+ let g:go_godoc_commands = 1
+endif
+
+if g:go_godoc_commands
+ command! -nargs=* -range -complete=customlist,go#complete#Package Godoc :call s:Godoc(<q-args>)
+endif
+
+nnoremap <silent> <Plug>(godoc-keyword) :<C-u>call <SID>Godoc('')<CR>
+
function! s:GodocView()
if !bufexists(s:buf_nr)
leftabove new
@@ -92,7 +116,4 @@ function! s:Godoc(...)
endif
endfunction
-command! -nargs=* -range -complete=customlist,go#complete#Package Godoc :call s:Godoc(<q-args>)
-nnoremap <silent> <Plug>(godoc-keyword) :<C-u>call <SID>Godoc('')<CR>
-
" vim:ts=4:sw=4:et
@@ -14,6 +14,7 @@ To use all the Vim plugins, add these lines to your $HOME/.vimrc.
If you want to select fewer plugins, use the instructions in the rest of
this file.
+
Vim syntax highlighting
-----------------------
@@ -47,9 +48,10 @@ Vim filetype plugins
To install one of the available filetype plugins:
1. Same as 1 above.
- 2. Copy or link one or more plugins from ftplugin/go/*.vim to the
- Go-specific ftplugin directory underneath your vim runtime directory
- (normally $HOME/.vim/ftplugin/go/*.vim).
+ 2. Copy or link ftplugin/go.vim to the ftplugin directory underneath your vim
+ runtime directory (normally $HOME/.vim/ftplugin). Copy or link one or more
+ additional plugins from ftplugin/go/*.vim to the Go-specific subdirectory
+ in the same place ($HOME/.vim/ftplugin/go/*.vim).
3. Add the following line to your .vimrc file (normally $HOME/.vimrc):
filetype plugin on
@@ -68,6 +70,21 @@ To install automatic indentation:
filetype indent on
+Vim compiler plugin
+-------------------
+
+To install the compiler plugin:
+
+ 1. Same as 1 above.
+ 2. Copy or link compiler/go.vim to the compiler directory underneath your vim
+ runtime directory (normally $HOME/.vim/compiler).
+ 3. Activate the compiler plugin with ":compiler go". To always enable the
+ compiler plugin in Go source files add an autocommand to your .vimrc file
+ (normally $HOME/.vimrc):
+
+ autocmd FileType go compiler go
+
+
Godoc plugin
------------

0 comments on commit dcc9312

Please sign in to comment.