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.

Is it even possible?

What I mean is, many vim commands can take a movement to operate on, can I define a custom movement so that I can tailor my edits to an environment?

The specific command I'm interested in is gq, to re-format. I can type gqip to re-format a paragraph, ip being the movement from the beginning to the end of the current paragraph excluding surrounding whitespace.

Is it possible to define a custom movement to replace ip to allow me to, say, re-format comments without touching surrounding code? This would require a movement similar to ip but with different conditions for where it starts or ends.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Take a look at this Vim Tips Wiki article on creating new text objects, and also at these two Vim plugins that provide functions for creating custom text objects and an example of creating custom text objects.

share|improve this answer
    
You should probably expand this answer to briefly cover what those links mention. In particular, that it's omap that does what I want. –  SpoonMeiser Nov 6 '10 at 1:29
    
@SpoonMeiser: I would if I understood it better myself. As it is, I just knew where to find more information. –  garyjohn Nov 6 '10 at 3:52

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.