You are not logged in.

#1 2023-12-22 13:04:41

sg4rb0sss
Member
Registered: 2023-12-22
Posts: 1

Syntax Highlighting Issue in Vim

In Vim I'm trying to make it so that my text filetype is using the same highlighting colours I've configured for conf file types.  The .vimrc file config below specifically only seems to work with conf files, and changes my comment colour to light blue.  But when I open this up in my gnome terminal, the comments are not changing to that same colour specifically for the text filetype files (they are white). 


    $ cat .vimrc
   
    set textwidth=72
    autocmd FileType conf highlight Comment ctermfg=50
    autocmd FileType text highlight Comment ctermfg=50
    colorscheme default
    syntax enable

This makes me think there is something wrong with vim not having some config file available for the text filetype (some text.vim file must be missing from the installation).  With some digging, I found that if I copy the conf.vim file to text.vim solves the issue.

$ sudo cp /usr/share/vim/vim90/syntax/conf.vim /usr/share/vim/vim90/syntax/text.vim

The question is, is this the right approach?  I'm not entirely sure this wouldn't get erased on an update.  I mean it works, but I just don't know if that's the correct way to solve the problem (or why the text.vim file would be missing from a default install of vim)?

Last edited by sg4rb0sss (2023-12-22 13:07:24)

Offline

#2 2023-12-22 14:08:20

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,048

Re: Syntax Highlighting Issue in Vim

syntax != filetype, https://stackoverflow.com/questions/271 … tax-in-vim

https://vim.fandom.com/wiki/Filetype.vim#File_locations
=> /usr/share/vim/vim90/ftplugin/text.vim

There's no "text" syntax, because it's unstrucured "text", what would you highlight there itfp.
What is a comment in your "text"?

Offline

#3 2023-12-22 14:56:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,462
Website

Re: Syntax Highlighting Issue in Vim

To elaborate a bit on the above, to get vim to colorize a bit of text two things need to happen 1) that bit of text needs to be linked to a highlight group (e.g., defining that lines starting with a '#' are to be in the 'Comment' group), and 2) each highlight group must be assigned a color (and / or fontweight, etc).

The "conf" filetype definition takes care of the first of these for you which is why you can successfully just do the second by assigning color 50 to "Comment".  But there is no definition of "Comment" for plain text files.  You can add one if you want, but that's up to you.

Last edited by Trilby (2023-12-22 14:58:38)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB