SkyBison
SkyBison copied to clipboard
SkyBison fails to call :nohlsearch
Steps to reproduce:
-
Install SkyBison (duh).
-
Add
nnoremap : :<C-u>call SkyBison("")<CR>
to your vimrc.
-
Reload your vimrc.
-
Use / to search for something.
-
Type :nohl (or :nohlsearch).
For some reason, it fails to un-highlight the search. :nohl works just fine from ex mode, so I assume SkyBison fails to actually call the command somehow.
Isn't this just the fact that :nohl has no effect when called in a function? Although, adding
if a:cmdline =~# '^[: ]*noh\%[lsearch]'
let v:hlsearch = 0
endif
to s:RunCommandAndQuit
doesn't help either. I did notice something else while looking at this. I'll file an issue for that.
I was not able to come up with any way to effectively do :nohl
in a function.
As :help :nohl
points out, autocmds are also not a viable solution. Trying
to do it indirectly with something like v:hlsearch
doesn't work either, as
jamessan pointed out. However, SkyBison only really runs into this at the very
end of what it does. We can leverage feedkeys()
to run something after
SkyBison's function ends. For example, change line 31 (execute a:cmdline
) in
the current version to:
call feedkeys(":") . a:cmdline . "\<cr>", "n")
The "n"
flag is necessary for situations such as alpha123's so it does not
call SkyBison again.
I've been bitten in the past by using feedkeys()
without fully thinking
things through, so I don't want to jump to doing this without some thought and
experimentation. However, a quick test with the instructions above seems to
work. Some potential issues with this:
- Can anyone think of a way that the
"n"
flag would keep SkyBison from using some mapping the user would want? I tried stuff like calling:normal
with stuff I have mapped in a feedkeys with and without"n"
but it seems to act the same. - Can anyone think possible user input which would result in an infinite loop,
even with the
"n"
flag?
While I think this is a terrible idea, another avenue which might work is to
make SkyBison a :command
instead of a function under-the-hood. A really
long, ugly command with lots of pipes that heavily abuses :execute
. I'd like
to exhaust options like feedkeys()
before pursuing this, but it may be worth
mentioning and thinking about.