1

Essentially, what if I want the markdown color scheme for a file not ending in .md? Sometimes I create files conforming to the markdown standard, but they don't have a .md extension.

Ideally, this would be a single option I could pass when calling vim, but the manpage doesn't seem to say how this can be achieved.

  • 2
    What you are looking for is the filetype and not the colorscheme. The file type helps vim to parse the syntax in the file and decide which words should be highlighted with which group (like "command", "constant", "comment", "error", ...). The colorscheme tells vim which group should be displayed with which color on the terminal. – Lucas Jul 26 '18 at 16:12
  • @Lucas Oh wow. I guess the core concepts in vim are still a bit muddled in my head then. I understand what you are saying as: vim assigns a label to each character in a file (command, keyword, etc.), where these labels are assigned based on the filetype vim detects, but they are the same set of labels regardless of filetype. Then a "colorscheme" is a function from this set of labels into whatever colors can be displayed by the terminal. The characters themselves, the filetype (determining the labels) and the colorscheme determine what's displayed. Could you please clarify if I'm wrong? – extremeaxe5 Jul 26 '18 at 18:23
  • I think you get it about right. I added some more info to my answer. – Lucas Jul 26 '18 at 19:58
3

You can execute :setfiletype markdown inside vim.

If you edit this file often and always want it to be recognized as markdown you can add a modeline to it. Put this like at the top or bottom of the file (yes it should be a HTML comment):

<!-- vim: set ft=markdown: -->

Background:

In order to understand more about these concepts you can read

Short overview:

The whole concept roughly works like this:

  • vim detects the filetype of a file, either from the extension of the file, from its contents or from a modeline in the file
  • based on the filetype a syntax file can (automatically) be sourced, this will define which part of your text belongs to what group (like if it is a command, a number, a string a comment and so on)
  • the different syntax groups can get different colors (and other display attributes) assigned to them by the colorscheme

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.