sammiwei
sammiwei

Reputation: 3200

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/  /

Upvotes: 0

Views: 231

Answers (3)

Neil G
Neil G

Reputation: 33202

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

Upvotes: 3

hochl
hochl

Reputation: 12920

You may use the = command to format code, if you indent a line with two spaces, the following lines may be indented with 2 spaces if you use the =<movement> command on them.

Upvotes: 1

richo
richo

Reputation: 8989

There is a builtin :retab

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

Upvotes: 3

Related Questions