1

I have a markdown file with the .md extension as "Personal Note.md". I make a symbolik (soft) link of it by ln -s command in Linux as "Note". I open the link with , it successfully traces the original file and opens it but doesn't highlight it, that is the markdown file format.

To note, it does highlight if I rename or create the link from the beginning with the extension .md, but that's no what I want to do, I don't want to add extension to the created link to keep it shorter and neutral in the user's eye.

2

This is tricky since in this situation you prefer not to have an extension on your symlink, and there's no reliable way that I know of to automatically detect a markdown file based on its syntax (since it is after all intended to be human-readable without rendering), so ftdetect is out of the picture. However, you do have some options.

If you tend to make similarly named symlinks to Markdown files, you can add an autocommand to set the filetype for you when reading these files:

" Your autocmds should be defined inside a group and cleared at the start so
" that they are not defined more than once if you happen to re-source your vimrc.
" See http://learnvimscriptthehardway.stevelosh.com/chapters/14.html

augroup MyAutoCmds
  autocmd!

  " If you have other files that you always want to use Markdown syntax, add them
  " after 'Note' below, comma delimited. Some other ideas could be README, AUTHORS,
  " CONTRIBUTING, COPYING, etc
  autocmd BufNewFile,BufRead Note setf markdown
augroup END

Or, you can use a modeline. I do not believe that there is an official syntax for Markdown comments, but I've seen most support basic HTML comments. So you could append this to your Markdown file:

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

See :h modeline for the full details on this feature. N.B. this will not show up in the rendered Markdown, so long as the implementation supports comments, which most that I've seen do indeed.

1

I think unfortunately without the extension you will have to manually set the syntax-type to markdown

:set syn=markdown  
  • Also, this article appears to ask a similar question but I do not understand the answers: stackoverflow.com/questions/15371499/… – varlogtim Nov 21 '16 at 4:47
  • Thanks, but I know how and don't want to activate the highlighting manually. It's sad and unbelievable that there's no other way. I think vim should trace the original file and check for its extension and highlight accordingly by default or when the link lacks extensions. – user373230 Nov 21 '16 at 10:00
  • You should set the syntax by setting filetype instead. :set syn will only fire the Syntax autocommand event, and thus wont run anything else filetype-related that would normally, such as specific formatting settings, etc – ZeroKnight Nov 30 '16 at 7:02
0

I could achive that by putting in the first line of the (linked) file:

vim: ft=markdown

It's ugly, but does the job.

  • 1
    The modeline will appear as a giant header when the markdown is rendered. See the latter half of my answer to put the modeline in a comment that will actually not show up (in most Markdown implementations). – ZeroKnight Nov 30 '16 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy