作为一个vim的初学者,我在格式化我的代码时遇到了一些问题。这里有一个小例子来解释我想要什么。下面的代码是我的原始文件,没有任何格式。它看起来太拥挤了
# include <stdio.h>
static int global=1;
static void test(int a,int b);
int main(){
int local=1;
int useless=local+1;
printf("hello,world\n");
test(1,2);
}
static void test(int a,int b){
int c=a*b+a-b;
return;
}
我想要样式看起来像:
int useless = local + 1;
或
test(1 , 2);
我在命令模式下尝试:!indent --linux-style %
,得到
# include <stdio.h>
static int global = 1;
static void test(int a, int b);
int main()
{
int local = 1;
int useless = local + 1;
printf("hello,world\n");
test(1, 2);
}
static void test(int a, int b)
{
int c = a * b + a - b;
return;
}
虽然它的工作,有两个恼人的点对我来说:
1.!indent --linux风格的%太长,效率较低
1.我想在每次输入一行时自动格式化,例如test(1,2)-〉test(1,2);
那么还有其他的解决办法吗?
2条答案
按热度按时间0aydgbwb1#
为了满足您的需要,您可以使用autocmd
它将在每个文件保存前运行命令
dxpyg8gm2#
我尝试这个插件:https://github.com/vim-autoformat/vim-autoformat
解决了我的问题