1

I know how to remap keys in .vimrc, but that's not what I want to do. I want to change a colon command; specifically, I want to change or remove :X (that's a capital "X"). I always type it when I'm trying to type :x (lowercase).

This has been driving me crazy for 15 years. My hands aren't going to stop making that typo 10 times a day. I've got to just change or remove that command.

migrated from serverfault.com Sep 10 '15 at 15:52

This question came from our site for system and network administrators.

1

To re-mapping a command in vim:

:command <mapping command> <original command>

In your case:

:command X x

But don't do that.

:X is already a command in vim, it prompt for an encryption key.

If you feel it's hard to type :x correctly, use another shortcut for it, ZZ.

  • That's not an answer, sorry. – felwithe Sep 10 '15 at 16:38
  • @felwithe: Well, I updated with the solution for remapping command, but it is still better to use the keyboard shortcut. You can't detect if you have override vim command default or not. – cuonglm Sep 10 '15 at 16:52
  • This game me an error: "E841: Reserved name, cannot be used for user defined command". The line I added to .vimrc was :command X W. I picked W because it's unused (according to vim whenever I type it). – felwithe Sep 12 '15 at 14:11
  • @felwithe: you must use command X W in .vimrc, no colon. Note that this will map :X to :W, which is not an editor command. – cuonglm Sep 12 '15 at 15:45
  • That gives an error also. "E841: Reserved name, cannot be used for user defined command" – felwithe Sep 12 '15 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.