1

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?

1

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.

  • 1
    I changed *.school_aliases to .*_aliases, and it worked perfectly for all my alias files. Thanks! – Kevin Feb 1 '18 at 20:21
  • Glad it worked out! – aliceinpalth Feb 2 '18 at 7:48
1

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.

  • 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 '18 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 '18 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.