Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .