Emacs bulk indent for Python

前端 未结 8 1323
星月不相逢
星月不相逢 2021-01-29 17:37

Working with Python in Emacs if I want to add a try/except to a block of code, I often find that I am having to indent the whole block, line by line. In Emacs, how do you inden

8条回答
  •  半阙折子戏
    2021-01-29 18:28

    In addition to indent-region, which is mapped to C-M-\ by default, the rectangle edit commands are very useful for Python. Mark a region as normal, then:

    • C-x r t (string-rectangle): will prompt you for characters you'd like to insert into each line; great for inserting a certain number of spaces
    • C-x r k (kill-rectangle): remove a rectangle region; great for removing indentation

    You can also C-x r y (yank-rectangle), but that's only rarely useful.

提交回复
热议问题