Setting Vim to use shell syntax for dotfiles?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I am creating multiple files (.school_aliases and .git_aliases) to put my aliases in for organization. However, Vim doesn't highlight syntax for these files automatically like for .bashrc or .bash_aliases. Is there a way I could get Vim to do this automatically rather than just doing set syntax=sh?







share|improve this question
























    up vote
    1
    down vote

    favorite












    I am creating multiple files (.school_aliases and .git_aliases) to put my aliases in for organization. However, Vim doesn't highlight syntax for these files automatically like for .bashrc or .bash_aliases. Is there a way I could get Vim to do this automatically rather than just doing set syntax=sh?







    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am creating multiple files (.school_aliases and .git_aliases) to put my aliases in for organization. However, Vim doesn't highlight syntax for these files automatically like for .bashrc or .bash_aliases. Is there a way I could get Vim to do this automatically rather than just doing set syntax=sh?







      share|improve this question












      I am creating multiple files (.school_aliases and .git_aliases) to put my aliases in for organization. However, Vim doesn't highlight syntax for these files automatically like for .bashrc or .bash_aliases. Is there a way I could get Vim to do this automatically rather than just doing set syntax=sh?









      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 1 at 19:40









      Kevin

      11016




      11016




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You can use the following in your .vimrc:



          autocmd BufNewFile,BufRead *.school_aliases,*.git_aliases set syntax=sh


          Or, you can set these file extensions to syntax types in ~/.vim/filetype.vim.






          share|improve this answer
















          • 1




            I changed *.school_aliases to .*_aliases, and it worked perfectly for all my alias files. Thanks!
            – Kevin
            Feb 1 at 20:21










          • Glad it worked out!
            – aliceinpalth
            Feb 2 at 7:48

















          up vote
          1
          down vote













          Add to each of the files a line, thus:



          # vim:syntax=sh filetype=sh


          This line is a comment to your shell(s) (as it starts with #), but vim will see it and understand that it should interpret the file as a shell script for the purposes of syntax highlighting et cetera, even though the filename does not end with .sh.






          share|improve this answer




















          • This seems like it's working, but my color scheme doesn't apply as it would when I manually do set syntax=sh...
            – Kevin
            Feb 1 at 20:09










          • That's highly unusual. You can set more things on that line if you wish to manually set the color scheme though (e. g. colorscheme=darkblue).
            – DopeGhoti
            Feb 1 at 20:10










          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f421279%2fsetting-vim-to-use-shell-syntax-for-dotfiles%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You can use the following in your .vimrc:



          autocmd BufNewFile,BufRead *.school_aliases,*.git_aliases set syntax=sh


          Or, you can set these file extensions to syntax types in ~/.vim/filetype.vim.






          share|improve this answer
















          • 1




            I changed *.school_aliases to .*_aliases, and it worked perfectly for all my alias files. Thanks!
            – Kevin
            Feb 1 at 20:21










          • Glad it worked out!
            – aliceinpalth
            Feb 2 at 7:48














          up vote
          1
          down vote



          accepted










          You can use the following in your .vimrc:



          autocmd BufNewFile,BufRead *.school_aliases,*.git_aliases set syntax=sh


          Or, you can set these file extensions to syntax types in ~/.vim/filetype.vim.






          share|improve this answer
















          • 1




            I changed *.school_aliases to .*_aliases, and it worked perfectly for all my alias files. Thanks!
            – Kevin
            Feb 1 at 20:21










          • Glad it worked out!
            – aliceinpalth
            Feb 2 at 7:48












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You can use the following in your .vimrc:



          autocmd BufNewFile,BufRead *.school_aliases,*.git_aliases set syntax=sh


          Or, you can set these file extensions to syntax types in ~/.vim/filetype.vim.






          share|improve this answer












          You can use the following in your .vimrc:



          autocmd BufNewFile,BufRead *.school_aliases,*.git_aliases set syntax=sh


          Or, you can set these file extensions to syntax types in ~/.vim/filetype.vim.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 1 at 19:58









          aliceinpalth

          760116




          760116







          • 1




            I changed *.school_aliases to .*_aliases, and it worked perfectly for all my alias files. Thanks!
            – Kevin
            Feb 1 at 20:21










          • Glad it worked out!
            – aliceinpalth
            Feb 2 at 7:48












          • 1




            I changed *.school_aliases to .*_aliases, and it worked perfectly for all my alias files. Thanks!
            – Kevin
            Feb 1 at 20:21










          • Glad it worked out!
            – aliceinpalth
            Feb 2 at 7:48







          1




          1




          I changed *.school_aliases to .*_aliases, and it worked perfectly for all my alias files. Thanks!
          – Kevin
          Feb 1 at 20:21




          I changed *.school_aliases to .*_aliases, and it worked perfectly for all my alias files. Thanks!
          – Kevin
          Feb 1 at 20:21












          Glad it worked out!
          – aliceinpalth
          Feb 2 at 7:48




          Glad it worked out!
          – aliceinpalth
          Feb 2 at 7:48












          up vote
          1
          down vote













          Add to each of the files a line, thus:



          # vim:syntax=sh filetype=sh


          This line is a comment to your shell(s) (as it starts with #), but vim will see it and understand that it should interpret the file as a shell script for the purposes of syntax highlighting et cetera, even though the filename does not end with .sh.






          share|improve this answer




















          • This seems like it's working, but my color scheme doesn't apply as it would when I manually do set syntax=sh...
            – Kevin
            Feb 1 at 20:09










          • That's highly unusual. You can set more things on that line if you wish to manually set the color scheme though (e. g. colorscheme=darkblue).
            – DopeGhoti
            Feb 1 at 20:10














          up vote
          1
          down vote













          Add to each of the files a line, thus:



          # vim:syntax=sh filetype=sh


          This line is a comment to your shell(s) (as it starts with #), but vim will see it and understand that it should interpret the file as a shell script for the purposes of syntax highlighting et cetera, even though the filename does not end with .sh.






          share|improve this answer




















          • This seems like it's working, but my color scheme doesn't apply as it would when I manually do set syntax=sh...
            – Kevin
            Feb 1 at 20:09










          • That's highly unusual. You can set more things on that line if you wish to manually set the color scheme though (e. g. colorscheme=darkblue).
            – DopeGhoti
            Feb 1 at 20:10












          up vote
          1
          down vote










          up vote
          1
          down vote









          Add to each of the files a line, thus:



          # vim:syntax=sh filetype=sh


          This line is a comment to your shell(s) (as it starts with #), but vim will see it and understand that it should interpret the file as a shell script for the purposes of syntax highlighting et cetera, even though the filename does not end with .sh.






          share|improve this answer












          Add to each of the files a line, thus:



          # vim:syntax=sh filetype=sh


          This line is a comment to your shell(s) (as it starts with #), but vim will see it and understand that it should interpret the file as a shell script for the purposes of syntax highlighting et cetera, even though the filename does not end with .sh.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 1 at 20:02









          DopeGhoti

          40.4k54779




          40.4k54779











          • This seems like it's working, but my color scheme doesn't apply as it would when I manually do set syntax=sh...
            – Kevin
            Feb 1 at 20:09










          • That's highly unusual. You can set more things on that line if you wish to manually set the color scheme though (e. g. colorscheme=darkblue).
            – DopeGhoti
            Feb 1 at 20:10
















          • This seems like it's working, but my color scheme doesn't apply as it would when I manually do set syntax=sh...
            – Kevin
            Feb 1 at 20:09










          • That's highly unusual. You can set more things on that line if you wish to manually set the color scheme though (e. g. colorscheme=darkblue).
            – DopeGhoti
            Feb 1 at 20:10















          This seems like it's working, but my color scheme doesn't apply as it would when I manually do set syntax=sh...
          – Kevin
          Feb 1 at 20:09




          This seems like it's working, but my color scheme doesn't apply as it would when I manually do set syntax=sh...
          – Kevin
          Feb 1 at 20:09












          That's highly unusual. You can set more things on that line if you wish to manually set the color scheme though (e. g. colorscheme=darkblue).
          – DopeGhoti
          Feb 1 at 20:10




          That's highly unusual. You can set more things on that line if you wish to manually set the color scheme though (e. g. colorscheme=darkblue).
          – DopeGhoti
          Feb 1 at 20:10












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f421279%2fsetting-vim-to-use-shell-syntax-for-dotfiles%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)