From 398c5a41d39417d2384651113015824e48b8524f Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Tue, 19 Aug 2025 09:09:34 +0200 Subject: [PATCH] feat: add vim-repeat support --- plugin/singlechar.vim | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/plugin/singlechar.vim b/plugin/singlechar.vim index 32e7dcf..fd32cc1 100644 --- a/plugin/singlechar.vim +++ b/plugin/singlechar.vim @@ -37,18 +37,26 @@ endif # ------------------------------------------------------------------------------ # # Core functionality +g:last_singlechar_key = '' +g:last_singlechar_mode = '' +g:last_singlechar_count = 1 + # Function to handle character insertion # Parameters: # mode: 'at' to insert before cursor, 'after' to insert after cursor # count: number of times to repeat the character -def InsertChar(mode: string, count: number): void - echo g:singlechar_prompt - - # Get character from user - var char = getchar() - var key = nr2char(char) - - redraw +# pkey: character to insert (optional) +export def InsertChar(mode: string, count: number, pkey: string = ''): void + + var key = pkey + if pkey == '' + echo g:singlechar_prompt + redraw + + # Get character from user + var char = getchar() + key = nr2char(char) + endif if key ==# "\" return endif @@ -58,10 +66,24 @@ def InsertChar(mode: string, count: number): void var text = repeat(key, count) execute 'normal! ' .. cmd .. text .. "\" + #save + g:last_singlechar_key = key + g:last_singlechar_mode = mode + g:last_singlechar_count = count + + #set vim-repeat + legacy call repeat#set("\(singlechar-repeat)") +enddef + +export def g:RepeatSingleChar(): void + if g:last_singlechar_key != '' + call InsertChar(g:last_singlechar_mode, g:last_singlechar_count, g:last_singlechar_key) + endif enddef # ------------------------------------------------------------------------------ # -# Commands and mappings +# Mappings +nnoremap (singlechar-repeat) :call g:RepeatSingleChar() # Direct command implementations command! -count=1 -nargs=0 InsertCharAt InsertChar('at', )