Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
.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 '14 at 0:47
because when I open a .conf it open highlighting – Guilherme Mar 27 '14 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 '14 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 '14 at 1:13

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 '14 at 2:35

juxiliary's [username changed to: user148237] 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.

share|improve this answer

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 '14 at 2:52

Your Answer


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.