Aliasing a command in vim

2020-01-25 04:09发布

Vim is my preferred text editor when I program, and thus I always run into a particularly annoying issue.

Frequently, when I quickly need to save the buffer and continue on to some other miscellaneous task, I do the typical

:w

However, I – what seems to be like more than 50% of the time – always manage to capitalise that :w. Naturally, vim yells at me because W is an invalid command

E492: Not an editor command: W

My question is how can one alias colon-commands in vim. Particularly, could you exemplify how to alias W to w.

I am aware of the process to map keys to certain commands. Unfortunately, that is not what I'm looking for.

7条回答
Luminary・发光体
2楼-- · 2020-01-25 04:55

Maybe you would like to map one of your function keys (F1..F12) to :w ? Then put this into your .vimrc:

noremap  <f1> :w<return>
inoremap <f1> <c-o>:w<return>

(ctrl-o in insert mode switches temporarily to normal mode).

查看更多
登录 后发表回答