I'm writing a lot of RST lately and I would like the %
keystroke to match between grave accent (i.e. backtick) characters.
`The cursor is at the |vertical line`
and then hitting %
moves the cursor as shown
`The cursor is at the vertical line|`
I have tried setting the b:match_words
for the matchit
plugin but that doesn't help.
Any tips appreciated.
Forgive me for tooting my own horn, but I am an expert on the matchit plugin.
Although it is designed to extend the built-in matching functionality, matchit extends it in several ways. For one, it allows you to match regular expressions, not just single characters. You can get very good results by using vim's start-of-word and end-of-word patterns:
:let b:match_words='`\<:\>`'
This certainly works on the one-line example you gave. Similarly, you might decide that the starting ` usually does not have a non-whitespace character before it, and the closing one is not followed by a non-whitespace character. (If that is too many negatives, then "This is markup" usually starts a new line or follows a space or tab; and it is usually followed by the end of a line or a space or tab.) Then you could use
:let b:match_words='\S\@<!`:`\S\@!'
The matchit plugin tries to live up to vim's design goals, including :help design-documented
. The standard vim distribution includes both matchit.vim
(the script) and matchit.txt
in $VIMRUNTIME/macros/
. You can either read the documentation there or follow the instructions at :help matchit-install
and browse the documentation with :help
.
Under :help b:match_words
, it says,
Tips: Be careful that your initial pattern does not match your final pattern.
This is because, when you bang on the % key, the script has to be able to figure out whether it is on the starting pattern or the ending pattern. The only information it has to make this decision is what you have told it in b:match_words
.