Skip to content

Getting vim to match begin/end

The default vim has a matchpairs option which matches pairs of single bytes.

However, I have a file which has a lot of nested conditions, and the language requires begin/end pairs for multi-line conditionals. I know I have more begin statements than end statements. So, I need help from vim in matching these up.

As it turns out, there’s a matchit macro in $VIMRUNTIME/macros that lets you extend the % command to match more complex expressions (including regular expressions). It also exists here. Install instructions are included on the vim.org page. Basically, you unzip in your ~/.vim directory and then and run a helptags command.

Be the first to like.

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*