feat: add vim-repeat support
This commit is contained in:
parent
be8e79da7c
commit
398c5a41d3
1 changed files with 31 additions and 9 deletions
|
|
@ -37,18 +37,26 @@ endif
|
||||||
# ------------------------------------------------------------------------------ #
|
# ------------------------------------------------------------------------------ #
|
||||||
# Core functionality
|
# Core functionality
|
||||||
|
|
||||||
|
g:last_singlechar_key = ''
|
||||||
|
g:last_singlechar_mode = ''
|
||||||
|
g:last_singlechar_count = 1
|
||||||
|
|
||||||
# Function to handle character insertion
|
# Function to handle character insertion
|
||||||
# Parameters:
|
# Parameters:
|
||||||
# mode: 'at' to insert before cursor, 'after' to insert after cursor
|
# mode: 'at' to insert before cursor, 'after' to insert after cursor
|
||||||
# count: number of times to repeat the character
|
# count: number of times to repeat the character
|
||||||
def InsertChar(mode: string, count: number): void
|
# pkey: character to insert (optional)
|
||||||
echo g:singlechar_prompt
|
export def InsertChar(mode: string, count: number, pkey: string = ''): void
|
||||||
|
|
||||||
# Get character from user
|
var key = pkey
|
||||||
var char = getchar()
|
if pkey == ''
|
||||||
var key = nr2char(char)
|
echo g:singlechar_prompt
|
||||||
|
redraw
|
||||||
redraw
|
|
||||||
|
# Get character from user
|
||||||
|
var char = getchar()
|
||||||
|
key = nr2char(char)
|
||||||
|
endif
|
||||||
if key ==# "\<Esc>"
|
if key ==# "\<Esc>"
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
@ -58,10 +66,24 @@ def InsertChar(mode: string, count: number): void
|
||||||
var text = repeat(key, count)
|
var text = repeat(key, count)
|
||||||
|
|
||||||
execute 'normal! ' .. cmd .. text .. "\<Esc>"
|
execute 'normal! ' .. cmd .. text .. "\<Esc>"
|
||||||
|
#save
|
||||||
|
g:last_singlechar_key = key
|
||||||
|
g:last_singlechar_mode = mode
|
||||||
|
g:last_singlechar_count = count
|
||||||
|
|
||||||
|
#set vim-repeat
|
||||||
|
legacy call repeat#set("\<Plug>(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
|
enddef
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------ #
|
# ------------------------------------------------------------------------------ #
|
||||||
# Commands and mappings
|
# Mappings <Plug>
|
||||||
|
nnoremap <Plug>(singlechar-repeat) :call g:RepeatSingleChar()<CR>
|
||||||
|
|
||||||
# Direct command implementations
|
# Direct command implementations
|
||||||
command! -count=1 -nargs=0 InsertCharAt InsertChar('at', <count>)
|
command! -count=1 -nargs=0 InsertCharAt InsertChar('at', <count>)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue