sponsor Vim development Vim logo Vim Book Ad

operator-user : Define your own operator easily

 script karma  Rating 23/7, Downloaded by 4236  Comments, bugs, improvements  Vim wiki

created by
Kana Natsuno
 
script type
utility
 
description
*operator-user* is a Vim library plugin to provide an easy way to define your
own |operator|.  Though there are several pitfalls to define operators, you
don't have to take care of them with |operator#user#define()| which are
provided by this library plugin.

For example, the following code defines operator "_" to adjust the height of
the current window to the same as the target range:

map _  <Plug>(operator-adjust)
call operator#user#define('adjust', 'Op_adjust_window_height')
function! Op_adjust_window_height(motion_wiseness)
  execute (line("']") - line("'[") + 1) 'wincmd' '_'
  normal! `[zt
endfunction

You can use this operator as follows:

10__ Adjust to 10 lines and show the current line at the top.
_ip Adjust to the same height of the paragraph under the cursor.

This operator is useful to adjust the visible content in the current window.

See also |operator-user-examples| for more examples and explanations.


Requirements:
- Vim 7.2 or later

Optionals:
- |grex| (vimscript#2773)
- |operator-replace| (vimscript#2782)
- |wwwsearch| (vimscript#2785)

Latest version:
http://github.com/kana/config/commits/vim-operator-user

Document
in HTML format:
http://kana.github.com/config/vim/operator-user.html
 
install details
...
 

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
vim-operator-user-0.0.7.zip 0.0.7 2012-06-02 7.0 Kana Natsuno - |operator#user#define_ex_command|: Support {ex-command} including "'".  For example: s/"/'/g
- Refine old-style test scripts.
vim-operator-user-0.0.5.zip 0.0.5 2009-09-07 7.0 Kana Natsuno - Add |operator#user#visual_command_from_wise_name()|.
- Revise a bit of the document.
vim-operator-user-0.0.4.zip 0.0.4 2009-09-07 7.0 Kana Natsuno - Fix a bug that it rarely fails to select the same text as a given {motion} in Normal mode.  It is caused by a bug in Vim; |v:count1| may be 0 in some cases.
- Fix a bug that register designation ("a, "b, etc) doesn't work for user defiend operators.
vim-operator-user-0.0.3.zip 0.0.3 2009-09-04 7.0 Kana Natsuno Incompatible change:
- |operator#user#define()|, |operator#user#define_ex_command()|: Change the meaning of the first argument:

  Old versions:
  The argument is {lhs} to execute the operator to be defined.

  New version:
  The argument is {name} of the operator to be defined.
  {lhs} to execute the operator is "<Plug>(operator-{name})".

  See also |operator-user-bugs-C| for the details.
vim-operator-user-0.0.2.zip 0.0.2 2009-09-03 7.0 Kana Natsuno - Add |operator#user#define_ex_command()|.
- Add a note on a bug.  See |operator-user-bugs-B| for the details.
- Remove :DefineOperator.  It's useless as a part of this library.
vim-operator-user-0.0.1.zip 0.0.1 2009-07-18 7.0 Kana Natsuno - Rename as "operator-user".  The old name "myoperator" is not good for further works.
vim-myoperator-0.0.0.zip 0.0.0 2009-06-26 7.0 Kana Natsuno Initial upload
ip used for rating: 142.132.191.50

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