Which Syntax Highligting to use in vim for structurizr's DSL - vim

Structurizr, a tool that is recommended to design a c4model, comes with its own DSL. It looks a bit like this:
workspace {
model {
user = person "User"
softwareSystem = softwareSystem "Software System"
user -> softwareSystem "Uses"
}
views {
systemContext softwareSystem {
include *
autolayout
}
theme default
}
}
and the file extension is .dsl. Does anyone know which filetype you have to set in vim in order to get some syntax highlighting? It probably won't be a perfect match but maybe better than nothing. I'm asking, because if you put a file like this to github or gitlab you do get some syntax highlighting, but vim guesses the filetype as dsl and the highlighting does not show at all.

Since there was no proper syntax for structurizr available in vim, I ended up providing a dedicated one.

Related

How can you reformat C source code '{' placements in VIM?

I want to change the following code:
if (test)
{
statements;
}
else
{
statements;
}
To the following:
if (test) {
statements;
} else {
statements;
}
Using '=' doesn't do this function (as far as I can tell).
Is there any clever VIM command to do this?
You can play with regexes. Here, it will be:
:%s/\_s*{/ {/g
:%s/}\zs\_s*\ze\(else\|while\)/ /g
The secret is in /\_s which is like /\s (which matches spaces), but which also matches newlines.
If you also want to transform things like { return foo; }, you'll have to insert newlines as well, and then reindent everything.
:%s/\_s*{\_s*/ {\r/g
gg=G
You can also have a look at vim plugins that integrates tools like AStyle or clang-format which should give better results.
PS: lh-cpp and mu-template snippets have an option (through :AddStyle) that lets the end-user specify whether a newline shall be inserted or not. Sometimes, the better approach is to produce code that conforms to project style.

MacVim - edit color theme for javascript

I am using MacVim with the Cobalt theme. I found it very nice, however, coming from Sublime Text, I feel there aren't enough different colours which makes my javscript code hard to read.
For example, I'd like the function name to be coloured to make them stand out a bit more:
myClass.prototype.myFunction = function myFunction() {
// here, I'd like "myClass" to have a different color from the text
// same for "prototype" and "myFunction"
}
Another example is the use of methods:
myArray.pop();
// I'd like to change the color of ".pop()" for more visibility
How can I add these types of patterns?
A syntax script parses the programming language into different groups (which can be listed via :syntax list). A colorscheme then prescribes how to color and format each individual group.
So, if there are distinct groups, but your colorscheme just assigns the same color to it, that can be easily changed by putting
:hi link <syntaxGroup> <highlightGroup>
commands into your ~/.vimrc.
The detail of parsing depends on the language and syntax script. Extending an existing syntax (to parse out more details) is possible, but complex. For JavaScript, there exist some alternatives (like this) to the built-in syntax script; you might want to give those a try.
PS: :syn list shows all active groups, but it's easier when you install the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin.
I use the plugin vim-javascript-syntax.

Can you create templates in VIM with placeholders?

Can you create a template in VIM with placeholders, and then it would cycle through the placeholders so you can fill in the content.
If the placeholder was used elsewhere, that would automatically get filled in since you already provided a definition for that placeholder.
example:
public class $CLASSNAME$
{
public $CLASSNAME$
{
}
}
There are plenty of snippets plugins for vim. You could try snipmate or snippetsemu for example.
The vim plugin snipmate already does precisely what you want to do. (Take a look at the screencast)
Edit: Changed to active github repo of vim-snipmate (thanks Peter Rincker)

Is it possible to modify the cindent rules for one case in vim?

I am currently using vim as my editor for programming in D. The indent rules are pretty much identical to C, but I've run into a case that vim doesn't handle by default. In D, case statements can take strings which are not properly handled by cindent.
For instance, this works:
switch(blah)
{
case 1:
// something
case some_variable:
// ...
}
But not this:
switch(blah)
{
case "yark":
case "flurb":
// something
case "...":
// ...
}
Is there some way to override that single rule in a custom indent file, or would the entire cindent ruleset have to be reimplemented?
Try Vim 7.3. The indentation rules introduced in this version mainly for JavaScript also fix this particular situation.
With Vim 7.3 the code is correctly indented as:
switch(blah)
{
case "yark":
case "flurb":
// something
case "...":
// ...
}

Does vim provide tiered intellisense support through phpdoc?

The one thing I really miss in vim is a tiered intellisense support, just like we have one in PHP Eclipse.
For example:
/**
* Get the config object
*
* #return Config
*/
public function getConfig()
{
return $this->_config;
}
I find this explicit return type setting very useful and time saving feature.
Do we have something similar in vim?
Vim by itself doesn't really have any intellisense... Instead, it just provides autocompletion. This means that Vim isn't aware of language, types, etc. It just looks for strings that it can complete.
I'm not familiar with tiered intellisense, but you could try using the Vim Intellisense plugin. It does have language-specific completion and type-checking. It does not have direct support for PHP, but perhaps it will get you closer to your goal.
EDIT Using Vim's omnifunc, you can get function completion, but there is still no built-in type awareness.

Resources