79

I get the following 10X times a day by accident.

Entering Ex mode. Type "visual" to go to Normal mode.

How can you disable the combo which causes it in Vim?

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • 9
    So glad I found this question... and let me guess, you're a fellow dvorak user, no? :) – Nik Reiman Dec 12 '09 at 12:43
  • 1
    @NikReiman Yes, you are right. I have been using Dvorak now about three and half years, started on October 2008. – Léo Léopold Hertz 준영 Jun 07 '12 at 09:28
  • 1
    here is a link that explains what that mode is for http://aplawrence.com/Words2005/2005_02_10.html – dreftymac Oct 03 '12 at 19:08
  • Agree with all the answers below, you can simply map it away. But are you sure you want to disable ex mode? It could be quite useful, here's a video by vimgirl showing what you can do in ex mode: https://www.youtube.com/watch?v=QP_xm0VwQa0&feature=youtu.be PS (I switched to dvorak 5 years ago after my wrist started hurting and then the pain went away. It's an amazing keyboard layout) – songz Sep 22 '17 at 01:27

5 Answers5

59

<Nop> is meant for use in mapping keys to "nothing". See :h <Nop>.

:map Q <Nop>

Or put it in your ~/.vimrc:

map Q <Nop>

.

Felix
  • 4,510
  • 2
  • 31
  • 46
Brian Carper
  • 71,150
  • 28
  • 166
  • 168
  • This worked for me from the command mode, but how do you put this in .vimrc? I tried a bunch of variations, but none of them worked. – Andrew Wagner Mar 05 '11 at 18:50
  • "map Q " in my .vimrc worked. Just don't try putting any comments after on the same line. – Andrew Wagner Mar 05 '11 at 18:53
  • 9
    I'd advise always using noremap instead of plain map, see http://learnvimscriptthehardway.stevelosh.com/chapters/05.html In this one case a map could theoretically never be remapped (I think) but never using a "plain map" is a good strategy in any case. – Niels Bom Jul 27 '12 at 15:40
  • @NielsBom Thank You for pointing that out! You saved my day and explained me a lot about my mistakes in Vim. I did not realize it before your comment. – Léo Léopold Hertz 준영 Oct 05 '12 at 21:04
  • `q:` (in Neovim) also drops me into ex mode, added `nnoremap q: ` to fix that – xeruf Nov 30 '21 at 08:18
32

This answer is based on @NielsBom's comment 4. October 2012 and on @BrianCarper's answer 13. August 2009.

I think NielsBom is completely right, please see the article. The command map is really evil in Vim and has caused me a lot of problems during years. I did not realize the thing before NielsBom's comment. So please use the following command instead:

:nnoremap Q <Nop>
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • 2
    @NielsBohrn was making a different point: He advised using the **`nore`** version of the map commands to prevent remapping of the right-hand side. In this case that would be `:nnoremap Q `, but since the right-hand side is ``, remapping is irrelevant. – glts Oct 06 '12 at 11:06
  • The comment has been included in the answer. I selected NielsBom's proposal as an accepted answer here because it is what I am looking for. – Léo Léopold Hertz 준영 Jan 08 '15 at 14:40
  • @glts That's an interesting point which I hadn't considered. Thanks for sharing it. At the same time, this `nnoremap` version doesn't really do any harm and may actually prevent problems down the road, for example if someone mindlessly copies this mapping to create another mapping which does not have `` as a target. I have certainly been guilty of things like that. For the sake of correctness, simplicity, and cognitive burden, I think we may be better off pretending the `*map` versions don't exist and instead using the `*noremap` versions everywhere, even where they are superfluous. – John Karahalis Apr 18 '21 at 09:25
  • 1
    Don't forget that it is also possible to enter ex mode with `gQ`. Use `:nnoremap gQ ` to disable that as well. – John Karahalis Apr 18 '21 at 09:27
  • 1
    ...and `nnoremap q: ` – xeruf Nov 30 '21 at 08:28
25

The "combo" is Q. To disable it, simply map Q to something else:

:map Q <whatever>

I use gq, which is used to format text.

If you don't want it do do anything map it to <Nop>:

:map Q <Nop>
R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
-1

If you don't want to map it to something else, just use :unmap. If you do have something else in mind, :map will work - take a look at the help pages to see the variations to specify what modes the map will be used in.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
-5

Another, albeit slightly more extreme option, would be to switch to https://neovim.io, which has removed ex-mode entirely, due to no one ever actually using it for anything ever.

maniacalrobot
  • 2,413
  • 2
  • 18
  • 20