summaryrefslogtreecommitdiff
path: root/misc/vim
diff options
context:
space:
mode:
Diffstat (limited to 'misc/vim')
-rw-r--r--misc/vim/autoload/go/complete.vim49
-rw-r--r--misc/vim/ftplugin/go/godoc.vim13
-rw-r--r--misc/vim/ftplugin/go/import.vim6
-rw-r--r--misc/vim/plugin/godoc.vim85
-rw-r--r--misc/vim/readme.txt42
-rw-r--r--misc/vim/syntax/godoc.vim20
6 files changed, 204 insertions, 11 deletions
diff --git a/misc/vim/autoload/go/complete.vim b/misc/vim/autoload/go/complete.vim
new file mode 100644
index 000000000..d4ae3b97f
--- /dev/null
+++ b/misc/vim/autoload/go/complete.vim
@@ -0,0 +1,49 @@
+" 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.
+"
+" This file provides a utility function that performs auto-completion of
+" package names, for use by other commands.
+
+let s:goos = $GOOS
+let s:goarch = $GOARCH
+
+if len(s:goos) == 0
+ if exists('g:golang_goos')
+ let s:goos = g:golang_goos
+ elseif has('win32') || has('win64')
+ let s:goos = 'windows'
+ elseif has('macunix')
+ let s:goos = 'darwin'
+ else
+ let s:goos = '*'
+ endif
+endif
+
+if len(s:goarch) == 0
+ if exists('g:golang_goarch')
+ let s:goarch = g:golang_goarch
+ else
+ let s:goarch = '*'
+ endif
+endif
+
+function! go#complete#Package(ArgLead, CmdLine, CursorPos)
+ let goroot = $GOROOT
+ if len(goroot) == 0
+ " should not occur.
+ return []
+ endif
+ let ret = {}
+ let root = expand(goroot.'/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
+ endfor
+ return sort(keys(ret))
+endfunction
diff --git a/misc/vim/ftplugin/go/godoc.vim b/misc/vim/ftplugin/go/godoc.vim
new file mode 100644
index 000000000..55195a674
--- /dev/null
+++ b/misc/vim/ftplugin/go/godoc.vim
@@ -0,0 +1,13 @@
+" 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.
+"
+" godoc.vim: Vim command to see godoc.
+
+if exists("b:did_ftplugin")
+ finish
+endif
+
+silent! nmap <buffer> <silent> K <Plug>(godoc-keyword)
+
+" vim:ts=4:sw=4:et
diff --git a/misc/vim/ftplugin/go/import.vim b/misc/vim/ftplugin/go/import.vim
index b5814ca5d..6705a476b 100644
--- a/misc/vim/ftplugin/go/import.vim
+++ b/misc/vim/ftplugin/go/import.vim
@@ -36,9 +36,9 @@ if exists("b:did_ftplugin")
finish
endif
-command! -buffer -nargs=? Drop call s:SwitchImport(0, '', <f-args>)
-command! -buffer -nargs=1 Import call s:SwitchImport(1, '', <f-args>)
-command! -buffer -nargs=* ImportAs call s:SwitchImport(1, <f-args>)
+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>
diff --git a/misc/vim/plugin/godoc.vim b/misc/vim/plugin/godoc.vim
new file mode 100644
index 000000000..fdb496631
--- /dev/null
+++ b/misc/vim/plugin/godoc.vim
@@ -0,0 +1,85 @@
+" 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.
+"
+" godoc.vim: Vim command to see godoc.
+
+if exists("g:loaded_godoc")
+ finish
+endif
+let g:loaded_godoc = 1
+
+let s:buf_nr = -1
+let s:last_word = ''
+
+function! s:GodocView()
+ if !bufexists(s:buf_nr)
+ leftabove new
+ file `="[Godoc]"`
+ let s:buf_nr = bufnr('%')
+ elseif bufwinnr(s:buf_nr) == -1
+ leftabove split
+ execute s:buf_nr . 'buffer'
+ delete _
+ elseif bufwinnr(s:buf_nr) != bufwinnr('%')
+ execute bufwinnr(s:buf_nr) . 'wincmd w'
+ endif
+
+ setlocal filetype=godoc
+ setlocal bufhidden=delete
+ setlocal buftype=nofile
+ setlocal noswapfile
+ setlocal nobuflisted
+ setlocal modifiable
+ setlocal nocursorline
+ setlocal nocursorcolumn
+ setlocal iskeyword+=:
+ setlocal iskeyword-=-
+
+ nnoremap <buffer> <silent> K :Godoc<cr>
+
+ au BufHidden <buffer> call let <SID>buf_nr = -1
+endfunction
+
+function! s:GodocWord(word)
+ let word = a:word
+ silent! let content = system('godoc ' . word)
+ if v:shell_error || !len(content)
+ if len(s:last_word)
+ silent! let content = system('godoc ' . s:last_word.'/'.word)
+ if v:shell_error || !len(content)
+ echo 'No documentation found for "' . word . '".'
+ return
+ endif
+ let word = s:last_word.'/'.word
+ else
+ echo 'No documentation found for "' . word . '".'
+ return
+ endif
+ endif
+ let s:last_word = word
+ silent! call s:GodocView()
+ setlocal modifiable
+ silent! %d _
+ silent! put! =content
+ silent! normal gg
+ setlocal nomodifiable
+ setfiletype godoc
+endfunction
+
+function! s:Godoc(...)
+ let word = join(a:000, ' ')
+ if !len(word)
+ let word = expand('<cword>')
+ endif
+ let word = substitute(word, '[^a-zA-Z0-9\/]', '', 'g')
+ if !len(word)
+ return
+ endif
+ call s:GodocWord(word)
+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
diff --git a/misc/vim/readme.txt b/misc/vim/readme.txt
index 3c3255113..fe15da993 100644
--- a/misc/vim/readme.txt
+++ b/misc/vim/readme.txt
@@ -1,5 +1,17 @@
-Vim syntax highlighting for Go (http://golang.org)
-==================================================
+Vim plugins for Go (http://golang.org)
+======================================
+
+To use all the Vim plugins, add these lines to your vimrc.
+
+ set rtp+=$GOROOT/misc/vim
+ filetype plugin indent on
+ syntax on
+
+If you want to select fewer plugins, use the instructions in the rest of
+this file.
+
+Vim syntax highlighting
+-----------------------
To install automatic syntax highlighting for GO programs:
@@ -18,15 +30,17 @@ commands:
mkdir -p $HOME/.vim/ftdetect
mkdir -p $HOME/.vim/syntax
+ mkdir -p $HOME/.vim/autoload/go
ln -s $GOROOT/misc/vim/ftdetect/gofiletype.vim $HOME/.vim/ftdetect/
ln -s $GOROOT/misc/vim/syntax/go.vim $HOME/.vim/syntax
+ ln -s $GOROOT/misc/vim/autoload/go/complete.vim $HOME/.vim/autoload/go
echo "syntax on" >> $HOME/.vimrc
-Vim filetype plugins for Go
-===========================
+Vim filetype plugins
+--------------------
-To install one of the available filetype plugins for Go:
+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
@@ -37,10 +51,10 @@ To install one of the available filetype plugins for Go:
filetype plugin on
-Vim indentation plugin for Go
-=============================
+Vim indentation plugin
+----------------------
-To install automatic indentation for Go:
+To install automatic indentation:
1. Same as 1 above.
2. Copy or link indent/go.vim to the indent directory underneath your vim
@@ -48,3 +62,15 @@ To install automatic indentation for Go:
3. Add the following line to your .vimrc file (normally $HOME/.vimrc):
filetype indent on
+
+
+Godoc plugin
+------------
+
+To install godoc plugin:
+
+ 1. Same as 1 above.
+ 2. Copy or link plugin/godoc.vim to $HOME/.vim/plugin/godoc,
+ syntax/godoc.vim to $HOME/.vim/syntax/godoc.vim,
+ ftplugin/go/godoc.vim to $HOME/.vim/ftplugin/go/godoc.vim.
+ and autoload/go/complete.vim to $HOME/.vim/autoload/go/complete.vim.
diff --git a/misc/vim/syntax/godoc.vim b/misc/vim/syntax/godoc.vim
new file mode 100644
index 000000000..82f78aa3c
--- /dev/null
+++ b/misc/vim/syntax/godoc.vim
@@ -0,0 +1,20 @@
+" 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.
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn case match
+syn match godocTitle "^\([A-Z]*\)$"
+
+command -nargs=+ HiLink hi def link <args>
+
+HiLink godocTitle Title
+
+delcommand HiLink
+
+let b:current_syntax = "godoc"
+
+" vim:ts=4 sts=2 sw=2: