jumping to corresponding syntax element

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

jumping to corresponding syntax element

Gergely Buday
Hi,

the percent sign makes vi jump to the corresponding closing
parenthesis, should I point to the opening one.

How can I program a similar functionality for other classes of
syntactical elements? In Standard ML, there is a let - in - end
construct that can span several pages so it would be useful to jump
from one let to the corresponding end. Of course a let-in-end triple
can be found in another.

Is there a way to program this in vi?

- Gergely

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: jumping to corresponding syntax element

Taylor Hedberg
The matchit plugin (which is bundled with most versions of Vim) can do
this. You will need to have the variable b:match_words defined in
Standard ML buffers (this can be done with an autocommand or filetype
plugin).

For instance, something like:

    let b:match_words = '\<let\>:\<in\>:\<end\>'

would do what you're asking for in a simple case, though you may want to
make it more sophisticated than that depending on the specifics of the
language syntax.

See `:help matchit` and `:help matchit-newlang` for more details.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: jumping to corresponding syntax element

Tony Mechelynck
In reply to this post by Gergely Buday
On 13/10/11 10:12, Gergely Buday wrote:

> Hi,
>
> the percent sign makes vi jump to the corresponding closing
> parenthesis, should I point to the opening one.
>
> How can I program a similar functionality for other classes of
> syntactical elements? In Standard ML, there is a let - in - end
> construct that can span several pages so it would be useful to jump
> from one let to the corresponding end. Of course a let-in-end triple
> can be found in another.
>
> Is there a way to program this in vi?
>
> - Gergely
>

1. Enable the matchit plugin, see :help matchit-install
    1.1 Create the directory $VIM/vimfiles/plugin if it doesn't exist,
and place in it a one-line file containing just

        runtime macros/matchit.vim

You can name it matchit.vim

    1.2 On Unix/Linux, you can enable the matchit help via a softlink:

        :shell
        mkdir -pv $VIM/vimfiles/doc
        cd $VIM/vimfiles/doc
        ln -sv ../../vim73/macros/matchit.txt
        exit
        :helptags $VIM/vimfiles/doc

        On Windows, you may have to copy the matchit.txt file from
$VIMRUNTIME/macros to $VIM/vimfiles/doc/. The :helptags command (as
above) is still necessary so that the help entries in the file will be
made part of Vim's help system.

2. If the ftplugin for StandardML doesn't already set the b:match_words
variable, you can set it in an after-plugin, named (for instance)
$VIM/vimfiles/after/ftplugin/standardml.vim (if "standardml" is the
'filetype' value for those files). For details, see :help
matchit-newlang (after installing the matchit help as above).

3. In order not to lose the "standard" function of the % key for files
which have no specific syntax pairings, I recommend adding the following
in your vimrc:

        augroup vimrclocal
                au FileType c,cpp,css,javascript
                        \ let b:match_words = &matchpairs
        augroup END

This will also avoid %-jumping from ( or ) in a comment to ) or ( in the
code or vice-versa (likewise for []{}).


Best regards,
Tony.
--
"In any world menu, Canada must be considered the vichyssoise of
nations -- it's cold, half-French, and difficult to stir."
                -- Stuart Keate

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php