Sublime Forum

ST3 setting default syntax for project

#1

Hello everyone,
I’m trying to set markdown as a default syntax for a project.
I’ve opened the project configuration with Project > Edit Project

but I can’t figure how to set it inside the config.

any clue?

0 Likes

#2

Can you be more specific as to what this means ? Syntax is set per file and not per project.

0 Likes

#3

I’ve got a documentation project, composed only by markdown files.

Inside this project I want that every time I create a new file the markdown syntax should be automatically selected, instead of the default plain text

0 Likes

#4

I feel the simplest way would be to use a key binding.

{
	"keys": ["ctrl+alt+3"],
	"command": "set_setting",
	"args": {
		"setting": "syntax",
		"value": "Packages/Markdown/Markdown.sublime-syntax"
	},
},

So whenever you create a new file via ctrl + n, you can press this key binding to set the markdown syntax and when saving, it would automatically default to the .md extension in the OS save dialog.

If you really want it automated, I believe making a custom plugin is the only way.

0 Likes

#5

Just as a note, applying the syntax setting directly will alter the syntax of the current buffer, but it won’t apply the syntax specific settings for the new syntax; for that you need a plugin that calls view.assign_syntax().

0 Likes

#6

That’s something new to me. Thanks.

0 Likes

#7

You may be able to get ApplySyntax to do that. I know you can set a default syntax for new files, but I’m not sure if you can set it in project-specific settings for just this project.

0 Likes

#8

And this is without using a plugin ? I mean ApplySyntax.

0 Likes

#9

Oh, sorry. It is a plugin, yes. OP just wouldn’t have to write their own.

0 Likes

#10

yeap, this could be my use case, since the project lives under a single path.

0 Likes

#11

Oh, okay. If that works, then awesome. I wasn’t sure what it would do with an unsaved buffer. (Maybe I misunderstood the problem.)

If that doesn’t work, you could try combining the New File Syntax with Project-Specific Rules. Something like

// my_markdown_project.sublime-project
{
    "settings": {
        "new_file_syntax": "Markdown/Markdown",
    },
}
2 Likes

#12

tried and tested, it works perfectly!

2 Likes