Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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