emacs string-insert-rectangle vector of numbers?

后端 未结 4 1285
萌比男神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:45

    You can use query-replace-regexp directly, by adding a new column with the match count \#.

    The matches look for 3 columns separated by spaces, which will be stored in submatch strings \1 to \3. The replaced string adds a new column using the match count.

    Version 1 (simpler, but starts at 0):

    M-x query-replace-regexp RET
    ^\(\w+\)\ +\(\w+\)\ +\(\w+\)$ RET
    \1 \2 id\# \3 RET
    

    Note I used spaces for matching and replacing. You can use tabs instead.

    Version 2 (uses lisp to customize the row count with the +1 function):

    M-x query-replace-regexp RET
    ^\(\w+\)\ +\(\w+\)\ +\(\w+\)$ RET
    \,(format "%s %s id%d %s" \1 \2 (+1 \#) \3) RET
    

提交回复
热议问题