I have a question.  Is there a way to have a replacement list and apply it to a buffer? I mean if I have in a file:


and I want to replace all the instances of the first word in a completely differentbuffer(which have many of the first words) is there an easy way?

EDIT: I think I made my post kinda ambigous, sorry for that. I meant that I have two files. One is the one I want to edit by replacing the words. The other file is one that has replacement rules.
Piotr Romanus's profile photoGianfranco Arroyo's profile photoElias Mårtenson's profile photoNick Alcock's profile photo
How about "M-x query-replace-regexp" with the following from regular expression: "^.*,"
I don't think you can do it without a bit of programming. Since I am not a elisp expert I would suggest sed and a bit of bash scripting. Something like the following:


cp -f $from_file $to_file

while read line; do 
    from_word=`echo $line | cut -f1 -d','`
    to_word=`echo $line | cut -f2 -d','`
    sed -i "s/$from_word/$to_word/g" $to_file
done < $rules_file
+Piotr Romanus, that only works as long as from_word and to_word don't contain spaces: you forgot to quote the assignments. It also works only as long as neither contain slashes.

I think elisp is a better choice.
I dont mind learning some elisp. I wanted to do it already so this is like a good project to start.
I always do stuff like that using a keyboard macro. I open two buffers and let the keyboard macro switch between them.
+Elias Mårtenson, it is one of my abiding shames that I find elisp so convenient that I've never learned to use keyboard macros for anything. I really should.
Add a comment...