Home > Emacs > Fix indentation on entire file

Fix indentation on entire file

Sometimes, a file is just not indented right (usually happens with HTML files), and is totally unmaintable. Then I find myself opening the file in emacs and manually going through each line and tabbing them to the appropriate indentation. This is really just dumb, and I should’ve looked this up a long time ago, but there’s a built in command in emacs to handle this. All you do is select the text you want to indent — ctrl-x h for the entire buffer — and then do M-x “indent-region”. That’s all. Nifty little trick. I’m going to have to mess around with the other indent commands and see what they do. You can also use the shortcut C-M-\ instead of M-x “indent-region”.

Categories: Emacs Tags:
  1. Alexander
    April 21st, 2012 at 03:57 | #1

    Exactly what I was looking for.

  1. No trackbacks yet.