0

I'm programming Bash scripts using Vim in Ubuntu 16.04 (on Windows Subsystem for Linux).

The filename ends in .sh and the first line of the file is

#!/bin/bash

When I wrote this command

rm -rf /tmp/*
   ~~~

The "word" -rf is shown in red (I use underlying tildes to point it out). I guess it's because Vim detected that -rm is a dangerous option when supplied to rm.

Later I wrote this:

tmpDir=$(mktemp "tmp-XXXXXX")
          ~~~~~~

and Vim confusingly marked mktemp as red.

image

Why is that? Can I stop Vim from marking this very word as red?

1

First, -rf is shown in red because it is recognized as an option, and red is the default color for the shOption syntax group.

mktemp is colored red because it is recognized as a shCommandSub. Bash commands will typically be colored differently here. You should notice that most things written in $(...) will be colored red, except strings, bash commands, and probably some more things.

You can see the syntax group(s) of the word under the cursor with this:

:echo reverse(map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")'))

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.