I have a text file with some sample content as shown here:
Sno = 1p Sno = 2p Sno = 3p
What i want is to remove the p
from each of the columns. With this intention i write a macro:
M-x //go to buffer C-x (//start the macro C-s = // search for equalto sign RET C-f C-f // reach to te alphabet 'p' DEL // Delete C-n C-x )//go to new line and Close the macro definition C-x e
Pressing e
twice will remove p
, but in case i want to do the same stuff till the end of file, how can i do it i can't keep pressing e
if i have 20000 such lines. What should be done??
Please donot suggest regex, as this is a sample example, not the actual case. Please donot suggest any elisp, i am comfortable with remembering shortcutf for emacs.
To execute the macro, press C-x e . This command executes the last macro you have defined.
C-x ) can be given a repeat count as an argument. This means to repeat the macro right after defining it. The macro definition itself counts as the first repetition, since it is executed as you define it, so C-u 4 C-x ) executes the macro immediately 3 additional times.
A keyboard macro is a command defined by an Emacs user to stand for another sequence of keys. For example, if you discover that you are about to type C-n M-d C-d forty times, you can speed your work by defining a keyboard macro to do C-n M-d C-d , and then executing it 39 more times.
M-0 C-x e
to repeat last macro until an error happens (after the final line, either C-s =
or C-n
will be an error).
You may hear an annoying beep.
You can use the "apply-macro-to-region-lines" function to apply the last defined keyboard macro to all lines in a region. So, the steps you follow are:
Define your keyboard macro (which you had already done but I've added another C-f to the 3rd line):
C-x ( C-s = RET C-f C-f C-f DEL C-n C-x )
Select the whole buffer with the "mark-whole-buffer" command (by default, it's bound to C-x h). Alternatively, if you just want to change a certain number of lines, just select the lines you want changed.
Run the "apply-macro-to-region-lines" function (by default, it's bound to C-x C-k r).
All the p's will be removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With