I have a vim (well, sed really) find and replace pattern I use for resetting the AUTO_INCREMENT property in mySQL CREATE TABLE statements:

:%s/AUTO_INCREMENT=[0-9]*/AUTO_INCREMENT=1/g

I use this command often, and would like to create a shortcut in vim. I know I will have to edit my .vimrc, but I can't figure out the cmap syntax.

My end goal is to be able to run

:reset-auto-increment

And run the above find and replace globally throughout the file.

link|improve this question

67% accept rate
feedback

1 Answer

up vote 4 down vote accepted

For that goal, I think a user-defined command would be better than a cmap. See

:help 40.2
:help user-commands

Vim requires that user-defined commands begin with an upper-case letter and contain only letters and digits. No hyphens. So your command will have to be something like ResetAutoIncrement.

command ResetAutoIncrement %s/AUTO_INCREMENT=[0-9]*/AUTO_INCREMENT=1/g

You can avoid typing the whole command name each time you use it by typing just the first few characters, then hitting Tab.

link|improve this answer
Thanks! The help command is super-helpful – CamelBlues Oct 20 '11 at 18:05
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.