Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to take the following data and query-replace occurences of each word identifier with the corresponding numeric identifier using some sort of repeatable function.

-1 ACT/CNS
-2 AG NFC
-3 AID
-4 BBG
-5 BIA
-6 BLM
-7 BOC
-8 BPD
-9 CCC
-10 CDC
-11 Census

In other words, with point at

-1 ACT/CNS
^

I'd like to be able to hit a key and launch into the following command

query-replace RET ACT/CNS RET -1 RET

I tried defining a keyboard macro but there seems to be enough jumping between buffers and M-x calls to confuse the kbmacro and make it unusable.

Thoughts?

share|improve this question
    
Where did you want to do the replacement? In that same buffer, or a different one? –  Trey Jackson Jun 21 '10 at 15:24
add comment

1 Answer

This is what I did to create the keyboard macro which did replacement of the symbols with the numbers.

C-a                     ;; move-beginning-of-line
M-f                     ;; forward-word
C-f                     ;; forward-char
C-SPC                   ;; set-mark-command
C-e                     ;; move-end-of-line
M-w                     ;; kill-ring-save
C-a                     ;; move-beginning-of-line
C-SPC                   ;; set-mark-command
M-f                     ;; forward-word
M-w                     ;; kill-ring-save
M-%                     ;; query-replace
C-y                     ;; yank
M-y                     ;; yank-pop
RET                     ;; newline-and-indent
C-y                     ;; yank
M-y                     ;; yank-pop
RET                     ;; newline-and-indent

When the cursor is on the line for "-1 ACT/CNS", the above will start the query/replace with the values you want - in the current buffer.

Unless you're doing this a lot (as in, more than just today), I'd stick with the macro because it's easy to set up.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.