Skip to content

Instantly share code, notes, and snippets.

@chendotjs
Last active August 24, 2019 15:25
Show Gist options
  • Save chendotjs/b59503f22da0385b19a8cd3e8ea7ea58 to your computer and use it in GitHub Desktop.
Save chendotjs/b59503f22da0385b19a8cd3e8ea7ea58 to your computer and use it in GitHub Desktop.
goman
" 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.
" ~/.vim/syntax/godoc.vim
if exists("b:current_syntax")
finish
endif
noremap <buffer> q :q!<CR>
syn case match
syn match godocTitle "^\([A-Z][A-Z ]*\)$"
hi def link godocTitle Title
" Single Line Definitions
syn match godocMethodRec /\i\+\ze)/ contained
syn match godocMethodName /) \zs\i\+\ze(/ contained
syn match godocMethod /^func \((\i\+ [^)]*)\) \i\+(/ contains=godocMethodRec,godocMethodName
syn match godocFunction /^func \zs\i\+\ze(/
syn match godocType /^type \zs\i\+\ze.*/
syn match godocVar /^var \zs\i\+\ze.*/
syn match godocConst /^const \zs\i\+\ze.*/
hi def link godocMethodRec Type
hi def link godocType Type
hi def link godocMethodName Function
hi def link godocFunction Function
hi def link godocVar Identifier
hi def link godocConst Identifier
" Definition Blocks
syn region godocComment start="/\*" end="\*/" contained
syn region godocComment start="//" end="$" contained
syn match godocDefinition /^\s\+\i\+/ contained
syn region godocVarBlock start=/^var (/ end=/^)/ contains=godocComment,godocDefinition
syn region godocConstBlock start=/^const (/ end=/^)/ contains=godocComment,godocDefinition
syn region godocTypeBlock start=/^type \i\+ \(interface\|struct\) {/ end=/^}/ matchgroup=godocType contains=godocComment,godocType
hi def link godocComment Comment
hi def link godocDefinition Identifier
syn sync minlines=500
let b:current_syntax = "godoc"
" vim:ts=4 sts=2 sw=2:
#$ echo 'gocol () { go doc "$@"|vim -Rnc "set filetype=godoc" - ;}' >> \
#~/.bash_aliases
#You may grab godoc.vim syntax file from https://github.com/fatih/vim-go
#(last time it was at v1.5 checkout) and put it in your vimrc. You need to
#tinker with it as it was abandoned after godoc migrated to 'go doc'.
goman() { go doc -all "$@" | vim -Rn -c "set syntax=godoc" -c "set ic" - ;}
golist() { go doc "$@" | vim -Rn -c "set syntax=godoc" -c "set ic" - ;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment