vim: Force specific syntax via command-line argument












14















When I want to easily read my PostgreSQL schema, I dump it to stderr and redirect it to vim:



pg_dump -h localhost -U postgres dog_food --schema-only | vim -


This gives:



enter image description here



vim does not have a syntax highlight schema, because it has no filename extension when reading from stdin, so I use the following:



:set syntax=sql


Which gives:



enter image description here



Being the lazy developer I am, I would like to force vim to use the SQL syntax by passing a command line argument, saving me the choir of re-typing set syntax=<whatever> every time I open it with stdin data..



Is there a way to set vim syntax by passing a command line argument?










share|improve this question



























    14















    When I want to easily read my PostgreSQL schema, I dump it to stderr and redirect it to vim:



    pg_dump -h localhost -U postgres dog_food --schema-only | vim -


    This gives:



    enter image description here



    vim does not have a syntax highlight schema, because it has no filename extension when reading from stdin, so I use the following:



    :set syntax=sql


    Which gives:



    enter image description here



    Being the lazy developer I am, I would like to force vim to use the SQL syntax by passing a command line argument, saving me the choir of re-typing set syntax=<whatever> every time I open it with stdin data..



    Is there a way to set vim syntax by passing a command line argument?










    share|improve this question

























      14












      14








      14








      When I want to easily read my PostgreSQL schema, I dump it to stderr and redirect it to vim:



      pg_dump -h localhost -U postgres dog_food --schema-only | vim -


      This gives:



      enter image description here



      vim does not have a syntax highlight schema, because it has no filename extension when reading from stdin, so I use the following:



      :set syntax=sql


      Which gives:



      enter image description here



      Being the lazy developer I am, I would like to force vim to use the SQL syntax by passing a command line argument, saving me the choir of re-typing set syntax=<whatever> every time I open it with stdin data..



      Is there a way to set vim syntax by passing a command line argument?










      share|improve this question














      When I want to easily read my PostgreSQL schema, I dump it to stderr and redirect it to vim:



      pg_dump -h localhost -U postgres dog_food --schema-only | vim -


      This gives:



      enter image description here



      vim does not have a syntax highlight schema, because it has no filename extension when reading from stdin, so I use the following:



      :set syntax=sql


      Which gives:



      enter image description here



      Being the lazy developer I am, I would like to force vim to use the SQL syntax by passing a command line argument, saving me the choir of re-typing set syntax=<whatever> every time I open it with stdin data..



      Is there a way to set vim syntax by passing a command line argument?







      vim stdout stdin sql syntax-highlighting






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 10 '16 at 11:40









      Adam MatanAdam Matan

      83331525




      83331525






















          3 Answers
          3






          active

          oldest

          votes


















          17














          You can use:



          vim -c 'set syntax=sql' -





          share|improve this answer





















          • 2





            Note: Works for me even without the colon in the command.

            – Murphy
            Mar 10 '16 at 12:27






          • 1





            Shorter variant: vim '+set syn=sql' -

            – Stéphane Chazelas
            Mar 10 '16 at 13:01








          • 5





            Typically you're better off using set filetype=sql (or ft=sql for short); that will also load the indentation files and such and not just the syntax highlighting...

            – Martin Tournoij
            Mar 16 '16 at 7:11





















          1














          You can even automate that by putting the command into your ~/.vimrc:



          augroup filetype
          au! StdinReadPre * set filetype=sql
          augroup END





          share|improve this answer

































            1














            vim -R -c 'set ft=sql' -




            • -R opens Vim in read-only mode. Your system may have the alias view for vim -R, but Neovim does not support it.


            • set ft is short for set filetype. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.






            share|improve this answer










            New contributor




            anishpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "106"
              };
              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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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%2funix.stackexchange.com%2fquestions%2f268889%2fvim-force-specific-syntax-via-command-line-argument%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              17














              You can use:



              vim -c 'set syntax=sql' -





              share|improve this answer





















              • 2





                Note: Works for me even without the colon in the command.

                – Murphy
                Mar 10 '16 at 12:27






              • 1





                Shorter variant: vim '+set syn=sql' -

                – Stéphane Chazelas
                Mar 10 '16 at 13:01








              • 5





                Typically you're better off using set filetype=sql (or ft=sql for short); that will also load the indentation files and such and not just the syntax highlighting...

                – Martin Tournoij
                Mar 16 '16 at 7:11


















              17














              You can use:



              vim -c 'set syntax=sql' -





              share|improve this answer





















              • 2





                Note: Works for me even without the colon in the command.

                – Murphy
                Mar 10 '16 at 12:27






              • 1





                Shorter variant: vim '+set syn=sql' -

                – Stéphane Chazelas
                Mar 10 '16 at 13:01








              • 5





                Typically you're better off using set filetype=sql (or ft=sql for short); that will also load the indentation files and such and not just the syntax highlighting...

                – Martin Tournoij
                Mar 16 '16 at 7:11
















              17












              17








              17







              You can use:



              vim -c 'set syntax=sql' -





              share|improve this answer















              You can use:



              vim -c 'set syntax=sql' -






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 10 '16 at 12:59









              Stéphane Chazelas

              309k57582942




              309k57582942










              answered Mar 10 '16 at 12:24









              LambertLambert

              9,07021228




              9,07021228








              • 2





                Note: Works for me even without the colon in the command.

                – Murphy
                Mar 10 '16 at 12:27






              • 1





                Shorter variant: vim '+set syn=sql' -

                – Stéphane Chazelas
                Mar 10 '16 at 13:01








              • 5





                Typically you're better off using set filetype=sql (or ft=sql for short); that will also load the indentation files and such and not just the syntax highlighting...

                – Martin Tournoij
                Mar 16 '16 at 7:11
















              • 2





                Note: Works for me even without the colon in the command.

                – Murphy
                Mar 10 '16 at 12:27






              • 1





                Shorter variant: vim '+set syn=sql' -

                – Stéphane Chazelas
                Mar 10 '16 at 13:01








              • 5





                Typically you're better off using set filetype=sql (or ft=sql for short); that will also load the indentation files and such and not just the syntax highlighting...

                – Martin Tournoij
                Mar 16 '16 at 7:11










              2




              2





              Note: Works for me even without the colon in the command.

              – Murphy
              Mar 10 '16 at 12:27





              Note: Works for me even without the colon in the command.

              – Murphy
              Mar 10 '16 at 12:27




              1




              1





              Shorter variant: vim '+set syn=sql' -

              – Stéphane Chazelas
              Mar 10 '16 at 13:01







              Shorter variant: vim '+set syn=sql' -

              – Stéphane Chazelas
              Mar 10 '16 at 13:01






              5




              5





              Typically you're better off using set filetype=sql (or ft=sql for short); that will also load the indentation files and such and not just the syntax highlighting...

              – Martin Tournoij
              Mar 16 '16 at 7:11







              Typically you're better off using set filetype=sql (or ft=sql for short); that will also load the indentation files and such and not just the syntax highlighting...

              – Martin Tournoij
              Mar 16 '16 at 7:11















              1














              You can even automate that by putting the command into your ~/.vimrc:



              augroup filetype
              au! StdinReadPre * set filetype=sql
              augroup END





              share|improve this answer






























                1














                You can even automate that by putting the command into your ~/.vimrc:



                augroup filetype
                au! StdinReadPre * set filetype=sql
                augroup END





                share|improve this answer




























                  1












                  1








                  1







                  You can even automate that by putting the command into your ~/.vimrc:



                  augroup filetype
                  au! StdinReadPre * set filetype=sql
                  augroup END





                  share|improve this answer















                  You can even automate that by putting the command into your ~/.vimrc:



                  augroup filetype
                  au! StdinReadPre * set filetype=sql
                  augroup END






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 10 '16 at 12:16

























                  answered Mar 10 '16 at 12:07









                  MurphyMurphy

                  1,7861617




                  1,7861617























                      1














                      vim -R -c 'set ft=sql' -




                      • -R opens Vim in read-only mode. Your system may have the alias view for vim -R, but Neovim does not support it.


                      • set ft is short for set filetype. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.






                      share|improve this answer










                      New contributor




                      anishpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        1














                        vim -R -c 'set ft=sql' -




                        • -R opens Vim in read-only mode. Your system may have the alias view for vim -R, but Neovim does not support it.


                        • set ft is short for set filetype. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.






                        share|improve this answer










                        New contributor




                        anishpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          1












                          1








                          1







                          vim -R -c 'set ft=sql' -




                          • -R opens Vim in read-only mode. Your system may have the alias view for vim -R, but Neovim does not support it.


                          • set ft is short for set filetype. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.






                          share|improve this answer










                          New contributor




                          anishpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          vim -R -c 'set ft=sql' -




                          • -R opens Vim in read-only mode. Your system may have the alias view for vim -R, but Neovim does not support it.


                          • set ft is short for set filetype. As Martin Tournoij mentioned in his comment, setting the file type sets the syntax and more.







                          share|improve this answer










                          New contributor




                          anishpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer








                          edited 10 hours ago





















                          New contributor




                          anishpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 10 hours ago









                          anishpatelanishpatel

                          1135




                          1135




                          New contributor




                          anishpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          anishpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          anishpatel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • 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%2funix.stackexchange.com%2fquestions%2f268889%2fvim-force-specific-syntax-via-command-line-argument%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







                              Popular posts from this blog

                              Loup dans la culture

                              How to solve the problem of ntp “Unable to contact time server” from KDE?

                              ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux