gordon-quad
gordon-quad

Reputation: 734

Make vim close syntactic construction for code block automatically

Is there plug-in that makes vim close syntactic constructions that wraps code blocks automatically for any language based on data in indent and syntax files?

For example I editing lua file, when I write

function myfunction()

and press enter it automatically make an closing "end"

function myfunction()
    <cursor position>
end

Or maybe anyone can show an example how to write your own plug-in for specific language with long keywords for code blocks (like lua, erlang or pascal) ?

Upvotes: 2

Views: 461

Answers (2)

David Brown
David Brown

Reputation: 13526

I would use a snippet plugin like UltiSnips (my favorite) or Snipmate. They essentially expand some small word or piece of text into larger pieces of code and allow you to edit only the parts that are unique for each structure. Both UltiSnips and Snippmate include snippets for many languages and let you create your own snippets.

For example UltiSnips inclueds a function snippet for Lua. I just have to type out fun and then press tab and it gets expanded to

function new_function(args)

end

and new_fuctnion gets selected so I can edit the function name. Then once I press Ctrl-j (in my vimrc I rebind this to Tab) it selects the next part of the snippet which is args in this case allowing me to enter the function's arguments. A final Ctrl-j puts the cursor in the body of the function.

Upvotes: 3

Austin Taylor
Austin Taylor

Reputation: 5477

Endwise seems to be what you're looking for. It already has lua support, and it looks like it would be pretty easy to extend, if you are comfortable with VimL.

Upvotes: 3

Related Questions