sponsor Vim development Vim logo Vim Book Ad

motpat.vim : create motion mappings defined by a pattern

 script karma  Rating 7/3, Downloaded by 1010  Comments, bugs, improvements  Vim wiki

created by
Andy Wokula
 
script type
utility
 
description
Create motion mappings defined by a pattern.
The resulting keys can be used in Normal, Visual and Operator-pending mode; and they accept a count.

2017 Nov 10 https://github.com/Houl/motpat-vim

Functions:

motpat#Map({buf-local}, {lhs-forw}, {lhs-back}, {rhs-pat}[, {excl}])

    {buf-local} if non-zero, create buffer-local mappings, else global mappings
    {lhs-forw} key to be mapped for forward searching (not if empty)
    {lhs-back} key to be mapped for backward searching (not if empty)
    {rhs-pat} pattern to define the motion, will be part of the resulting {rhs} of the mapping
    {excl} type of motion, one of "e" (default), "i" or "l", for exclusive, inclusive or linewise, makes use of |o_v|.

" the following two functions just omit one argument:
motpat#Fmap({buf-local}, {lhs-forw}, {rhs-pat}[, {excl}])
motpat#Bmap({buf-local}, {lhs-back}, {rhs-pat}[, {excl}])


Examples:

ftplugin/vim.vim >
" simpler definition of ]], [[, ][, [], [" and ]"

" Move around functions.
call motpat#Map(1, ']]', '[[', '^\s*fu\%[nction]\>')
call motpat#Map(1, '][', '[]', '^\s*endf\%[unction]\>', 'l')

" Move around comments
call motpat#Fmap(1, ']"', '\%(^\s*".*\n\)\%(^\s*"\)\@!', 'l')
call motpat#Bmap(1, '["', '\%(^\s*".*\n\)\@<!\%(^\s*"\)', 'l')
 
install details
extract to a runtimepath folder

files in the archive:
autoload/motpat.vim
autoload/gvmap.vim (helper script)
doc/motpat.txt
 

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
motpat_0.1.zip 0.1 2010-03-28 7.2 Andy Wokula 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