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?

1 Answer 1

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>
3
  • Thanks, that did have me confused!
    – fbence
    Oct 20, 2022 at 8:02
  • I'd suggest to add the <bang> attribute as well: command -nargs=* -bang -complete=file W w<bang> <args> Oct 20, 2022 at 8:46
  • Ah yeah, cheers @ChristianBrabandt Oct 20, 2022 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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