Tuesday, July 29, 2014

linux - Apply full vim colorization for bash scripts that have no shebang line


So in my project there are many bash script files that are sourced, but never run directly, so they get no shebang line and no execute bit set. Vim colors them a little bit, but doesn't use the full colorization. How do I tweak vim to give me all the normal bash colors for these files?


EDIT:


Without shebang:


Without shebang


With shebang:


With shebang


EDIT 2:


There is an answer that works for file-by-file changes below, and I'll go with that if that's all I can get, but what I'd really like is to modify a config file or something else in my vim installation so that I always get the full "with shebang" colors even when there is no shebang. There must be a file somewhere that defines the incomplete colorization, which I can just replace with the file defining the complete colorization.


EDIT 3:


The vim global variables set are not substantially different, as seen in these images (output of :let g:):


Environments


Diffed


I'm sort of at a loss here.


EDIT 4:


I dumped the entire environment from a properly-colored window (left) and an improperly-colored window (right), and diffed them, finding this:


60 b:current_syntax       bash   |   61 b:current_syntax       conf

So, for some reason it thinks my shebangless source files are conf files. So I need to figure out how to match them to bash instead.


Answer



Run :setf sh


You may want to place this at the top of the files (if you want no shebang):


# vim:ft=sh

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...