paperlined.org
apps > vim > howto
document updated 13 years ago, on Apr 10, 2011

Is it possible to have extensive custom functions, just for a single document?

It's true there's modelines, but you can only do one line with them, and for security reasons, they only do variables.



So, just put this in your ~/.vimrc:

au BufRead *
    \   if filereadable(expand("%:p:h")."/.".expand("%:t").".vim")
    \ |     exe 'source '.expand("%:p:h")."/.".expand("%:t").".vim"
    \ | endif
That way, when you edit foobar.html, it will load .foobar.html.vim if it exists.

(this has RAGING security issues, namely, the fact that anyone who can create files in the directory you're editing can force you to run any vim command, which also means they can make vim shell out and run any system command, which means they can backdoor your account, even if you're root)

Then in .foobar.html.vim, put:

command!   Fix   call Fix()

" fix problems that commonly occur in this document
function! Fix()

    %s/foo/bar/

endfunction
Then you can run :Fix while editing, whenever desired.