0

I want to map :bd to :bd! using:

command! -nargs=* -complete=buffer bd :call bd!

but vim told me "User defined commands must start with an uppercase letter"


update solutions from answer:

cnoremap bd bd!

another way

cnoreabbrev <expr> bd getcmdtype() == ":" && getcmdline() == 'bd' ? 'bd!' : 'bd'
BigFish
  • 77
  • 6

1 Answers1

2

You can create a "user-defined" command to wrap the target command, bd in your case. Then you have to let the command name start with an uppercase letter.

In fact, if I understand your requirement correctly, you want to always execute bd! when you type bd in command mode, then you can just create a mapping:

cnoremap bd bd!

In this way, when you type :bd the ! will be there automatically.

P.S.

When you used call, you are calling a function() instead of a command.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • I have seen [it recommended](https://learnvimscriptthehardway.stevelosh.com/chapters/05.html) that one should always use `cnoremap` instead of `cmap`. – chepner Apr 08 '20 at 12:44
  • @chepner thx, I've changed in answer. – Kent Apr 08 '20 at 13:38