0

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/  /
sammiwei
  • 3,140
  • 9
  • 41
  • 53
  • 1
    Do you mean "I do not want to indent with ASCII TAB characters?"? That is the nearest I can guess from the word "tapping". – sarnold Jan 11 '12 at 00:29
  • 1
    You might find the answers to [this question](http://stackoverflow.com/questions/69998/tabs-and-spaces-in-vim) useful. – Matthew Strawbridge Jan 11 '12 at 00:35
  • 3
    The way to indicate that your question has been answered is to accept an answer (you can post and accept your own answer if you like). Adding "[SOLVED]" to the title is just noise. – Keith Thompson Jan 11 '12 at 01:33

3 Answers3

3

There is a builtin :retab

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

richo
  • 8,717
  • 3
  • 29
  • 47
3

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
Neil G
  • 32,138
  • 39
  • 156
  • 257
1

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.

hochl
  • 12,524
  • 10
  • 53
  • 87