1

I easily found how to remap keys in my vimrc, but not how to change commands like :badd , :new ... to be for example :bd, :n ...

Can someone show me how to do this, or give me a link to a page that shows it?

aurelienC
  • 1,113
  • 3
  • 12
  • 22
  • `:n` and `:bd` are already other existed commands you can use `:N` or `:Bd` instead – Meninx - メネンックス Aug 07 '16 at 16:40
  • 1
    @Meninx `:N` is also already taken, and it means `:previous`, of all things. :) – Sato Katsura Aug 07 '16 at 16:58
  • 4
    Yes, you can "change" commands, but (1) you need to make sure you aren't overriding existing commands (otherwise plugins would start breaking right and left), and (2) it isn't trivial to do it [safely](http://vim.wikia.com/wiki/Replace_a_builtin_command_using_cabbrev). – Sato Katsura Aug 07 '16 at 17:03
  • Similar post: [vim change :x function to delete buffer instead of save & quit](http://stackoverflow.com/q/7513380/438329) – Peter Rincker Aug 10 '16 at 17:52

1 Answers1

2

Use :command!. For example, if you want to be able to type :W<cr> in addition to :w<cr> to save your file you would add the following line to your vimrc

command! W w

The exclamation point makes the command mapping non-recursive, similar to noremap vs. map. Further, commands you define must start with a capital letter. This stops them from overlapping with built-in commands.

lwassink
  • 1,595
  • 13
  • 16