From de7d77d1b48f24beeb782f700b2c59ca0f8b9463 Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Thu, 21 Aug 2025 16:13:10 +0200 Subject: [PATCH 1/6] feature: Add begin/end line singlechar insertion and static cursor option - Introduce InsertCharBegin and InsertCharEnd commands to insert a character at the beginning or end of the line (I and A). - Add configuration variables for customizable mappings: - g:singlechar_map_insert_begin - g:singlechar_map_insert_end - Implement GetInsertCommand() and DoSingleChar() in autoload/singlechar.vim to support new modes and static cursor feature. - Add g:singlechar_static_cursor option: when enabled, cursor returns to its original position after insertion. --- autoload/singlechar.vim | 30 +++++++++++++++++++++++++++--- plugin/singlechar.vim | 21 +++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/autoload/singlechar.vim b/autoload/singlechar.vim index bd8cefc..53878e2 100644 --- a/autoload/singlechar.vim +++ b/autoload/singlechar.vim @@ -19,11 +19,10 @@ export def InsertChar(mode: string, count: number, input_char: string = ''): voi return endif - # Determine whether to insert before (i) or after (a) cursor - var insert_command = (mode ==# 'at') ? 'i' : 'a' + var insert_command = GetInsertCommand(mode) var insert_text = repeat(first_char, (count == 0) ? 1 : count) - execute 'normal! ' .. insert_command .. insert_text .. "\" + DoSingleChar(insert_command, insert_text, g:singlechar_static_cursor) # Save last used values g:last_singlechar_key = first_char @@ -38,6 +37,31 @@ export def InsertChar(mode: string, count: number, input_char: string = ''): voi endif 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 .. "\" + if resetCursor == 1 + if (command ==# 'i') + pos[2] = pos[2] + 1 + endif + setpos('.', pos) + endif +enddef + def g:RepeatSingleChar(): void if g:last_singlechar_key != '' call InsertChar(g:last_singlechar_mode, g:last_singlechar_count, g:last_singlechar_key) diff --git a/plugin/singlechar.vim b/plugin/singlechar.vim index e4ddf80..b0d62dc 100644 --- a/plugin/singlechar.vim +++ b/plugin/singlechar.vim @@ -30,15 +30,32 @@ if !exists('g:singlechar_map_insert_after') g:singlechar_map_insert_after = 'a' endif +# Mapping to insert a character at the endline +if !exists('g:singlechar_map_insert_end') + g:singlechar_map_insert_end = 'A' +endif + +# Mapping to insert a character at the startline +if !exists('g:singlechar_map_insert_begin') + g:singlechar_map_insert_begin = 'I' +endif + # Prompt message shown when waiting for character input if !exists('g:singlechar_prompt') g:singlechar_prompt = 'Press the character to insert - Press Esc to cancel...' endif +#Toggle static cursor +if !exists('g:singlechar_static_cursor') + g:singlechar_static_cursor = 0 +endif + +# toggle warnign if !exists('g:singlechar_keylen_warning') g:singlechar_keylen_warning = 1 endif +# warning message if !exists('g:singlechar_warning_message') g:singlechar_warning_message = 'Only the first character will be taken: {char}' endif @@ -54,6 +71,8 @@ g:last_singlechar_count = 1 nnoremap (singlechar-repeat) :call g:RepeatSingleChar() # Direct command implementations +command! -count=1 -nargs=? InsertCharBegin singlechar.InsertChar('begin', , ) +command! -count=1 -nargs=? InsertCharEnd singlechar.InsertChar('end', , ) command! -count=1 -nargs=? InsertCharAt singlechar.InsertChar('at', , ) command! -count=1 -nargs=? InsertCharAfter singlechar.InsertChar('after', , ) @@ -61,6 +80,8 @@ command! -count=1 -nargs=? InsertCharAfter singlechar.InsertChar('after', ' .. g:singlechar_map_insert_at .. ' ":InsertCharAt " .. v:count1 .. ""' execute 'nnoremap ' .. g:singlechar_map_insert_after .. ' ":InsertCharAfter " .. v:count1 .. ""' + execute 'nnoremap ' .. g:singlechar_map_insert_begin .. ' ":InsertCharBegin " .. v:count1 .. ""' + execute 'nnoremap ' .. g:singlechar_map_insert_end .. ' ":InsertCharEnd " .. v:count1 .. ""' endif # Usage: From 5393ae0555b660eda89122f08509c386e43a901e Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Thu, 21 Aug 2025 16:51:03 +0200 Subject: [PATCH 2/6] feat: enhance character insertion mappings in README - Add new mappings for character insertion: - `[count]I(char)` - Insert a character at the beginning of the line - `[count]A(char)` - Insert a character at the end of the line - Update insertion commands to reflect new functionalities: - `:InsertCharBegin (count) [char]` - Insert a character at the beginning of the line - `:InsertCharEnd (count) [char]` - Insert a character at the end of the line - Introduce an option for a static cursor during insertion actions. --- README.md | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 46b3a0e..48b6a5b 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,16 @@ git clone https://tpope.io/vim/repeat.git ## Usage -By default, the plugin provides two mappings: +By default, the plugin provides four mappings: +> [optional param] +> (param) -- `i` - Insert a character at the cursor position -- `a` - Insert a character after the cursor position +> `[count](char)` + +- `[count]i(char)` - Insert a character at the cursor position +- `[count]a(char)` - Insert a character after the cursor position +- `[count]I(char)` - Insert a character at the beginning of the line +- `[count]A(char)` - Insert a character at the end of the line After pressing the mapping, you'll see a prompt asking for the character to insert. Press any character and it will be inserted without entering insert mode. @@ -63,8 +69,13 @@ You can customize the plugin by setting these variables in your vimrc: ```vim " Change the mappings (before loading the plugin) -let g:singlechar_map_insert_at = 'i' " Default -let g:singlechar_map_insert_after = 'a' " Default +let g:singlechar_map_insert_at = 'i' " Default +let g:singlechar_map_insert_after = 'a' " Default +let g:singlechar_map_insert_begin = 'I' " Default +let g:singlechar_map_insert_end = 'A' " Default + +" Set the static cursor (no cursor move during singlechar actions) +let g:singlechar_static_cursor = 1 " Change the prompt message let g:singlechar_prompt = 'Press the character to insert - Press Esc to cancel...' " Default @@ -84,9 +95,14 @@ let g:singlechar_warning_message = 'Only the first character will be taken: {cha The plugin provides these commands: -- `:InsertCharAt [count]` - Insert a character at the cursor position -- `:InsertCharAfter [count]` - Insert a character after the cursor position +> [optional param] +> (param) + +- `:InsertCharAt (count) [char]` - Insert a character at the cursor position +- `:InsertCharAfter (count) [char]` - Insert a character after the cursor position +- `:InsertCharBegin (count) [char]` - Insert a character at the beginning of the line +- `:InsertCharEnd (count) [char]` - Insert a character at the end of the line ## License -MIT License +[MIT License](https://github.com/lohhiiccc/vim-singlechar/blob/main/LICENSE) From 502bf47ce4a03c2b4419b363a2f001308546ff3e Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Thu, 21 Aug 2025 16:57:52 +0200 Subject: [PATCH 3/6] docs: update singlechar.vim comments - Updated comments to specify toggling off the static cursor. - Revised usage instructions for character insertion mappings to include line positioning options. --- plugin/singlechar.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugin/singlechar.vim b/plugin/singlechar.vim index b0d62dc..a4d5c82 100644 --- a/plugin/singlechar.vim +++ b/plugin/singlechar.vim @@ -45,7 +45,7 @@ if !exists('g:singlechar_prompt') g:singlechar_prompt = 'Press the character to insert - Press Esc to cancel...' endif -#Toggle static cursor +#Toggle off static cursor if !exists('g:singlechar_static_cursor') g:singlechar_static_cursor = 0 endif @@ -85,10 +85,9 @@ if !exists('g:singlechar_no_mappings') endif # Usage: -# i - Insert character at cursor position -# a - Insert character after cursor position +# [count]i - Insert character at cursor position +# [count]I - Insert character at begin of the line +# [count]a - Insert character after cursor position +# [count]A - Insert character at end of the line # -# You can use a count before the mapping to insert multiple copies -# of the same character. For example: 3i will insert the -# character 3 times at the cursor position. # ------------------------------------------------------------------------------ # From d26ea1e5a616a6f611ada183f859c5a9c4fd4837 Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Thu, 21 Aug 2025 17:18:08 +0200 Subject: [PATCH 4/6] docs: Add new commands and mappings for begin/end-of-line insertion - Document new commands: :InsertCharBegin [count] [char], :InsertCharEnd [count] [char] - Update mappings to support begin/end-of-line insertion with [count] - Add configuration options for I and A mappings - Document static cursor option (g:singlechar_static_cursor) - Clarify usage and mapping examples for all new features --- doc/singlechar.txt | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/singlechar.txt b/doc/singlechar.txt index ab2e7eb..8a78a85 100644 --- a/doc/singlechar.txt +++ b/doc/singlechar.txt @@ -6,7 +6,7 @@ Author: lohhiiccc Version: 1.0.0 License: MIT -Last Change: 2025-08-19 +Last Change: 2025-08-21 CONTENTS *singlechar-contents* @@ -79,8 +79,10 @@ COMMANDS *singlechar-commands The plugin provides two commands: -`:InsertCharAt [count]` - Insert a character at the cursor position -`:InsertCharAfter [count]` - Insert a character after the cursor position +`:InsertCharAt [count] [char]` - Insert a character at the cursor position +`:InsertCharAfter [count] [char]` - Insert a character after the cursor position +`:InsertCharBegin [count] [char]` - Insert a character at the beginning of the line +`:InsertCharEnd [count] [char]` - Insert a character at the end of the line The optional count parameter specifies how many times to insert the character. @@ -89,8 +91,10 @@ MAPPINGS *singlechar-mappings By default, the plugin defines these mappings: -`i` - Map to `:InsertCharAt` -`a` - Map to `:InsertCharAfter` +`[count]i` - Map to `:InsertCharAt [count]` +`[count]a` - Map to `:InsertCharAfter [count]` +`[count]I` - Map to `:InsertCharBegin [count]` +`[count]A` - Map to `:InsertCharEnd [count]` =============================================================================== CONFIGURATION *singlechar-configuration* @@ -99,6 +103,8 @@ Customizing mappings: > " Must be set before the plugin is loaded let g:singlechar_map_insert_at = 'i' " Default let g:singlechar_map_insert_after = 'a' " Default + let g:singlechar_map_insert_begin = 'I' " Default + let g:singlechar_map_insert_end = 'A' " Default < Disabling default mappings: > " Disable default mappings @@ -107,7 +113,13 @@ Disabling default mappings: > " Create your own mappings nnoremap ,i ":InsertCharAt " .. v:count1 .. "" nnoremap ,a ":InsertCharAfter " .. v:count1 .. "" + nnoremap ,I ":InsertCharBegin " .. v:count1 .. "" + nnoremap ,A ":InsertCharEnd " .. v:count1 .. "" < +Set static cursor option: > + " When enabled, cursor returns to its original position after insertion + let g:singlechar_static_cursor = 1 + Changing the prompt message: > let g:singlechar_prompt = 'Character to insert (Esc to cancel): ' < From 0e688387b95a6adb1aba132d03f24ddf90f3338d Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Thu, 21 Aug 2025 17:25:16 +0200 Subject: [PATCH 5/6] docs: comment improvement - plugin/singlechar.vim Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- plugin/singlechar.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/singlechar.vim b/plugin/singlechar.vim index a4d5c82..b641c24 100644 --- a/plugin/singlechar.vim +++ b/plugin/singlechar.vim @@ -45,7 +45,7 @@ if !exists('g:singlechar_prompt') g:singlechar_prompt = 'Press the character to insert - Press Esc to cancel...' endif -#Toggle off static cursor +# Enable/disable static cursor feature if !exists('g:singlechar_static_cursor') g:singlechar_static_cursor = 0 endif From 5c3dec5d7e8fb091ca47ec90e8a201a7458c6294 Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Thu, 21 Aug 2025 17:25:45 +0200 Subject: [PATCH 6/6] typo(plugin/singlechar.vim): warnign -> warning Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- plugin/singlechar.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/singlechar.vim b/plugin/singlechar.vim index b641c24..1bbf54e 100644 --- a/plugin/singlechar.vim +++ b/plugin/singlechar.vim @@ -50,7 +50,7 @@ if !exists('g:singlechar_static_cursor') g:singlechar_static_cursor = 0 endif -# toggle warnign +# toggle warning if !exists('g:singlechar_keylen_warning') g:singlechar_keylen_warning = 1 endif