C indentation Vim and Emacs

Hi All,

I would like to know if there is a way to get the editors Vim or Emacs (I use both as I haven't decided which I prefer yet) to change the indentation automatically when you wrap existing code into a new statement.

For example:
/* original code */
inst 1;
inst 2;
inst 3;

/* wrapping the code into a while loop */
while (cond) {
inst 1;
inst 2;
inst 3;
}

/* desired result */
while (cond) {
inst1;
inst2;
inst3;
}

Is there anyway to get the editor to change the indentation of the three instructions? Although I use the autoindent, it doesn't acknowledge subsequent changes. So far I've been making the changes manually, but I presume there must be a better way. Any clue ?
Thanks.

sorry, the format didn't come out properly:

1
2
3
4
5
6
/* desired result */
while (cond) {
   inst1;
   inst2;
   inst3;
}

Vim has autoindent and related features that can be configured in ~/.vimrc. For more details just do a search.
Topic archived. No new replies allowed.