all repos — dotfiles @ 037cb472cc122197838a1c583d6202e556c23dff

my *nix dotfiles

config/nvim/ftplugin/go.vim (view raw)

 1setlocal noexpandtab
 2setlocal autoindent
 3setlocal shiftwidth=4
 4setlocal smarttab
 5setlocal formatoptions=croql
 6setlocal tabstop=4
 7
 8" stolen from https://go.googlesource.com/go/+/c4f5421/misc/vim/ftplugin/go/fmt.vim
 9
10if exists("b:did_ftplugin_go_fmt")
11    finish
12endif
13if !exists("g:go_fmt_commands")
14    let g:go_fmt_commands = 1
15endif
16if !exists("g:gofmt_command")
17    if executable("goimports")
18        let g:gofmt_command = "goimports"
19    else
20        let g:gofmt_command = "gofmt"
21    endif
22endif
23if g:go_fmt_commands
24    command! -buffer Fmt call s:GoFormat()
25endif
26function! s:GoFormat()
27    let view = winsaveview()
28    silent execute "%!" . g:gofmt_command
29    if v:shell_error
30        let errors = []
31        for line in getline(1, line('$'))
32            let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
33            if !empty(tokens)
34                call add(errors, {"filename": @%,
35                                 \"lnum":     tokens[2],
36                                 \"col":      tokens[3],
37                                 \"text":     tokens[4]})
38            endif
39        endfor
40        if empty(errors)
41            % | " Couldn't detect gofmt error format, output errors
42        endif
43        undo
44        if !empty(errors)
45            call setloclist(0, errors, 'r')
46        endif
47        echohl Error | echomsg "Gofmt returned error" | echohl None
48    endif
49    call winrestview(view)
50endfunction
51let b:did_ftplugin_go_fmt = 1
52" vim:ts=4:sw=4:et