5

It happens to me many times that I want to repeat a command in Vim till a certain condition is satisfied rather than just multiple times. For example, say I want to make this code tidier:

Ogre::String GetConfigPath() const { return m_configPath; }
Ogre::String GetConfigName() const { return m_configName; }
Ogre::String GetConfigFileName() const { return m_configPath + m_configName + ".txt"; }
Ogre::String GetConfigStateFileName() const { return m_configPath + m_configName + "-state.txt"; }
Ogre::String GetConfigStatisticsFileName() const { return m_configPath + m_configName + "-statistics.txt"; }
Ogre::String GetConfigDetailedStatisticsFileName() const { return m_configPath + m_configName + "-detailed_statistics.txt"; }

What I usually do is to go to the function with longest name, press 'Tab' then align the other braces of other functions to match this one. Obviously, the task is now to add spaces before the braces of other functions until the cursor is at position, say, 80 (which the position of the brace of the longest function).

Is there anyway of repeating the command until the cursor is at position x?

This is just an example, and I frequently need to repeat a command until a certain condition is fulfilled.

Any idea?

Rafid
  • 18,991
  • 23
  • 72
  • 108
  • 3
    For that very specific case, you could use the Align plugin : http://www.vim.org/scripts/script.php?script_id=294 To answer your question in a more generic sense, I have no idea how you could deal with arbitrary conditions other than developing specific functions for each case. – Xavier T. Dec 21 '10 at 16:27
  • Wow, I don't believe that myself :-) Yeah, to be honest, I always thought of "conditional editing" rather than "repetitive editing". If you think about editing abstractly it is a special kind of programming because you always have rules for editing (even when writing non-programming texts). How does that sound?! – Rafid Dec 21 '10 at 16:29
  • @Xavier, thanks, yeah it seems that I have to develop functions for that. – Rafid Dec 21 '10 at 16:33

1 Answers1

3

I don't know how to do this through vim only, but I believe you should try the Align script.

icecrime
  • 74,451
  • 13
  • 99
  • 111
  • 1
    I believe it is hard to implement "conditional editing", so I don't think I will get more reply. Thank you, your answer is good enough to be the accepted answer. – Rafid Dec 21 '10 at 17:54