3

I'm trying to have the command

    let b:match_words='<:>,<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'

run every time I open an html file. I tried putting the line

    autocmd FileType html let b:match_words='<:>,<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'

in a file named html.vim in both my ftdetect and ftplugin folders and nothing happened. How do I have the command run everytime I'mm in an html file?

The command is to change the matching behavior of matchit btw.

1

1 Answer 1

5

In general, your autocmd is alright; the problem is that you're trying to redefine the b:match_words definition done in $VIMRUNTIME/ftplugin/html.vim, so the execution order becomes important.

The place for these customizations is in the after directory, i.e. ~/.vim/after/ftplugin/html.vim; just create a new file and put the :let command in there.

You can observe the sequence of sourced scripts via :scriptnames. In other cases, when you're not overriding default behavior, the :autocmd FileType is alright, but I prefer putting these (e.g. custom mappings) into ~/.vim/ftplugin/html_mymappings.vim, as it provides better separation and helps keeping your .vimrc short and understandable.

The ftdetect subdirectory is for filetype detection, i.e. inspecting file path / name / contents to determine the correct filetype. It doesn't apply here, as the filetype is html.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.