reformat file by external tool before writing file in vim











up vote
0
down vote

favorite












I want the vim to call ':!gn format BUILD.gn' when I write BUILD.gn file, my .vimrc is (version 1)



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnForamt()
exec '!gn format %'
endfunction


But it can not work when I press ':w", it shows error message as



Error detected while processing BufWrite Autocommands for "*.gn":
"BUILD.gn" 67L, 1423C written


How to show more detail debug information and what's the correct method to call external format tool?



I also tried following method, but failed too (version 2)



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnForamt()
exec '%!gn format --stdin'
endfunction


The output result of version 2 .vimrc of :11verbose w is



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))


And in the version 2, I can use :call GnForamt() manually to reformat the buffer without any error message.



Just know the reason



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnFormat() " <--- typo of Format as Foramt
exec '%!gn format --stdin'
endfunction









share|improve this question
























  • Shouldn't it be *.gn,*.gni as filetype?
    – Doktor OSwaldo
    Nov 8 at 7:05










  • It can changed to BUILD.gn, but still not workable, you can try it.
    – Daniel YC Lin
    Nov 8 at 7:14










  • don't worry *.{gn,gni} seems to work depending on your output. It is just new for me
    – Doktor OSwaldo
    Nov 8 at 7:18















up vote
0
down vote

favorite












I want the vim to call ':!gn format BUILD.gn' when I write BUILD.gn file, my .vimrc is (version 1)



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnForamt()
exec '!gn format %'
endfunction


But it can not work when I press ':w", it shows error message as



Error detected while processing BufWrite Autocommands for "*.gn":
"BUILD.gn" 67L, 1423C written


How to show more detail debug information and what's the correct method to call external format tool?



I also tried following method, but failed too (version 2)



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnForamt()
exec '%!gn format --stdin'
endfunction


The output result of version 2 .vimrc of :11verbose w is



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))


And in the version 2, I can use :call GnForamt() manually to reformat the buffer without any error message.



Just know the reason



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnFormat() " <--- typo of Format as Foramt
exec '%!gn format --stdin'
endfunction









share|improve this question
























  • Shouldn't it be *.gn,*.gni as filetype?
    – Doktor OSwaldo
    Nov 8 at 7:05










  • It can changed to BUILD.gn, but still not workable, you can try it.
    – Daniel YC Lin
    Nov 8 at 7:14










  • don't worry *.{gn,gni} seems to work depending on your output. It is just new for me
    – Doktor OSwaldo
    Nov 8 at 7:18













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want the vim to call ':!gn format BUILD.gn' when I write BUILD.gn file, my .vimrc is (version 1)



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnForamt()
exec '!gn format %'
endfunction


But it can not work when I press ':w", it shows error message as



Error detected while processing BufWrite Autocommands for "*.gn":
"BUILD.gn" 67L, 1423C written


How to show more detail debug information and what's the correct method to call external format tool?



I also tried following method, but failed too (version 2)



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnForamt()
exec '%!gn format --stdin'
endfunction


The output result of version 2 .vimrc of :11verbose w is



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))


And in the version 2, I can use :call GnForamt() manually to reformat the buffer without any error message.



Just know the reason



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnFormat() " <--- typo of Format as Foramt
exec '%!gn format --stdin'
endfunction









share|improve this question















I want the vim to call ':!gn format BUILD.gn' when I write BUILD.gn file, my .vimrc is (version 1)



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnForamt()
exec '!gn format %'
endfunction


But it can not work when I press ':w", it shows error message as



Error detected while processing BufWrite Autocommands for "*.gn":
"BUILD.gn" 67L, 1423C written


How to show more detail debug information and what's the correct method to call external format tool?



I also tried following method, but failed too (version 2)



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnForamt()
exec '%!gn format --stdin'
endfunction


The output result of version 2 .vimrc of :11verbose w is



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))


And in the version 2, I can use :call GnForamt() manually to reformat the buffer without any error message.



Just know the reason



autocmd BufWritePre  *.{gn,gni} call GnFormat()
function! GnFormat() " <--- typo of Format as Foramt
exec '%!gn format --stdin'
endfunction






vim






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 7:53

























asked Nov 8 at 3:28









Daniel YC Lin

4,44893963




4,44893963












  • Shouldn't it be *.gn,*.gni as filetype?
    – Doktor OSwaldo
    Nov 8 at 7:05










  • It can changed to BUILD.gn, but still not workable, you can try it.
    – Daniel YC Lin
    Nov 8 at 7:14










  • don't worry *.{gn,gni} seems to work depending on your output. It is just new for me
    – Doktor OSwaldo
    Nov 8 at 7:18


















  • Shouldn't it be *.gn,*.gni as filetype?
    – Doktor OSwaldo
    Nov 8 at 7:05










  • It can changed to BUILD.gn, but still not workable, you can try it.
    – Daniel YC Lin
    Nov 8 at 7:14










  • don't worry *.{gn,gni} seems to work depending on your output. It is just new for me
    – Doktor OSwaldo
    Nov 8 at 7:18
















Shouldn't it be *.gn,*.gni as filetype?
– Doktor OSwaldo
Nov 8 at 7:05




Shouldn't it be *.gn,*.gni as filetype?
– Doktor OSwaldo
Nov 8 at 7:05












It can changed to BUILD.gn, but still not workable, you can try it.
– Daniel YC Lin
Nov 8 at 7:14




It can changed to BUILD.gn, but still not workable, you can try it.
– Daniel YC Lin
Nov 8 at 7:14












don't worry *.{gn,gni} seems to work depending on your output. It is just new for me
– Doktor OSwaldo
Nov 8 at 7:18




don't worry *.{gn,gni} seems to work depending on your output. It is just new for me
– Doktor OSwaldo
Nov 8 at 7:18












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










try :debug w (see :h debug) or :13verbose w. See :h verbose and :h 'verbose'.



:[level]verbose will allow you to activate verbose mode for a single action






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201144%2freformat-file-by-external-tool-before-writing-file-in-vim%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    try :debug w (see :h debug) or :13verbose w. See :h verbose and :h 'verbose'.



    :[level]verbose will allow you to activate verbose mode for a single action






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      try :debug w (see :h debug) or :13verbose w. See :h verbose and :h 'verbose'.



      :[level]verbose will allow you to activate verbose mode for a single action






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        try :debug w (see :h debug) or :13verbose w. See :h verbose and :h 'verbose'.



        :[level]verbose will allow you to activate verbose mode for a single action






        share|improve this answer












        try :debug w (see :h debug) or :13verbose w. See :h verbose and :h 'verbose'.



        :[level]verbose will allow you to activate verbose mode for a single action







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 7:11









        Doktor OSwaldo

        3,524826




        3,524826






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201144%2freformat-file-by-external-tool-before-writing-file-in-vim%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings