-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.vim
129 lines (118 loc) · 3.04 KB
/
go.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
" *** General
au FileType go setlocal noexpandtab
au FileType go setlocal ts=3
au FileType go setlocal sw=3
let g:indent_guides_enable_on_vim_startup = 0
" :IndentGuidesDisable
" vim-go
let g:go_snippet_engine = "ultisnips"
let g:go_disable_autoinstall = 0
func! GoFmtImap()
let lines_before = line('$')
let cur_pos = getpos('.')
:GoFmt
let lines_after = line('$')
let line_diff = max([0,cur_pos[1] + lines_after - lines_before])
let cur_pos[1] = line_diff
call setpos('.', cur_pos)
endfunc
func! GoImportImap()
let lines_before = line('$')
let cur_pos = getpos('.')
let pkg = input('GoImport ')
execute ':GoImport ' . pkg
let lines_after = line('$')
let line_diff = max([0,cur_pos[1] + lines_after - lines_before])
let cur_pos[1] = line_diff
call setpos('.', cur_pos)
endfunc
au FileType go imap <C-A-i> <C-\><C-O>call GoImportImap()
" au FileType go nmap <C-A-f> <Plug>(go-format)
au FileType go nmap <Leader>gd <Plug>(go-doc-split)
au FileType go nnoremap <leader>m :silent make\|redraw!\|botright cwindow\|cc<CR>
au BufEnter,FileType go :TagbarOpen
" ***
" GoDef
au FileType go let g:godef_same_file_in_same_window = 1
" ***
" ***
" tag bar
au FileType go let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
" ***
" ***
" GoDoc
function! FixWindows()
let cur_win = winnr()
let cur_cur = getcurpos()
call tagbar#CloseWindow()
exec "wincmd ="
call tagbar#OpenWindow()
let qf = []
let pw = []
let godoc = []
for i in range(1,winnr('$'))
if getbufvar(winbufnr(i), '&filetype') == "godoc"
call insert(godoc,i)
endif
if getwinvar(i, '&previewwindow')
call insert(pw,i)
endif
if getbufvar(winbufnr(i), '&filetype') == "qf"
call insert(qf,i)
endif
endfor
for i in qf
exec i."wincmd w"
" wincmd J
call AdjustWindowHeight(3,10)
setlocal winheight=3
setlocal winminheight=3
call AdjustWindowHeight(3,10)
endfor
for i in godoc
exec i."wincmd w"
call AdjustWindowHeight(10,10)
endfor
for i in pw
exec i."wincmd w"
call AdjustWindowHeight(3,10)
setlocal winheight=3
setlocal winminheight=3
call AdjustWindowHeight(3,10)
endfor
exec cur_win."wincmd w"
call setpos(".", cur_cur)
endfunc
nmap <C-g> :silent call FixWindows()<CR>
au FileType godoc resize 10
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage)
" autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow