Have you ever experienced awful code arrangements after pasting the codes to vi or vim editor? Well, you shall worry no more! No matter how messed up was the codes you paste into the editor, you can indent them in a blink with the right command! Let’s see how it works:
- Make sure you are in viewing mode (not insert mode!)
- type the command below directly:[code language=”bash”]gg=G[/code]
- BOOM! Indented! Happy coding!
(Explanation: “gg” makes the cursor go to the top of the file, “=” is a command to fix the indentation and “G” tells it to perform the operation to the end of the file.)
Reference:
http://stackoverflow.com/questions/2355834/how-can-i-autoformat-indent-c-code-in-vim
gg=G好像在某些語言還是會跑掉XD
不過C的話可以順利排版~~
感謝Master指點迷津~