sponsor Vim development Vim logo Vim Book Ad

modepar : Extended modelines to execute real Vim script when loading a file.

 script karma  Rating 0/0, Downloaded by 597  Comments, bugs, improvements  Vim wiki

created by
Paul Isambert
 
script type
utility
 
description
Sometimes you want a bit of Vim code to be processed for a single file:
e.g. special mappings or a few convenient functions. You can't
put that into a filetype plugin, because it's for one file only, and perhaps
it doesn't even have a filetype to begin with. You can write a Vim script for
that file, but you have to remember to source it, and it creates unnecessary
files.

For instance, for a single file, you want to remap "S" to some function:

        function! MyFunc ()
           ...
        endfunction
        nnoremap <buffer> S :call MyFunc()<CR>

Modepars are meant to solve that issue: like modelines, they are bits of Vim
code contained directly in the file loaded in Vim, but unlike modelines, any
Vim code can be processed, not just options. Thus, the above example may appear
as follows at the beginning or end of a TeX file:
        
        % modepar:
        %
        % function! MyFunc ()
        %   ...
        % endfunction
        % nnoremap <buffer> S :call MyFunc()<CR>
        %
        % endmodepar

The comments make the code harmless to the TeX file, while the first and last
lines signal that it should be sourced by Vim like a script.

Modepars are executed automatically when a file is loaded into a buffer, just
like modelines; they can also be (re)loaded by hand. All modepars are
protected by ids, and only authorized modepars are automatically executed.
 
install details
Classic install
modepar/plugin/modepar.vim   goes into   ~/.vim/plugin
modepar/doc/modepar.txt          goes into   ~/.vim/doc

Pathogen;
Put the entire "modepar" dir in "~/.vim/bundle".
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
modepar.zip 1.0 2013-04-17 7.0 Paul Isambert Initial upload
ip used for rating: 18.222.182.105

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github