# Exit user-mode with lock

**URL:** <https://discuss.kakoune.com/t/exit-user-mode-with-lock/1710>\
**Category:** Help\
**Tags:** usermode\
**Created:** [May 4, 2021, 2:47am UTC](https://discuss.kakoune.com/t/exit-user-mode-with-lock/1710 "2021-05-04T02:47:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![scr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/scr/32/486_2.png) [@scr](https://discuss.kakoune.com/u/scr)\
**Post date:** [May 4, 2021, 2:47am UTC](https://discuss.kakoune.com/t/exit-user-mode-with-lock/1710/1 "2021-05-04T02:47:37Z")

</div>

Hello,

I would like to use `-lock` for all of my user-mode command exept for one that need to exit the user-mode to do some editing.

I try to run:

```auto
map global my-user-mode x "<esc>" 

```

But this doesn’t seems to exit the usermode.  
Is there a way to exit the “locking”?

I could remove the “-lock” and add `:enter-user-mode my-user-mode<ret>` at the end of all my usermode mapping but would be nice to have a less verbose solution.

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [May 4, 2021, 4:11am UTC](https://discuss.kakoune.com/t/exit-user-mode-with-lock/1710/2 "2021-05-04T04:11:56Z")

</div>

The way user-modes work is:

- Kakoune displays the list of mappings
- The user presses one of the mapped keys
- Kakoune exits the user-mode and returns to normal mode
- Kakoune executes the mapping
- If `-lock` was used when the user-mode was first entered, Kakoune re-enters the user-mode

So if you have a user-mode mapping that maps to `<esc>`, that won’t exit the user-mode, because Kakoune isn’t _in_ the user-mode when the mapping is executed.

I don’t know of a way around this, other than adding an extra `enter-user-mode` to the end of every mapping, which causes issues if anybody _does_ try to use `-lock` mode.

---

<div class="post-metadata">

**Author:** ![scr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/scr/32/486_2.png) [@scr](https://discuss.kakoune.com/u/scr)\
**Post date:** [May 4, 2021, 4:59am UTC](https://discuss.kakoune.com/t/exit-user-mode-with-lock/1710/3 "2021-05-04T04:59:10Z")

</div>

Maybe a hook when re-entering user-mode could work?

---

<div class="post-metadata">

**Author:** ![prion](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/prion/32/404_2.png) [@prion](https://discuss.kakoune.com/u/prion)\
**Post date:** [May 4, 2021, 7:02am UTC](https://discuss.kakoune.com/t/exit-user-mode-with-lock/1710/4 "2021-05-04T07:02:04Z")

</div>

it’s not pretty but

```auto
map global user-mode x ': fail<ret>'

```

works

---

<div class="post-metadata">

**Author:** ![scr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/scr/32/486_2.png) [@scr](https://discuss.kakoune.com/u/scr)\
**Post date:** [May 4, 2021, 11:47am UTC](https://discuss.kakoune.com/t/exit-user-mode-with-lock/1710/5 "2021-05-04T11:47:40Z")

</div>

Punk rock editor I guess 😉
