summaryrefslogtreecommitdiffstats
path: root/ftplugin/vlang.vim
diff options
context:
space:
mode:
Diffstat (limited to 'ftplugin/vlang.vim')
-rw-r--r--ftplugin/vlang.vim31
1 files changed, 31 insertions, 0 deletions
diff --git a/ftplugin/vlang.vim b/ftplugin/vlang.vim
index cda16cba..fbc0a711 100644
--- a/ftplugin/vlang.vim
+++ b/ftplugin/vlang.vim
@@ -2,5 +2,36 @@ if polyglot#init#is_disabled(expand('<sfile>:p'), 'v', 'ftplugin/vlang.vim')
finish
endif
+if exists("b:did_ftplugin")
+ finish
+endif
+
setlocal commentstring=//\ %s
setlocal makeprg=v\ %
+
+if exists('b:undo_ftplugin')
+ let b:undo_ftplugin .= "|setlocal commentstring< makeprg<"
+else
+ let b:undo_ftplugin = "setlocal commentstring< makeprg<"
+endif
+
+function! _VFormatFile()
+ if exists('g:v_autofmt_bufwritepre') && g:v_autofmt_bufwritepre || exists('b:v_autofmt_bufwritepre') && b:v_autofmt_bufwritepre
+ let substitution = system("v fmt -", join(getline(1, line('$')), "\n"))
+ if v:shell_error != 0
+ echoerr "While formatting the buffer via vfmt, the following error occurred:"
+ echoerr printf("ERROR(%d): %s", v:shell_error, substitution)
+ else
+ let [_, lnum, colnum, _] = getpos('.')
+ %delete
+ call append(0, split(substitution, "\n"))
+ call cursor(lnum, colnum)
+ endif
+ endif
+endfunction
+
+if has('autocmd')
+ augroup v_fmt
+ autocmd BufWritePre *.v call _VFormatFile()
+ augroup END
+endif