Remapping :Wq to :wq in vim

2019-02-12 10:26发布

A lot of times, when I want to save a file in vim and immediately exit thereafter, I accidentally type :Wq instead of :wq.

Vim naturally gives me this error:

E492: Not an editor command: Wq 

I'm wondering, is it possible to remap :Wq to :wq?

3条回答
小情绪 Triste *
2楼-- · 2019-02-12 11:00

You can create a simple vim command that is basically an alias for wq. Place the following in your ~/.vimrc file:

command! Wq wq

For more help see:

:h :command
查看更多
Fickle 薄情
3楼-- · 2019-02-12 11:07

Though abbreviations suggest themselves for this (:cnoreabbrev Wk wk), their main disadvantage is that they are also applied in other places, such as when using Wk in a search pattern.

With the cmdalias plugin, you can define an alias:

:Alias Wk wk

PS: There is no :wk command, did you mean :wn[ext]? For a simple :w, have a look at this question

查看更多
做自己的国王
4楼-- · 2019-02-12 11:15

You can also use ZZ which is the same as :wq<CR>

查看更多
登录 后发表回答