Question

The "matchit" plugin for vim is supposed to allow you to use the % key to jump between matching start/end tags when editing HTML, as well as /* and */ comment delimiters when editing other kinds of code.

I've followed the exact instructions in ":help matchit", but % still doesn't work for me.

It seems silly to ask "Why doesn't this work?" so instead I'm asking How can I diagnose the problem? Pointers to references are welcome, but specific vim-plugin-debugging techniques are preferred.

Here is the ~/.vim directory:

$ ls -ltaGR ~/.vim
/cygdrive/y/.vim:
total 0
drwxr-xr-x 1 spause 0 Sep 17 13:20 ..
drwxr-xr-x 1 spause 0 Sep 16 13:59 doc
drwxr-xr-x 1 spause 0 Sep 16 13:58 .
drwxr-xr-x 1 spause 0 Sep 16 13:58 plugin

/cygdrive/y/.vim/doc:
total 24
-rw-r--r-- 1 spause  1961 Sep 16 13:59 tags
drwxr-xr-x 1 spause     0 Sep 16 13:59 .
-rw-r--r-- 1 spause 19303 Sep 16 13:58 matchit.txt
drwxr-xr-x 1 spause     0 Sep 16 13:58 ..

/cygdrive/y/.vim/plugin:
total 32
drwxr-xr-x 1 spause     0 Sep 16 13:58 ..
-rw-r--r-- 1 spause 30714 Sep 16 13:58 matchit.vim
drwxr-xr-x 1 spause     0 Sep 16 13:58 .

I am running vim 7.2 under Cygwin (installed Fall 2008). cygcheck shows:

1829k 2008/06/12 C:\cygwin\bin\cygwin1.dll
Cygwin DLL version info:
    DLL version: 1.5.25
    DLL epoch: 19
    DLL bad signal mask: 19005
    DLL old termios: 5
    DLL malloc env: 28
    API major: 0
    API minor: 156
    Shared data: 4
    DLL identifier: cygwin1
    Mount registry: 2
    Cygnus registry name: Cygnus Solutions
    Cygwin registry name: Cygwin
    Program options name: Program Options
    Cygwin mount registry name: mounts v2
    Cygdrive flags: cygdrive flags
    Cygdrive prefix: cygdrive prefix
    Cygdrive default prefix:
    Build date: Thu Jun 12 19:34:46 CEST 2008
    CVS tag: cr-0x5f1
    Shared id: cygwin1S4

In vim, :set shows:

--- Options ---
  autoindent          fileformat=dos      shiftwidth=3
  background=dark     filetype=html       syntax=html
  cedit=^F            scroll=24           tabstop=3
  expandtab           shelltemp           textmode
  viminfo='20,<50,s10,h

Notably, the syntax and filetype are both recognized as HTML. (The syntax colouring is just fine.)

If additional info is needed, please comment.

UPDATE:

Per answer by too much php:

After trying vim -V1, I had changed my .vimrc to include a line

set nocp

so the compatible option is not on.

:let loadad_matchit

loaded_matchit        #1

:set runtimepath?

runtimepath=~/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim72,/usr/share/vim/vimfiles/after,~/.vim/after

(~ is /cygdrive/y)

Per answer by michael:

:scriptnames

  1: /cygdrive/y/.vimrc
  2: /usr/share/vim/vim72/syntax/syntax.vim
  3: /usr/share/vim/vim72/syntax/synload.vim
  4: /usr/share/vim/vim72/syntax/syncolor.vim
  5: /usr/share/vim/vim72/filetype.vim
  6: /usr/share/vim/vim72/colors/evening.vim
  7: /cygdrive/y/.vim/plugin/matchit.vim
  8: /cygdrive/y/.vim/plugin/python_match.vim
  9: /usr/share/vim/vim72/plugin/getscriptPlugin.vim
 10: /usr/share/vim/vim72/plugin/gzip.vim
 11: /usr/share/vim/vim72/plugin/matchparen.vim
 12: /usr/share/vim/vim72/plugin/netrwPlugin.vim
 13: /usr/share/vim/vim72/plugin/rrhelper.vim
 14: /usr/share/vim/vim72/plugin/spellfile.vim
 15: /usr/share/vim/vim72/plugin/tarPlugin.vim
 16: /usr/share/vim/vim72/plugin/tohtml.vim
 17: /usr/share/vim/vim72/plugin/vimballPlugin.vim
 18: /usr/share/vim/vim72/plugin/zipPlugin.vim
 19: /usr/share/vim/vim72/syntax/html.vim
 20: /usr/share/vim/vim72/syntax/javascript.vim
 21: /usr/share/vim/vim72/syntax/vb.vim
 22: /usr/share/vim/vim72/syntax/css.vim

Note that matchit.vim, html.vim, tohtml.vim, css.vim, and javascript.vim are all present.

:echo b:match_words

E121: Undefined variable: b:match_words
E15: Invalid expression: b:match_words

Hm, this looks highly relevant. I'm now looking through :help matchit-debug to find out how to fix b:match_words.

Was it helpful?

Solution

Thanks to this posting from the vim_use mailing list, I found a sequence of commands that works:

vim -u NONE somefile.html

(this starts vim without reading .vimrc)

Then,

:set nocp
:source /usr/share/vim/vim72/macros/matchit.vim
:filetype plugin on
:filetype detect
:syntax on

It's not ideal, but it doesn't seem to work from .vimrc. And it doesn't work when syntax on precedes the filetype detection, so I suspect there's a conflict in the interaction between the syntax highlighting stuff and matching stuff.

OTHER TIPS

Use the following command to see if the plugin was loaded:

:let loaded_matchit

If you get an undefined variable error, then the plugin was not loaded - you should make sure that '/cygdrive/y/.vim' is in your 'runtimepath' option (use ':set runtimepath?')

Also note that the matchit plugin does not load if the 'compatible' option is turned on.

You might want to read through :he matchit . The section on configuration might help.

:he matchit-debug - debugging info specific to matchit

:he debug - general vim debugging (you can do all sorts of breakpoint/step through stuff)

A common gotcha (not your case though) is the html filetype can be nicked if you are using a template plugin. (Eg. my html is turned into html.djangotemplate) Try :set ft? to find your filetype. you might need to copy b:match_words into the ftplugin for the template filetype.

:echo b:match_words - should give a list of html looking regex's

also in case of the obvious :scriptnames should show matchit.vim somewhere

Good Luck

I have no clue about vim (besides using it a lot), but I found that putting the followng two lines in my .vimrc helped a lot:

:source /usr/share/vim/addons/plugin/matchit.vim
:source /usr/share/vim/vim72/ftplugin/html.vim

I am sure that there is a proper way, but at least this worked for me.

Cheers,

Joerg

I got the commands above to work in my .vimrc by removing most of the other crap in ~/vim, such as ~/.vim/ftdetect and ~/.vim/ftplugin. Start with a clean ~/.vim and only copy in what's specific to you, avoiding anything that might have a newer version in $VIMRUNTIME, and it should work.

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