I was trying to map 'q!' to 'Q!' in .vimrc ? I tried the following but not working. :command Q! q! Please provide any suggestion to mitigate this issue. Thank you.
Asked
Active
Viewed 2,028 times
3 Answers
3
You just have to give
:command Q q
Similarly, you can do for other commands like,
:command WQ wq
:command W w
muru
- 193,181
- 53
- 473
- 722
Kenny John Jacob
- 81
- 4
-
Thank you for your suggestion. ":command Q q" is working perfectly, but the problem creates when I try to map the key "q!" (which is quit without implementing the changes.) – Bhaiti May 20 '15 at 11:52
-
In that case, you could simply do ZQ in Normal mode although it takes some rewiring to remember! :) – Kenny John Jacob May 20 '15 at 11:58
-
Thank you. However It is better to stick with q!. – Bhaiti May 20 '15 at 12:04
2
This worked perfectly for me:
:command-bang Q q<bang>
From vim's help (:h command-bang):
Special cases :command-bang :command-bar
:command-register :command-buffer
There are some special cases as well:
-bang The command can take a ! modifier (like :q or :w)
and
Replacement text
The replacement text for a user defined command is scanned for special escape
sequences, using <...> notation. Escape sequences are replaced with values
from the entered command line, and all other text is copied unchanged. The
resulting string is executed as an Ex command. [...]
The valid escape sequences are
[...]
<bang> (See the '-bang' attribute) Expands to a ! if the
command was executed with a ! modifier, otherwise
expands to nothing.
[...]
0
Try that:
:cmap Q! q!
Maps Q! in command mode to q!.
chaos
- 27,106
- 12
- 74
- 77
-
Thank you. It works fine. But If I take time to type ! after Q, It doesn't work. When I type Q! quickly it automatically gets changed to q!. Nevertheless I am not that slow in typing. Thank you once again. – Bhaiti May 20 '15 at 12:00