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
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>
-
-
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 -