From ce73df6fc53c011cae7c8dc0df5a283c66a44930 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Fri, 23 Oct 2020 22:41:54 +0800 Subject: [PATCH] Add f{char} for iedit-normal mode (#3922) --- autoload/SpaceVim/plugins/iedit.vim | 23 ++++++++++++++++++++++- docs/cn/documentation.md | 3 ++- docs/documentation.md | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/plugins/iedit.vim b/autoload/SpaceVim/plugins/iedit.vim index fa48d9080..cd0a92b61 100644 --- a/autoload/SpaceVim/plugins/iedit.vim +++ b/autoload/SpaceVim/plugins/iedit.vim @@ -140,13 +140,31 @@ endfunction function! s:handle(mode, char) abort - if a:mode ==# 'n' + if a:mode ==# 'n' && s:Operator ==# 'f' + return s:handle_f_char(a:char) + elseif a:mode ==# 'n' return s:handle_normal(a:char) elseif a:mode ==# 'i' return s:handle_insert(a:char) endif endfunction +function! s:handle_f_char(char) abort + silent! call s:remove_cursor_highlight() + " map(rang(32,126), 'nr2char(v:val)') + " [' ', '!', '"', '#', '$', '%', '&', '''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'] + if a:char >= 32 && a:char <= 126 + let s:Operator = '' + for i in range(len(s:cursor_stack)) + let matchedstr = matchstr(s:cursor_stack[i].end, printf('[^%s]*', nr2char(a:char))) + let s:cursor_stack[i].begin = s:cursor_stack[i].begin . s:cursor_stack[i].cursor . matchedstr + let s:cursor_stack[i].end = matchstr(s:cursor_stack[i].end, printf('[%s]\zs.*', nr2char(a:char))) + let s:cursor_stack[i].cursor = nr2char(a:char) + endfor + endif + silent! call s:highlight_cursor() + return s:cursor_stack[0].begin . s:cursor_stack[0].cursor . s:cursor_stack[0].end +endfunction let s:toggle_stack = {} @@ -227,6 +245,9 @@ function! s:handle_normal(char) abort let s:cursor_stack[i].cursor = s:STRING.toggle_case(s:cursor_stack[i].cursor) endfor call s:replace_symbol() + elseif a:char == 102 " f + let s:Operator = 'f' + call s:timeout() elseif a:char == 115 " s let s:mode = 'i' let w:spacevim_iedit_mode = s:mode diff --git a/docs/cn/documentation.md b/docs/cn/documentation.md index 8e4076fc2..3fbb93ed9 100644 --- a/docs/cn/documentation.md +++ b/docs/cn/documentation.md @@ -1819,7 +1819,7 @@ Denite/Unite 是一个强大的信息筛选浏览器,这类似于 Emacs 中的 | `SPC p k` | 关闭当前工程的所有缓冲区 | | `SPC p p` | 显示所有工程 | -`SPC p p` 将会列出最近使用的项目清单,默认会显示最多20个, +`SPC p p` 将会列出最近使用的项目清单,默认会显示最多 20 个, 这一数量可以使用 `projects_cache_num` 来修改。 为了可以夸 Vim 进程读取历史打开的项目信息,这一功能使用了缓存机制。 @@ -2044,6 +2044,7 @@ SpaceVim 内置了 iedit 多光标模式,可快速进行多光标编辑。这 | `X` | 删除所有 occurrences 中光标前的字符,类似于一般模式下的 `X` | | `gg` | 跳至第一个 occurrence,类似于一般模式下的 `gg` | | `G` | 跳至最后一个 occurrence,类似于一般模式下的 `G` | +| `f{char}` | 向右移动光标至字符 `{char}` 首次出现的位置 | | `n` | 跳至下一个 occurrence | | `N` | 跳至上一个 occurrence | | `p` | 替换所有 occurrences 为最后复制的文本 | diff --git a/docs/documentation.md b/docs/documentation.md index 1d7057f71..ee7cfa302 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -2098,6 +2098,7 @@ The default color for iedit is `red`/`green` which is based on the current color | `X` | delete the character before cursor in all the occurrences, same as `X` in `Normal` model | | `gg` | go to first occurrence, same as `gg` in `Normal` model | | `G` | go to last occurrence, same as `G` in `Normal` model | +| `f{char}` | Move the cursor to the right where the `{char}` first appears in all the occurrences | | `n` | go to next occurrence | | `N` | go to previous occurrence | | `p` | replace occurrences with last yanked (copied) text |