Feature/begin end #3

Merged
lohhiiccc merged 6 commits from feature/begin-end into main 2025-08-21 15:26:13 +00:00
2 changed files with 48 additions and 3 deletions
Showing only changes of commit de7d77d1b4 - Show all commits

View file

@ -19,11 +19,10 @@ export def InsertChar(mode: string, count: number, input_char: string = ''): voi
return return
endif endif
# Determine whether to insert before (i) or after (a) cursor var insert_command = GetInsertCommand(mode)
var insert_command = (mode ==# 'at') ? 'i' : 'a'
var insert_text = repeat(first_char, (count == 0) ? 1 : count) var insert_text = repeat(first_char, (count == 0) ? 1 : count)
execute 'normal! ' .. insert_command .. insert_text .. "\<Esc>" DoSingleChar(insert_command, insert_text, g:singlechar_static_cursor)
# Save last used values # Save last used values
g:last_singlechar_key = first_char g:last_singlechar_key = first_char
@ -38,6 +37,31 @@ export def InsertChar(mode: string, count: number, input_char: string = ''): voi
endif endif
enddef enddef
def GetInsertCommand(mode: string): string
if mode ==# 'at'
return 'i'
elseif mode ==# 'after'
return 'a'
elseif mode ==# 'begin'
return 'I'
elseif mode ==# 'end'
return 'A'
else
return 'i'
endif
enddef
def DoSingleChar(command: string, text: string, resetCursor: number): void
var pos = getpos('.')
execute 'normal! ' .. command .. text .. "\<Esc>"
if resetCursor == 1
if (command ==# 'i')
pos[2] = pos[2] + 1
endif
setpos('.', pos)
endif
enddef
def g:RepeatSingleChar(): void def g:RepeatSingleChar(): void
if g:last_singlechar_key != '' if g:last_singlechar_key != ''
call InsertChar(g:last_singlechar_mode, g:last_singlechar_count, g:last_singlechar_key) call InsertChar(g:last_singlechar_mode, g:last_singlechar_count, g:last_singlechar_key)

View file

@ -30,15 +30,32 @@ if !exists('g:singlechar_map_insert_after')
g:singlechar_map_insert_after = '<Leader>a' g:singlechar_map_insert_after = '<Leader>a'
copilot-pull-request-reviewer[bot] commented 2025-08-21 15:24:18 +00:00 (Migrated from github.com)
Review

The comment 'Toggle off static cursor' is misleading. This variable enables/disables the static cursor feature, not toggles it off.

# Enable/disable static cursor feature
The comment 'Toggle off static cursor' is misleading. This variable enables/disables the static cursor feature, not toggles it off. ```suggestion # Enable/disable static cursor feature ```
copilot-pull-request-reviewer[bot] commented 2025-08-21 15:24:18 +00:00 (Migrated from github.com)
Review

Spelling error: 'warnign' should be 'warning'.

# toggle warning
Spelling error: 'warnign' should be 'warning'. ```suggestion # toggle warning ```
endif endif
# Mapping to insert a character at the endline
if !exists('g:singlechar_map_insert_end')
g:singlechar_map_insert_end = '<Leader>A'
endif
# Mapping to insert a character at the startline
if !exists('g:singlechar_map_insert_begin')
g:singlechar_map_insert_begin = '<Leader>I'
endif
# Prompt message shown when waiting for character input # Prompt message shown when waiting for character input
if !exists('g:singlechar_prompt') if !exists('g:singlechar_prompt')
g:singlechar_prompt = 'Press the character to insert - Press Esc to cancel...' g:singlechar_prompt = 'Press the character to insert - Press Esc to cancel...'
endif endif
#Toggle static cursor
if !exists('g:singlechar_static_cursor')
g:singlechar_static_cursor = 0
endif
# toggle warnign
if !exists('g:singlechar_keylen_warning') if !exists('g:singlechar_keylen_warning')
g:singlechar_keylen_warning = 1 g:singlechar_keylen_warning = 1
endif endif
# warning message
if !exists('g:singlechar_warning_message') if !exists('g:singlechar_warning_message')
g:singlechar_warning_message = 'Only the first character will be taken: {char}' g:singlechar_warning_message = 'Only the first character will be taken: {char}'
endif endif
@ -54,6 +71,8 @@ g:last_singlechar_count = 1
nnoremap <Plug>(singlechar-repeat) :call g:RepeatSingleChar()<CR> nnoremap <Plug>(singlechar-repeat) :call g:RepeatSingleChar()<CR>
# Direct command implementations # Direct command implementations
command! -count=1 -nargs=? InsertCharBegin singlechar.InsertChar('begin', <count>, <q-args>)
command! -count=1 -nargs=? InsertCharEnd singlechar.InsertChar('end', <count>, <q-args>)
command! -count=1 -nargs=? InsertCharAt singlechar.InsertChar('at', <count>, <q-args>) command! -count=1 -nargs=? InsertCharAt singlechar.InsertChar('at', <count>, <q-args>)
command! -count=1 -nargs=? InsertCharAfter singlechar.InsertChar('after', <count>, <q-args>) command! -count=1 -nargs=? InsertCharAfter singlechar.InsertChar('after', <count>, <q-args>)
@ -61,6 +80,8 @@ command! -count=1 -nargs=? InsertCharAfter singlechar.InsertChar('after', <count
if !exists('g:singlechar_no_mappings') if !exists('g:singlechar_no_mappings')
execute 'nnoremap <expr> <silent> ' .. g:singlechar_map_insert_at .. ' ":<C-u>InsertCharAt " .. v:count1 .. "<CR>"' execute 'nnoremap <expr> <silent> ' .. g:singlechar_map_insert_at .. ' ":<C-u>InsertCharAt " .. v:count1 .. "<CR>"'
execute 'nnoremap <expr> <silent> ' .. g:singlechar_map_insert_after .. ' ":<C-u>InsertCharAfter " .. v:count1 .. "<CR>"' execute 'nnoremap <expr> <silent> ' .. g:singlechar_map_insert_after .. ' ":<C-u>InsertCharAfter " .. v:count1 .. "<CR>"'
execute 'nnoremap <expr> <silent> ' .. g:singlechar_map_insert_begin .. ' ":<C-u>InsertCharBegin " .. v:count1 .. "<CR>"'
execute 'nnoremap <expr> <silent> ' .. g:singlechar_map_insert_end .. ' ":<C-u>InsertCharEnd " .. v:count1 .. "<CR>"'
endif endif
# Usage: # Usage: