mirror of
https://github.com/golang/go
synced 2024-11-24 22:00:09 -07:00
misc/vim: command complete using autoload helper function.
R=golang-dev, dsymonds, jnwhiteh, n13m3y3r, gustavo CC=golang-dev https://golang.org/cl/4837051
This commit is contained in:
parent
8380ff34ed
commit
d2a45dbf08
49
misc/vim/autoload/go/complete.vim
Normal file
49
misc/vim/autoload/go/complete.vim
Normal file
@ -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
|
@ -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>
|
||||
|
||||
|
@ -11,8 +11,6 @@ let g:loaded_godoc = 1
|
||||
|
||||
let s:buf_nr = -1
|
||||
let s:last_word = ''
|
||||
let s:goos = $GOOS
|
||||
let s:goarch = $GOARCH
|
||||
|
||||
function! s:GodocView()
|
||||
if !bufexists(s:buf_nr)
|
||||
@ -81,43 +79,7 @@ function! s:Godoc(...)
|
||||
call s:GodocWord(word)
|
||||
endfunction
|
||||
|
||||
function! s:GodocComplete(ArgLead, CmdLine, CursorPos)
|
||||
if len($GOROOT) == 0
|
||||
return []
|
||||
endif
|
||||
if len(s:goos) == 0
|
||||
if exists('g:godoc_goos')
|
||||
let s:goos = g:godoc_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:godoc_goarch')
|
||||
let s:goarch = g:godoc_goarch
|
||||
else
|
||||
let s:goarch = g:godoc_goarch
|
||||
endif
|
||||
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
|
||||
|
||||
command! -nargs=* -range -complete=customlist,s:GodocComplete Godoc :call s:Godoc(<q-args>)
|
||||
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
|
||||
|
@ -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
|
||||
@ -51,11 +65,12 @@ To install automatic indentation for Go:
|
||||
|
||||
|
||||
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,
|
||||
and ftplugin/go/godoc.vim to $HOME/.vim/ftplugin/go/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.
|
||||
|
Loading…
Reference in New Issue
Block a user