2019-01-28 A simple tip with killing and yanking code

I often kill (cut) some code and then yank (paste) it somewhere else. Often the level of indentation is wrong in the new place (for instance, something is put from a higher level into a then-branch of a conditional).

Emacs has the indent-region command (by default bound to C-M-\). While it operates on the region, it does not require the region to be active. Since yank sets the mark and point at the opposite sides of the yanked text, you can press C-M-\ immediately after the yank and Emacs does The Right Thing™ for you. It even works when the region begins or ends in the middle of a line (in such a case, that line is also indented).

You’re welcome.

CategoryEnglish, CategoryBlog, CategoryEmacs