vim syntax highlight not working (MacOs Ventura)

548 Views Asked by At

I use vim as my text editor, and I want to make use of highlighted syntax. However, I cannot get it to work when I use the command “syntax on” in my ~/.vimrc file.

The strange thing is that it does the syntax is highlighted in the ~/.vimrc file itself, but not in other files.

When I use the command “syntax on” in my ~/.vimrc file, it does highlight the text in the ~/.vimrc file itself, but not in other files. If I provide other commands in the ~/.vimrc file they work: colorscheme wors, set number also works. So the ~/.vimrc file itself is actually used and works correctly, only the “syntax on” command does not work.

Anybody who can help me with this?

Thanks in advance!

1

There are 1 best solutions below

1
On BEST ANSWER

I have found the issue. Beginners mistake I guess...

As mentioned the comments, in the .vimrc file syntax highlighting worked fine. In the files I made myself, I just opened a file without extension (i.e. vim testfile).

In a file without extension, the syntax highlighting does not work because vim does not know how to highlight the syntax. When I now for instance open a file vim testfile.py (with the Python extension), it works fine.

Thanks anyway for your comments!