Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 ?

share|improve this question
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 W. Mar 27 at 0:47
    
because when I open a .conf it open highlighting –  Guilherme Mar 27 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 W. Mar 27 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 at 1:13

2 Answers 2

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.

share|improve this answer
    
thanks juxiliary. –  Guilherme Mar 28 at 2:35

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)

share|improve this answer
    
thanks Thomas w. –  Guilherme Mar 28 at 2:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.