emacs string-insert-rectangle vector of numbers?

后端 未结 4 1297
萌比男神i
萌比男神i 2020-12-28 11:12

How can I use emacs string-insert-rectangle operation to add a vector of numbers to a series of lines? For example, I\'ve got this shortened version of a bunch of text entri

4条回答
  •  不知归路
    2020-12-28 11:22

    I think the simplest solution is to mark the first character of the original third column in the first line, move point to the same character of the last line, and then type:

    C-uC-xrNRET id%d RET

    rectangle-number-lines is an interactive compiled Lisp function in `rect.el'.

    It is bound to C-x r N.

    (rectangle-number-lines START END START-AT &optional FORMAT)

    Insert numbers in front of the region-rectangle.

    START-AT, if non-nil, should be a number from which to begin counting. FORMAT, if non-nil, should be a format string to pass to `format' along with the line count. When called interactively with a prefix argument, prompt for START-AT and FORMAT.

    The regexp-replace and macro techniques are both superb general-purpose tools to know, but rectangle-number-lines is pretty much custom-built for this very question.

    Edit: I hadn't noticed at the time, but it turns out that this is a new feature in Emacs 24. Earlier versions of Emacs will translate that sequence to C-x r n (lower-case n) which runs an entirely different function.

提交回复
热议问题