0

I'm new to vim and bash and something seems odd to me. I have two functions and they have a different highlighting, but I can't understand why. I searched through google, but I haven't found an answer to this specific problem.

Here's how the code looks like with syntax highlighting:

Functions

function unlock() {
    rm -f ${LOCKFILE}
    if [ -f ${LOCKFILE} ]; then
        echo "ERROR: Unable to delete lockfile ${LOCKFILE}!"
        exit 1
    fi
    echo_debug "lock file ${LOCKFILE} removed."
}

function copy_file() {
        #  scp -q -i "$RSA_FILE" -P "$NEXTCLOUD_SERVER_PORT" "$1" \
        #     "$NEXTCLOUD_SERVER_USER@$NEXTCLOUD_SERVER_HOST:$NEXTCLOUD_SERVER_DEST_DIR"
        echo "copy_file()"
}

I noticed that if I add another function named coFUNCTION() the highlighting changes to the one like copy_file(). Why is this the case?

Here's my .vimrc

1 set number
2 syntax on
3 :color desert
4
  • Can you try running :syntax sync fromstart? BTW, on my system, the highlighting is seen fine. Commented Sep 10, 2019 at 9:55
  • ran then command, but nothing changed. Commented Sep 10, 2019 at 9:57
  • 1
    What is the file type detected? Use :set filetype?.. good to enable the ft plugin "set filetype=on" Commented Sep 10, 2019 at 9:59
  • @SamDaniel, Actually, set filetype=sh. Commented Sep 10, 2019 at 10:01

1 Answer 1

3

sh != bash, and the function keyword is a bashism. So it's entirely possible the syntax highlighting is correct, except it's been applied to the wrong language. You can simply remove the function keyword to get closer to POSIX syntax, that might help the highlighting code. Or, depending on how the highlighting code works you might have more luck adding a shebang line or changing the script extension from "sh" to "bash".

Sign up to request clarification or add additional context in comments.

1 Comment

Further info about useless function keyword here... wiki-dev.bash-hackers.org/scripting/obsolete

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.