2

I'm trying to get :W to also save like :w (I often mistype). I tried something like this: command! W execute "norm! w", but that doesn't work. How can I do this?

fbence
  • 677
  • 4
  • 12

1 Answers1

1

norm! (short for normal!) executes commands in normal mode. A "command" in normal mode is a key you use to do something; for example w to go to the next word, dd to delete the line, and many more.

command expects ex commands, or CLI commands. That is, what you type after pressing :.

It's a bit confusing both are called "commands".

So to get your command, you can do:

command W w

Which will work fine for typo-ing :W to :w, but if you want :W file to work you need to also pass any arguments:

command -nargs=* -bang -complete=file W w<bang> <args>
Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271