Будучи строчным редактором, ed
не отслеживает отступы между строками.
Вы можете использовать e !command
для вызова внешнего форматера кода в файле.
Типичная сессия редактирования, в которой создается, редактируется и отстукивается простая программа на языке Си, может выглядеть так:
$ rm test.c
$ ed -p'> ' test.c
test.c: No such file or directory
> H
cannot open input file
> i
#include <stdlib.h>
int main(void)
{
/* There is no place else to go.
* The theatre is closed.
*/
return EXIT_SUCCESS;
}
.
> /void/
int main(void)
> s/void/int argc, char **argv/
> %p
#include <stdlib.h>
int main(int argc, char **argv)
{
/* There is no place else to go.
* The theatre is closed.
*/
return EXIT_SUCCESS;
}
> w
142
> e !clang-format test.c
158
> %p
#include <stdlib.h>
int main(int argc, char **argv)
{
/* There is no place else to go.
* The theatre is closed.
*/
return EXIT_SUCCESS;
}
> w
158
> q
$
Обратите внимание на запись файла до и после вызова форматера кода (clang-format
в данном случае). Мы записываем файл в test.c
, а затем читаем результат выполнения команды над этим файлом.