tags:

views:

64

answers:

3

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.

+3  A: 

With supplementary searching, I've found that someone asked nearly the same question as I.

:command commandToBeAliased commandAlias

will do the trick.

Sean
+1  A: 

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).

Benoit
+4  A: 

To leave completion untouched try using cnoreabbrev W w, it will replace W in command line with w but only if it is neither followed nor preceded by word character, so :W<CR> will be replaced with :w<CR>, but :Write won't.

ZyX
This answer is the safest and most reliable for me.
Sean