3

I'm always typing :Wq when I mean :wq. Is there a way to alias :Wq=':wq' in vim?

2 Answers 2

5

I had the same problem, but I aliased ; to : instead.

nnoremap ; :

(Why worry about not releasing Shift in time if you can just not press it in the first place.)

A more direct answer:

command Wq :wq

(As it happens, user-defined commands must start with an upper-case letter.)

You'll likely want proper tab-completion though, as well as :W:

command -complete=file -bang -nargs=? W  :w<bang> <args>
command -complete=file -bang -nargs=? Wq :wq<bang> <args>
2
  • This is a line to be added in ~/.vimrc? Feb 24, 2015 at 17:44
  • 1
    Since I tend to have a "lazy shift finger" when typing a colon, I have had to create user-commands that correspond to a number of internal Vim commands, including :Help.
    – Heptite
    Feb 24, 2015 at 18:17
0

Check the answers for the same question on the stackoverflow on how to achieve what you asked.

But I think it is better to use ZZ (which is also mentioned there), as it is shorter to type and avoid the problem altogether. Mappings are usually better than commands for frequent actions/tasks.

1
  • Thanks @mMontu. I thought this must have been asked before but couldn't find it via google Feb 26, 2015 at 12:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .