all repos — dotfiles @ a80f1ed0a43626deaa73f789ed683816f2404579

my *nix dotfiles

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

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