From 0eaf1f2da0e5a3c5d214c8d3648970ef56961c81 Mon Sep 17 00:00:00 2001 From: Illia Bobyr Date: Thu, 24 Jul 2025 00:28:02 -0700 Subject: [PATCH] Move required machinery into `plugin/repeat.vim`. `repeat.vim` was written to be used as either an autoloaded script or a normally loaded script. In particular, as mappings used to be defined by the autoload script, they would only be actually injected if any other plugin has used the repeat functionality. In practice, this creates problems as the mapping is not stable. One cannot define a custom mapping to `(RepeatUndo)`, as the existence of the mapping from `(RepeatUndo)` is subject to the prior execution of any code that uses the repeat functionality. Similarly, when loading a session that was stored when `u` was remapped to `(RepeatUndo)` is almost guaranteed to be an issue. As `u` is already remapped, but the plugin has not constructed the next step, mapping `(RepeatUndo)` to the correct function. Just setting up the mappings seems like a solid solution to these problems. While it is a bit less efficient, if the user has enabled this plugin, they probably rely on it, and so the optimizations are most likely negligible. Also updated the installation instructions. I would imagine most people use plugin managers today. And so it is no longer useful, in my mind, to be able to decide if the plugin will be eagerly or lazily loaded. It just complicates the installation process. --- autoload/repeat.vim | 78 +------------------------------------------ plugin/repeat.vim | 81 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 77 deletions(-) create mode 100644 plugin/repeat.vim diff --git a/autoload/repeat.vim b/autoload/repeat.vim index 364d311..7e9b2fa 100644 --- a/autoload/repeat.vim +++ b/autoload/repeat.vim @@ -1,56 +1,4 @@ " repeat.vim - Let the repeat command repeat plugin maps -" Maintainer: Tim Pope -" Version: 1.2 -" GetLatestVimScripts: 2136 1 :AutoInstall: repeat.vim - -" Installation: -" Place in either ~/.vim/plugin/repeat.vim (to load at start up) or -" ~/.vim/autoload/repeat.vim (to load automatically as needed). -" -" License: -" Copyright (c) Tim Pope. Distributed under the same terms as Vim itself. -" See :help license -" -" Developers: -" Basic usage is as follows: -" -" silent! call repeat#set("\MappingToRepeatCommand",3) -" -" The first argument is the mapping that will be invoked when the |.| key is -" pressed. Typically, it will be the same as the mapping the user invoked. -" This sequence will be stuffed into the input queue literally. Thus you must -" encode special keys by prefixing them with a backslash inside double quotes. -" -" The second argument is the default count. This is the number that will be -" prefixed to the mapping if no explicit numeric argument was given. The -" value of the v:count variable is usually correct and it will be used if the -" second parameter is omitted. If your mapping doesn't accept a numeric -" argument and you never want to receive one, pass a value of -1. -" -" Make sure to call the repeat#set function _after_ making changes to the -" file. -" -" For mappings that use a register and want the same register used on -" repetition, use: -" -" silent! call repeat#setreg("\MappingToRepeatCommand", v:register) -" -" This function can (and probably needs to be) called before making changes to -" the file (as those typically clear v:register). Therefore, the call sequence -" in your mapping will look like this: -" -" nnoremap MyMap -" \ :execute 'silent! call repeat#setreg("\Plug>MyMap", v:register)' -" \ call MyFunction(v:register, ...) -" \ silent! call repeat#set("\Plug>MyMap") - -if exists("g:loaded_repeat") || &cp || v:version < 800 - finish -endif -let g:loaded_repeat = 1 - -let g:repeat_tick = -1 -let g:repeat_reg = ['', ''] " Special function to avoid spurious repeats in a related, naturally repeating " mapping when your repeatable mapping doesn't increase b:changedtick. @@ -73,7 +21,6 @@ function! repeat#setreg(sequence,register) let g:repeat_reg = [a:sequence, a:register] endfunction - function! s:default_register() let values = split(&clipboard, ',') if index(values, 'unnamedplus') != -1 @@ -119,6 +66,7 @@ function! repeat#run(count) endtry return 1 endfunction + function! repeat#errmsg() return s:errmsg endfunction @@ -129,28 +77,4 @@ function! repeat#wrap(command,count) return (a:count ? a:count : '') . a:command . preserve . foldopen endfunction -nnoremap (RepeatDot) :if !repeat#run(v:count)echoerr repeat#errmsg()endif -nmap