junegunn / junegunn/vader.vim

README incorrectly states that not updated search history is a Vim bug

Open
#62 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Vim Script
Stars
599
Forks
40
PR merge metrics
No merged PRs in 30d

Description

Unlike absense of `CursorMoved` event which is either a bug or feature without documentation I know about, search history is intentionally not updated: `:h function-search-undo`. README should not mention this as being “likely a bug of Vim”.

---

If you want to fix this you need to run `Do` blocks outside of a function which will get messy because function looking like

```
function Foo() abort
" Do something
normal test
" Do something else
endfunction
```

needs to be converted into

```
function FooStart() abort
" Do something
call feedkeys("test\:call FooEnd()\n", "t")
endfunction
function FooEnd() abort
" Do something else
endfunction
```

which looks easy only as long as `Foo` is called at the top level and not by other function and does not contain any kinds of conditional/cyclic execution: both is not your case. But this conversion may appear to fix problems with events (did not actually test), search history (very much likely to fix), and also allows creating workaround for “inability to use `feedkeys()`” problem: use `FooEndRunner()` function that may delay `FooEnd` run:

```
function FooStart() abort
" Do something
call feedkeys("test\(VaderRunFooEnd)", "t")
endfunction
function FooEndRunner() abort
if getchar(1) isnot 0
call feedkeys("\(VaderRunFooEnd)", "t") " Delay running FooEnd until there is no output
return ""
endif
return "\\:call FooEnd()\n"
endfunction
map (VaderRunFooEnd) FooEndRunner()
map! (VaderRunFooEnd) FooEndRunner()
```

(looks ugly, which is why I would never use test frameworks written in VimL: ugly hacks either in your code or in framework code are necessary in many complex cases).

---

There is also another unmentioned issue with `` mappings: column position is updated not when you expect:

```
:let @a='i|jj'
:inoremap jj col('.')
:normal! @a
```

yields `|1`. Change ` jj col('.')` to `jj =col('.')` and this will yield `|2`. Do not change anything, but in place of using macros type `i|jj`, you will see `|2` again. `feedkeys(@a, "t")` is not helpful here as well, so my workaround will not fix this issue. (Issue was actually found when creating tests for translit3 plugin; those tests have nothing to do with vader.vim, but issue will also definitely hit your users should they need cursor position inside an `` mapping for whatever reason. Do not remember whether I did report it to vim-dev.)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.