我要维姆呼叫':!gn format BUILD.gn'当我写BUILD.gn文件时,我的.vimrc是(版本1)
autocmd BufWritePre *.{gn,gni} call GnFormat()
function! GnForamt()
exec '!gn format %'
endfunction
但当我按“:w”时它不能工作,它显示错误消息
Error detected while processing BufWrite Autocommands for "*.gn":
"BUILD.gn" 67L, 1423C written
我也尝试了以下方法,但也失败了(版本2)
autocmd BufWritePre *.{gn,gni} call GnFormat()
function! GnForamt()
exec '%!gn format --stdin'
endfunction
的版本2.vimrc的输出结果
:11verbose w
Executing BufWrite Autocommands for "*.{gn,gni}"
autocommand call GnFormat()
Error detected while processing BufWrite Autocommands for "*.{gn,gni}":
"BUILD.gn" 27L, 538C written
Executing BufWritePost Autocommands for "*"
autocommand cal s:record(expand('<abuf>', 1))
Executing BufWritePost Autocommands for "*"
autocommand call s:BufWritePostHook(expand('<afile>', 1))
在版本2中,我可以使用
:call GnForamt()
手动重新格式化缓冲区而不显示任何错误消息。
只知道原因
autocmd BufWritePre *.{gn,gni} call GnFormat()
function! GnFormat() " <--- typo of Format as Foramt
exec '%!gn format --stdin'
endfunction