# Visual-mode.kak

**URL:** <https://discuss.kakoune.com/t/visual-mode-kak/1725>\
**Category:** Plugins\
**Created:** [May 16, 2021, 5:10pm UTC](https://discuss.kakoune.com/t/visual-mode-kak/1725 "2021-05-16T17:10:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dead10ck](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/dead10ck/32/906_2.png) [@dead10ck](https://discuss.kakoune.com/u/dead10ck)\
**Post date:** [May 16, 2021, 5:10pm UTC](https://discuss.kakoune.com/t/visual-mode-kak/1725/1 "2021-05-16T17:10:29Z")

</div>

[visual-mode.kak](https://gitlab.com/dead10ck/visual-mode.kak) is my first attempt at a plugin; it emulates vim’s visual modes (character- and line-wise). Coming from vim, it’s a bit annoying having to hold down shift all the time, so I put this together and have been using it in my kakrc for a while, but I figured others might find it useful, so I factored it out to a plugin.

I’m still relatively new to Kakoune, so it’s possible I’m not doing everything the best way. Any feedback on the usability or implementation are welcome.

---

<div class="post-metadata">

**Author:** ![danr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/danr/32/700_2.png) [@danr](https://discuss.kakoune.com/u/danr)\
**Post date:** [May 17, 2021, 5:41am UTC](https://discuss.kakoune.com/t/visual-mode-kak/1725/2 "2021-05-17T05:41:03Z")

</div>

Hi, thanks for sharing! Did you have to do all the work with the hooks to get a behaviour of making unmapped keys fall back to normal mode keys? I’ve also wanted to have that fallback behaviour, it would be good if enter-user-mode had a flag for it.

---

<div class="post-metadata">

**Author:** ![dead10ck](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/dead10ck/32/906_2.png) [@dead10ck](https://discuss.kakoune.com/u/dead10ck)\
**Post date:** [May 17, 2021, 12:52pm UTC](https://discuss.kakoune.com/t/visual-mode-kak/1725/3 "2021-05-17T12:52:27Z")

</div>

@danr that’s right, basically all of the many hooks are just to make kakoune escape the user mode back to normal mode, and then press the same key. There were a surprising number of gotchas, like the fact that the event that signals entering and exiting user mode happens on every key press (see [#4513](https://github.com/mawww/kakoune/issues/4153)). And also that if the user just hits escape, this doesn’t trigger the inner `RawKey` hook, so another hook was required to remove the other hooks!

It would be much easier if there were an option to just pass through unmapped keys to normal mode.

---

<div class="post-metadata">

**Author:** ![danr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/danr/32/700_2.png) [@danr](https://discuss.kakoune.com/u/danr)\
**Post date:** [May 17, 2021, 2:16pm UTC](https://discuss.kakoune.com/t/visual-mode-kak/1725/4 "2021-05-17T14:16:01Z")

</div>

I remembered having a stab at implementing what is  
called “real custom modes” in [#3441](https://github.com/mawww/kakoune/issues/3441) here:

> <https://github.com/danr/kakconf/blob/main/archive/modalkak.kak>

I never got around to actually using it. But it is a way to add an indirection in the kakoune normal mode mapping to look up in custom modes.

Anyways, this would all be better to solve in the C++ code to add some kind of fallthrough.

Although another lazy way to work around this is to first prepopulate the user mode with all keys forwarding to normal mode. But it messes up the info box since it is now full of fallthrough forwarders. So the lazy thing is to add a `-hidden` flag to `map` 😛

---

<div class="post-metadata">

**Author:** ![CharlesGueunet](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/charlesgueunet/32/428_2.png) [@CharlesGueunet](https://discuss.kakoune.com/u/CharlesGueunet)\
**Post date:** [May 21, 2021, 11:18am UTC](https://discuss.kakoune.com/t/visual-mode-kak/1725/5 "2021-05-21T11:18:09Z")

</div>

In `visual-mode`, in seems `k` is going downward, is it the expected behavior ?

---

<div class="post-metadata">

**Author:** ![dead10ck](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/dead10ck/32/906_2.png) [@dead10ck](https://discuss.kakoune.com/u/dead10ck)\
**Post date:** [May 21, 2021, 2:44pm UTC](https://discuss.kakoune.com/t/visual-mode-kak/1725/6 "2021-05-21T14:44:27Z")

</div>

Doh, no, it is not. This was a copy/paste error from a last-minute change. Sorry about that, and thanks for testing! It should be fixed now.
