" Vim plugin -- repeat motions for which a count was given " General: {{{1 " File: repmo.vim " Created: 2008 Jan 27 " Last Change: 2009 Jun 03 " Rev Days: 7 " Author: Andy Wokula " Version: 0.5 " Question: BML schrieb: Is there a way/command to repeat the last movement, " like ; and , repeat the last f command? It would be nice to be able to " select the 'scrolling' speed by typing 5j or 8j, and then simply hold " down a key and what the text scroll by at your given speed. Ben " Answer: No there isn't, but an exception is :h 'scroll " Or take repmo.vim as an answer. It overloads the keys ";" and "," to " repeat motions. " Usage By Example: " Type "5j" and then ";" to repeat "5j" (after :RepmoMap j k ). " Type "hjkl" and then ";", it still repeats "5j". " Type "," to do "5k" (go in reverse direction). " Type "4k" and then ";" to repeat "4k" (after :RepmoMap k j ). " " The following motions (and scroll commands) are mapped per default: " j,k, h,l, Ctrl-E,Ctrl-Y, zh,zl " " Compatibility: " - Visual mode " - "f{char}" followed by ";," " - Operator pending mode with ";" and "," " Commands: " :RepmoMap {motion}|{reverse-motion} ... [] ... " " Map {motion} to be repeatable with ";". Use {reverse-motion} for " ",". Key notation is like in mappings. " If one of the arguments is , all key pairs right from it are " mapped with modifier (:h map-). " Options: type default when checked " g:repmo_key (string) ";" frequently, e.g. when " g:repmo_revkey (string) "," \ doing "5j" " g:repmo_mapmotions (bool) 1 when sourced " " see Customization for details " Installation: " it's a plugin, simply :source it (e.g. :so %) " Hints: " - there is little error checking, don't do :let repmo_key = " " or "|" " etc. " - to unmap "f", "F", "t", "T", ";" and "," at once, simply type "ff" (for " example); the next "5j" maps them again " - to avoid mapping "f", "F", "t" and "T" at all, use other keys than ";" " and "," for repeating " - Debugging: :debug normal 5j doesn't work, use 5:debug normal j " instead; but 5:normal jjj does 5j5j5j " - when changing g:repmo_key, g:repmo_revkey during session, the old keys " will not be unmapped automatically " TODO: " - more\test\C130.vim " ? preserve remappings by user, e.g. :map j gj " currently these mappings are replaced without warning " ? [count]{g:repmo_key} -- multiply the counts? " - protect more alien :omaps (yankring!) " + make ";" and "," again work with "f{char}", "F{char}", ... " + v0.2 don't touch user's mappings for f/F/t/T " + v0.2 check for empty g:repmo_key " + check key notation: '\|' is ok, '|' not ok " no check added: we cannot check for everything " + Bug: i_l inserts rest of l-mapping in the text; for l and h " VimBuddy doesn't rotate its nose ... ah, statusline is updated twice " ! v0.3 use :normal {motion} within the function " v0.5 " + :RepmoMap, new argument syntax " + work in Vi-mode with " + added :sil! before unmap ; in case user unmapped ";" by hand " + :normal didn't work with (i.e. " ") " + let f/F/t/T accept a count when unmapping " }}} " Script Init Folklore: {{{1 if exists("loaded_repmo") finish endif let loaded_repmo = 1 if v:version < 700 || &cp echo "Repmo: you need at least Vim 7 and 'nocp' set" finish endif let s:sav_cpo = &cpo set cpo&vim " " doesn't help, we need absent cpo-< all the time " :h map- " Customization: {{{1 " keys used to repeat motions: if !exists("g:repmo_key") " " key notation is like in mappings: " let g:repmo_key = "" " let g:repmo_revkey = "" let g:repmo_key = ";" let g:repmo_revkey = "," endif " motions to map per default if !exists("g:repmo_mapmotions") let g:repmo_mapmotions = "j|k h|l | zh|zl" " use "" to map "|" endif " Functions: {{{1 " Internal Variables: {{{ let s:lastkey = "" let s:lastrevkey = "" "}}} " Internal Mappings: "{{{ nn repmo( :callMapRepeatMotion(0, vn repmo( :callMapRepeatMotion(1, nn lastkey :callMapRepMo(0) vn lastkey :callMapRepMo(1) no cnt Count("get") " straight (v:count>0 ? v:count : "") doesn't yet work with gVim7.1.315 let s:SNR = matchstr(maparg("lastkey", "n"), '\d\+_') "}}} func! RepmoMap(key, revkey, ...) abort "{{{ " Args: {motion} {rev-motion} " map the {motion} key; {motion}+{rev-motion} on RHS let unique = a:0>=1 && a:1 ? "" : "" let lhs = printf("