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
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?
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
The syntax file for
sh actually handles several different kinds of shell syntax:
ksh, and plain old
sh. Since your conf file isn’t recognized as
ksh, it falls back to
$(...) 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”.
UPDATE: As Alok commented, you should be able to add the following to the file
vim know the correct syntax highlighting to use as well.
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Ebook Reviews
- PES Matches, Skills & News