4

I have a doubt about vim,

I installed the editor on my ubuntu 13.10 and everything is ok.

but when I create a file ".txt, or .conf" the highlighting isn't enabled, I put "#" and " but not change color in the file

But when I open a file ".conf" the highlighting is enabled.

the syntax is ON

someone can help me ?

4
  • 1
    .txt is a plaintext file. And so is a .conf. What makes you think that there's supposed to be highlighting on those?
    – Thomas Ward
    Mar 27, 2014 at 0:47
  • because when I open a .conf it open highlighting
    – Guilherme
    Mar 27, 2014 at 0:52
  • There is no one .conf syntax, because it differs by program a lot of times. If you open in GEdit, or anything else which has syntax highlighting, unless there's a line at the beginning saying #!/bin/something or something which defines the syntax language, they usually don't highlight on .conf files. I just tested by doing vim znc.conf on my ZNC config file, and vim nginx.conf on my nginx conf file and there's 0 syntax highlighting, maybe you have a line at the beginning of the specific conf files that dictates the language/syntax to highlight with?
    – Thomas Ward
    Mar 27, 2014 at 1:09
  • My doubt is because when I open a file. conf it is on highlighting, and when I create a txt file. conf or. highlighting it does not get in
    – Guilherme
    Mar 27, 2014 at 1:13

3 Answers 3

11

The file ending .conf has no syntax set by default. Different configuration files have different syntax, so vim cannot use the same syntax for all .conf files. To handle this, vim looks at the whole file name and compares it to the patterns found in filetype.vim (located at /usr/share/vim/vim74/filetype.vim on my system)

For example, say you opened the file apache.conf, vim will look in filetype.vim until it finds something like:

       au BufNewFile,BufRead apache.conf*,apache2.conf* setfiletype apache

which tells vim to use the apache syntax highlighting file for any file that begins in apache.conf. Try creating a new file called apache.conf and you should get apache syntax highlighting for that file.

Another way vim can set the syntax for a file is with modelines. Modelines let you run vim commands for specific files. They can be found at the top or bottom of files and look something like this:

# vim: syntax=apache

For more info on modelines checkout :help modeline in vim.

0
6

juxiliary's answer is correct. I found that the easiest way to set this when you know you want this style is an abbreviated version of his answer:

:setf apache

You may want to mark his answer as correct.

0

Based on the comments, I think your question is "If I save a file, will it later have highlighting on". Until you save the file, unless you've added a line at the beginning of the file (such as #!/bin/bash), it won't have any highlighting. Highlighting is defined by the first line of the file, or by the file extension.

If there's special .conf highlighting, based on the filename pattern, it will show up when you next open the .conf file.

All .txt files are plain-text and don't have any syntax highlighting unless the file opens with #!/bin/bash or some other similar line.


TL;DR; the syntax highlighting is not saved with the file. It's determined internally with Vim, when the file is opened. (Or, if it's a new file, at first save)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .