The best solution involves writing a custom function for handling abbreviations that only take place in the beginning of the command bar.
For this, add the following your vimrc file or anywhere else.
" cabs - less stupidity {{{
fu! Single_quote(str)
return "'" . substitute(copy(a:str), "'", "''", 'g') . "'"
endfu
fu! Cabbrev(key, value)
exe printf('cabbrev <expr> %s (getcmdtype() == ":" && getcmdpos() <= %d) ? %s : %s',
\ a:key, 1+len(a:key), Single_quote(a:value), Single_quote(a:key))
endfu
"}}}
" use this custom function for cabbrevations. This makes sure that they only
" apply in the beginning of a command. Else we might end up with stuff like
" :%s/\vfoo/\v/\vbar/
" if we happen to move backwards in the pattern.
" For example:
call Cabbrev('W', 'w')
A few useful abbreviations from the source material where I found this stuff:
call Cabbrev('/', '/\v')
call Cabbrev('?', '?\v')
call Cabbrev('s/', 's/\v')
call Cabbrev('%s/', '%s/\v')
call Cabbrev('s#', 's#\v')
call Cabbrev('%s#', '%s#\v')
call Cabbrev('s@', 's@\v')
call Cabbrev('%s@', '%s@\v')
call Cabbrev('s!', 's!\v')
call Cabbrev('%s!', '%s!\v')
call Cabbrev('s%', 's%\v')
call Cabbrev('%s%', '%s%\v')
call Cabbrev("'<,'>s/", "'<,'>s/\v")
call Cabbrev("'<,'>s#", "'<,'>s#\v")
call Cabbrev("'<,'>s@", "'<,'>s@\v")
call Cabbrev("'<,'>s!", "'<,'>s!\v")
:W
you could a map a key to perform the saving. If you are used to some program that saves with Ctrl-s, there are these mappings from $VIM/mswin.vim:" Use CTRL-S for saving, also in Insert mode
noremap <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
inoremap <C-S> <C-O>:update<CR>
– Ebonee