I am cross-developing applications for a system that does not use a dot to separate file name from extension, but rather an underscore.
Is there a way to make Sublime Text detect this "_" separated extension as an indication of file type? Like have it detect
main_c
as a file type of "C" for syntax highlighting?
I know that I can set the file type manually, I also know that I can set a file type per file, but that's simply a work-around. I would like to have ST detect the type on its own.
Related
For i.e: I'd like to have a custom syntax file, may be called sugar.vim that includes multiple other syntax files(?) to have the ability to highlight, maybe a paragraph as python.vim and another paragraph as javascript.vim, may be separated by newline (paragraphs often distinct by newline)
The real case that I often catch myself writing a document (non-extension file) other than real config a specific filetype (specific extension file), but for clear readability in the document filetype (we called sugar above). I'm thinking about a mechanism to recognize and highlight different parts of a filetype as different syntaxes.
To narrow down this case. How would it be to have a syntax file called sugar.vim that would be able to recognize python syntax and javascript syntax in files that have an extension of .sugar then the recognized python text should have highlights applied as a normal python file, same for javascript part. All recognized text must be separated by newline (at least one before and one after that text)
Sample:
# this is a sample text for this question
# i'm writing a document that has an extension of `.sugar`
def py_func1(arg1, arg2) # python.vim and its highlights applied here.
print("bello world!")
square = function(x) { # javascript.vim and its highlights applied here.
return x * x;
};
System: gvim 8.1 / windows10
Thanks in advances.
Vim supports that with the :help :syn-include command. As it's intended for syntax script writers leveraging other syntaxes, its use is somewhat complicated, and it's not really suited for interactive, on-demand use.
My SyntaxRange plugin provides commands and functions to set up regions in the current buffer that either use a syntax different from the buffer's 'filetype', or completely ignore the syntax. With it, it's trivial to dynamically add a particular syntax highlighting for a range of lines, and public API functions also make the programmatic definition easier.
You're looking for :help :syn-include.
Excerpt from vim help :
If top-level syntax items in the included syntax file are to be
contained within a region in the including syntax, you can use the
":syntax include" command:
:sy[ntax] include [#{grouplist-name}] {file-name}
All syntax items declared in the included file will have the
"contained" flag added. In addition, if a group list is specified,
all top-level syntax items in the included file will be added to
that list. >
" In perl.vim:
:syntax include #Pod :p:h/pod.vim
:syntax region perlPOD start="^=head" end="^=cut" contains=#Pod
When {file-name} is an absolute path (starts with "/", "c:", "$VAR"
or "") that file is sourced. When it is a relative path
(e.g., "syntax/pod.vim") the file is searched for in 'runtimepath'.
All matching files are loaded. Using a relative path is
recommended, because it allows a user to replace the included file
with his own version, without replacing the file that does the ":syn
include".
As long as you can clearly define boundaries for your embedded language regions it is fairly straight forward to achieve this.
You can also refer to https://github.com/tpope/vim-markdown/blob/master/syntax/markdown.vim for reference on how tpope embeds other syntax definitions within the markdown syntax, driven by configuration to minimise the number of language syntax's that need embedding for optimal performance.
I have build_config (and other *_config files), GdbRun and build.txt files which are basically bash shell scripts.
How could I associate these files with shell syntax ? To place a pattern like
'if filename is *_config or GdbRun or build.txt' somewhere.
BufferScroll plugin can remember most of view settings for a particular file including syntax.
Just install BufferScroll and change the syntax manually using the status bar or the command palette and it'll remember it next time you open that file.
Vagrant files, for instance, contain code like this:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Is there a way to get Sublime to do something useful with this?
Sublime automatically chooses the syntax highlighting mode based on the file's extension. If you would like a certain extension to be associated with a particular language, just open the file, then choose View -> Syntax -> Open all with current extension as... and pick the language you'd like.
If you are working with files without an extension, or would just like finer-grained control, check out the ApplySyntax plugin. It allows you to define regexes based on file name and file contents, including shebang lines. It could very easily be modified in the settings to read Vim setting strings. It already includes a setting for Vagrantfile, so for your particular example you wouldn't need to modify anything.
When I type acroread and first couple of letters of the PDF I want to open and hit [Tab] it autocompletes the file name with the .pdf file. Even if there are other matching file names with the same starting letters as the ones i typed in but with different extensions like .ps. My C++ code accepts text file names with a custom extension .tk3 as input argument. how do I setup my code to do the same thing acroread does?
I just started using the spell checking feature in vim. According to the documentation, zg adds the current word to the first spellfile.
Is it recommended to create an own, empty spellfile, so that the English one doesn't get littered? If so: How do I create an empty spell list? An empty appropriately named file yields "E757: This does not look like a spell file".
Using your own additional spell files is both the recommended and default way of doing custom spelling. In Vim you have a 'root' spell file based on the current language and encoding, and an optional quantity of 'additional' spell files.
The easiest way to create an additional spell file (if you haven't already) is simply to add or remove a word using zg or zw - If 'spellfile' is empty, an new additional spell file will be created in the first writeable directory in 'runtimepath'.
The naming of spell files can be a bit tricky. Firstly, Vim takes a text file containing a list of words and converts it into a binary file which is a lot quicker to work with internally. The reason you're getting an error E757 is that Vim is attempting to load the binary spell file, but it's not finding the marker text at the start of the file, so it's bailing out.
To create your own spell files the filename needs to be in the format "mySpellFile.en.utf-8.add" where spelllang=en and encoding=utf-8.