1

I know I can set user-defined commands using the :command Foo bar syntax, but I want a way to set a command without using capitals.

For example, to save all open buffers, the command is :wa, but that's slightly too inconvenient. I'd really like to be able to just do :ww.

What's with this seemingly arbitrary limitation? Why do I have to use capital letters?

  • @VanLaser After installing that, I'm able to run :AlterCommand ww wa in the actual vim instance and have it work, but I can't add it to my .vimrc properly. I've tried AlterCommand ww wa :AlterCommand ww wa and a few variations of that. I'm not even sure what to Google for this? What are these "commands" called that have colons before them? And how do I add them to my vimrc? – Brandon Sturgeon Dec 12 '16 at 21:41
  • 1
    To use AlterCommand in your vimrc, you will need to place this command somewhere above (still in your vimrc): call altercmd#load(). It's documented in the plugin's help. BTW, the whole plugin is a convenient interface around Vim's builtin cnoreabbrev command. Also those "commands" with colons before them are called ... Vim commands (and they are run from "command-line mode"). – VanLaser Dec 12 '16 at 21:52
  • 1
    Thanks for having patience, I appreciate it. I was reading vim.org/scripts/script.php?script_id=2675 and didn't see it there, but I looked at the other docs and I'm seeing it now. Thank you! – Brandon Sturgeon Dec 12 '16 at 21:57
  • 1
    You're welcome. You can always use :h altercmd, :h cnoreabbrev and so on. – VanLaser Dec 12 '16 at 22:13
4

Why

Commands (custom as well as built-in) are used in mappings, scripts, plugins. If you could override them, it would be very easy to break functionality.

There is a mechanism for customization that doesn't suffer from this (command-line mode abbreviations); unfortunately, they don't differentiate (between commands and arguments, or commands and searches), so they are too coarse, especially for short tweaks (like :W:w). Try that:

:Alias ww wa

Plugin

The cmdalias.vim - Create aliases for Vim commands plugin attempts to solve this problem, by defining mappings that only apply in command positions.

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.