vim red highlight $( )

vim red highlight $( )

I was writing a script when I decided to move the functions to a lib file, but when I open the lib file all the $( and the consecutive ) are red highlighted, here are some examples of the script
TAB=”$(printf ‘\t’)”
percent=$(echo “scale=2; $number/$total*100” | bc | sed -e ‘s/\.[[:digit:]]*//g’)
if [[ -z $(grep $site/post $max_lim) ]];then

The filetype is conf but I’ve set it as sh syntax in .vimrc
Any idea of what is happenning?
Thank you

Edit: Thanks for the quick answers, I found that this line makes vim match the files with the extension specified behind the * with the syntax sh
au BufReadPost * set syntax=sh

I’ve also thought that using shebang in the libraries was not allowed, but is a nice solution
Anyway using g:is_bash in .vimrc returns an error of pattern not found
So what I would like to do is as I only write in bash, to vim recognize any file without extension as bash

Solutions/Answers:

Solution 1:

The syntax file for sh actually handles several different kinds of shell syntax: bash, ksh, and plain old sh. Since your conf file isn’t recognized as bash or ksh, it falls back to sh. $(...) isn’t a valid construct in sh, so it is highlighted as an error.

To fix this, you can make sure “g:is_bash” is set for the file, so that the sh syntax script will know your file should be highlighted as bash code. Please edit your question to include what you added to your .vimrc to make the file use sh syntax highlighting. This will make it easier to suggest the correct way of setting “g:is_bash”.

Related:  Resolving IBus Issue - IBus prior to 1.5.11 may cause input problems

UPDATE: As Alok commented, you should be able to add the following to the file

#!/bin/bash

to let vim know the correct syntax highlighting to use as well.

References