简体   繁体   中英

VIM Editor: How to do auto formatting in VIM?

I am new to VIM, so still learning. The thing I wanna do is instead of using tabs, I wanna to use 2 spaces to replace A tab. I wanna apply this format to my entire java code. How would I do it? Thanks!

Updated I used this following and it worked

:%s/\t/  /

There is a builtin :retab

You can also use gg=G to reindent the entire source file.

There are many ways of replace tabs with spaces. If you want to use search-and-replace, you need the :s command. Try typing ":help :s" for help. You'll find that the following works:

:%s/<ctrl-v><tab>/  /g

您可以使用=命令来设置代码格式,如果您将一行缩进两个空格,则对它们以下行可以缩进2个空格(如果您对它们使用=<movement>命令)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM