Question

I'm writing a plugin for the dg language, what can I do to auto-indent when a line terminates with some specified symbols?

For example, if the line terminates with -> or ~> or => and I press Enter, then the cursor would go on a new line indented a level deeper. I guess I should put the code in the indent directory?

Was it helpful?

Solution

The built-in indent methods (cindent, autoindent, smartindent) won't suffice for a custom language. You need to write your own indent plugin, which would go into ~/.vim/indent/dg.vim.

Basically, you need to write a Vimscript function that examines the current (and previous) line(s) and determines the indent level from this. This function is then installed into 'indentexpr'. See :help indent-expression, which unfortunately only recommends to have a look at the existing indent scripts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top