My coding habits were not very good in the past, so a lot of tabs were used in the code.
Now I want to convert tabs to spaces by setting vimrc
and then executing the :ret
command. The problem is that there are many files that need to be processed. Manually execute # for each file. ##:retThe command is not very practical. From what angle can I consider to solve this problem?
For example, all you want to process are python files, then cd to the project root directory:
1. $> vim `find . -type f -name "*.py"` // Open all files to be processed with VIM
2. :argdo :ret | update // Execute the :ret command on all files in the vim parameter list and save
In addition, you can learn more about the usage of bufdo and windo commands.
The above is just to show that VIM can easily do this in response to the original poster's problem, without having to do it one by one. Of course, writing a script according to the idea above is also a good method.
Try sed:
sed -i -e "s/t/ /g" *.py
It is recommended not to use vim and write a script to handle it.
It can be written in shell, and the find + sed command will do it. It can also be written in python, and os.path.walk traverses the file and scans line by line. There is not much code.
This kind of problem can be solved using regular expressions, but it is best not to use vim to deal with it one by one. It would be better to write a python script to run regular expressions
expand
The shell command does this.It is more comfortable to use regular expressions for batch processing, but if you must use vim, @shizhz’s answer is good.
sed -i "s/\t/ /g" *.py
Use the non-interactive mode of vi(m).
^I
使用CTRL+V+I
Enter.No spaces can be used after EOF.
There cannot be a space before the vi(m) command.
:h retab