How to select or highlight a block in Emacs?

后端 未结 9 749
一向
一向 2020-12-22 20:37

I want to select or highlight a block in emacs without using mouse but doing it from the keyboard like vim\'s visual mode. What is the easiest way to do this from a keyboard

相关标签:
9条回答
  • 2020-12-22 21:18

    If I understand the question correctly, it is not about rectangular regions originally.

    C-Spc puts a mark at the current position.

    Wherever your cursor is afterwards, the text between the last mark and the current position is "selected" (you can highlight this by activating transient-mark-mode, but this will also mean that marks have to be deleted when you don't want highlight).

    You can operate on that region with commands like:

    C-w . . Kill region. This deletes and puts the region into the kill ring.
    C-y . . Yank. This inserts the last snippet from the kill ring.
    M-y . . Cycle kill ring. Immediately after C-y, this replaces the yanked part by the other snippets in the kill ring.
    M-w . . Save region into kill ring. Like C-w, but doesn't delete.

    This is just the basic usage. Marks have other uses, too. I recommend the tutorial (C-h t).

    0 讨论(0)
  • 2020-12-22 21:21

    Emacs 24.4 now has rectangle-mark-mode. C-x space to invoke it.

    0 讨论(0)
  • 2020-12-22 21:24

    Use Control-Space to set a mark and move your cursor.

    The transient-mark-mode will highlight selections for you. M-x transient-mark-mode.

    You can setup Emacs to enable this mode by default using a customization. M-x customize-option RET transient-mark-mode.

    0 讨论(0)
提交回复
热议问题