5

I'm troubleshooting syntax highlighting in my .vimrc settings.

My setup is a little complex because I have some filetype settings for plain text and other settings for programming files (using filename extension handlers). It's all very well organized.

The problem is even my text only files have syntax highlighting, and I only noticed when I changed to a new colorscheme. Random words are highlighted in text file. Programming files are OK.

Help me find the settings I should check, What are all of the global mechanisms for highlighting text?

I'm thinking I need to reorder these settings, so I keep highlighting in code and remove highlighting from text.

  • What does :set ft? show for these text files with highlighting? Ideally the result should be empty for plain text. What kind of text is getting highlighted? – B Layer Aug 4 '17 at 17:04
  • filetype= so, empty. One example is vim made file named RadioLab_2016-11-05 and the contents start: RadioLab_2016-11-05 \r [...] Mel Blanc was known as the man of a 1,000 voices [...] Bugs Bunny, Porkey Pig, Tweety, [...] Dr. Conway and NYU brain scientist Orrin... In the original 20 line quote, the following words are highlighted {RadioLab, Tweety, NYU, Orrin} – xtian Aug 4 '17 at 18:03
  • 1
    Are the colors all the same? It's not bad spelling is it? :) Just spitballin here but with an empty file type, if you do :hi are you able to match some of the text coloring to one or more highlight groups? Or does a matched highlight group give any clue as to why it's applied? That's just some more poking and prodding you could try until/if/when someone shows up with an easy answer. ;) – B Layer Aug 4 '17 at 21:06
  • That's a great question! I tested the comment mentioned file with <kbd>[</kbd> + <kbd>s<kbd> and it jumped between all the highlighted words. I forgot there are several different spelling highlights. They're not incorrectly spelled, but they are suspected candidates. @BLayer--if you add the spelling note to your answer I will mark it correct. Thanks. – xtian Aug 4 '17 at 23:31
  • Cool. Glad we figured it out. I updated my answer. – B Layer Aug 5 '17 at 7:17
4

:help syntax-loading has detailed description of how syntax gets set up. For instance this section on file loading:

Loading the file triggers the BufReadPost autocommands.
|
+-  If there is a match with one of the autocommands from |synload-3|
|   (known file types) or |synload-4| (user's file types), the 'filetype'
|   option is set to the file type.
|
+-  The autocommand at |synload-5| is triggered.  If the file type was not
|   found yet, then scripts.vim is searched for in 'runtimepath'.  This
|   should always load $VIMRUNTIME/scripts.vim, which does the following.
|   |
|   +-  Source the user's optional file, from the *myscriptsfile*
|   |   variable.  This is for backwards compatibility with Vim 5.x only.
|   |
|   +-  If the file type is still unknown, check the contents of the file,
|       again with checks like "getline(1) =~ pattern" as to whether the
|       file type can be recognized, and set 'filetype'.
|
+-  When the file type was determined and 'filetype' was set, this
|   triggers the FileType autocommand |synload-6| above.  It sets
|   'syntax' to the determined file type.
|
+-  When the 'syntax' option was set above, this triggers an autocommand
|   from |synload-1| (and |synload-2|).  This find the main syntax file in
|   'runtimepath', with this command:
|       runtime! syntax/<name>.vim
|
+-  Any other user installed FileType or Syntax autocommands are
triggered.  This can be used to change the highlighting for a specific
syntax.

Perhaps you can piece things together by going through this.

Edit: Moving the winning idea from a comment to here...

As for a more concrete idea, if you do :hi you can try to match the text colors with a syntax group and see if that gives you some clues. First thing that comes to mind as far as coloring of plain text is search or incremental search. The next one that comes to mind is spelling errors or warnings. (If it's spelling that can be checked by simply doing typing ]s and seeing if the cursor moves to a highlighted word.)

  • Just to be clear, the above comment example doesn't have a filetype and that's OK. It's just a text file. This description seems to be focused on triggering the correct responses when the filetype is found. But in the first case, I want to be sure to clear all syntax commands from triggering for None type files. – xtian Aug 4 '17 at 18:37

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.