sponsor Vim development Vim logo Vim Book Ad

Omap.vim : create user-defined operator mappings

 script karma  Rating 24/6, Downloaded by 554  Comments, bugs, improvements  Vim wiki

created by
Ben Collerson
 
script type
utility
 
description
A slightly more maintained version of this script is here: https://github.com/bencollerson/Omap.vim

Omap.vim provides the :Omap command, among others, which creates user-defined operator commands (like y c d and g?, see :help operator for more info).

To demonstrate, this command can be used to add functionality to other scripts. You can use Omap.vim in conjuction with EnhancedCommentify.vim (vimscript #23) to create a commenting operator. Assuming both EnhancedCommentify.vim and Omap.vim are installed in your vim plugin directory, add the following commands to your .vimrc file:

    let g:EnhCommentifyUserBindings = 'yes'
    runtime plugin/Omap.vim
    Omap <silent> <unique> <leader>c <Plug>Commentj
    Omap <silent> <unique> <leader>u <Plug>DeCommentj

This will stop the default mappings being defined by EnhancedCommentify.vim and in their place create comment (\c) and uncomment (\u) operators.

This allows commenting to be carried out over areas defined by vim motions and text objects. For example:

    \cc  --  comments a line
    .  --  comments the next line (repeats last command)
    3\cc  --  comments three lines
    \uu  --  uncomments a line
    \c4j  --  comments the current line and the four following lines
    \caB  --  comments a block of code

Note that the dot (.) command (see :help .) works to repeat Omaps even though they are mappings. A command, :DotCommandSet, is defined by Omap.vim which allows other mappings to similarly be repeated using the dot command.

For more detailed help see the help documentation in the archive below.
 
install details
To install, unzip Omap.zip placing Omap.vim in your vim plugins directory and Omap.txt in your vim doc directory.

Run :helptags on your doc directory to install documentation into the vim help system.
 

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
Omap.zip 1.0 2005-03-22 6.0 Ben Collerson Initial upload
ip used for rating: 3.144.33.41

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