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:

  1. Make sure you are in viewing mode (not insert mode!)
  2. type the command below directly:[code language=”bash”]gg=G[/code]
  3. 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

2 Comments

Leave a Reply to gindedoc Cancel reply

Your email address will not be published. Required fields are marked *