Reusing 'wq' to save and close the buffer instead of saving and exiting

Vim newbie here.

when I ': wq' I want it to save and delete the buffer instead of saving and terminating. Similarly, pressing ': q' will instead execute ': bd'.

Any suggestions? Thanks!

+7
vim macvim
source share
1 answer

Vim allows you to add key mappings for commands in all modes, including command line mode, so you can define these mappings (in your .vimrc ):

 :cnoreabbrev wq w<bar>bd :cnoreabbrev q bd 

Commands tell Vim that pressing w q on the command line should be expanded to w|bd and, similarly, q to bd . See :help key-mapping details.

+10
source share

All Articles